Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
text-similarity
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ani
text-similarity
Commits
cfb01eb5
Commit
cfb01eb5
authored
Aug 17, 2018
by
Anirudha Pimpale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check output
parent
6b5bad0f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
9 deletions
+68
-9
LabeledLineSentence.cpython-36.pyc
lib/__pycache__/LabeledLineSentence.cpython-36.pyc
+0
-0
trainCall.cpython-36.pyc
lib/__pycache__/trainCall.cpython-36.pyc
+0
-0
predictCall.py
lib/predictCall.py
+16
-2
trainCall.py
lib/trainCall.py
+50
-5
main.py
main.py
+2
-2
testModel.model
testModel.model
+0
-0
testModel.model.trainables.syn1neg.npy
testModel.model.trainables.syn1neg.npy
+0
-0
testModel.model.wv.vectors.npy
testModel.model.wv.vectors.npy
+0
-0
No files found.
lib/__pycache__/LabeledLineSentence.cpython-36.pyc
0 → 100644
View file @
cfb01eb5
File added
lib/__pycache__/trainCall.cpython-36.pyc
View file @
cfb01eb5
No preview for this file type
lib/predictCall.py
View file @
cfb01eb5
import
gensim
from
nltk
import
RegexpTokenizer
from
nltk.corpus
import
stopwords
from
os
import
listdir
from
os.path
import
isfile
,
join
from
gensim.models.doc2vec
import
Doc2Vec
,
TaggedDocument
def
predict
():
def
predict
():
print
(
"hello"
)
old_model
=
gensim
.
models
.
doc2vec
.
Doc2Vec
.
load
(
'testModel.model'
)
\ No newline at end of file
tokens
=
"computer gaming is the best thing"
.
split
()
new_vector
=
d2v_model
.
infer_vector
(
tokens
)
print
(
old_model
.
docvecs
.
most_similar
(
new_vector
))
print
(
old_model
.
most_similar
([
new_vector
]))
print
(
old_model
.
docvecs
.
offset2doctag
([
new_vector
]))
\ No newline at end of file
lib/trainCall.py
View file @
cfb01eb5
from
App
import
db
from
App
import
db
from
Models
import
*
from
Models
import
*
from
multiprocessing.pool
import
Pool
from
nltk.tokenize
import
RegexpTokenizer
import
gensim
from
nltk
import
RegexpTokenizer
from
nltk.corpus
import
stopwords
def
load_paper
():
from
os
import
listdir
from
os.path
import
isfile
,
join
from
gensim.models.doc2vec
import
Doc2Vec
,
TaggedDocument
labels
=
[]
tokenizer
=
RegexpTokenizer
(
r'\w+'
)
stopword_set
=
set
(
stopwords
.
words
(
'english'
))
def
nltk_cleaning
(
data
):
clean_data
=
[]
new_str
=
data
.
lower
()
dlist
=
tokenizer
.
tokenize
(
new_str
)
dlist
=
list
(
set
(
dlist
)
.
difference
(
stopword_set
))
clean_data
=
dlist
return
clean_data
def
tokenize
(
article
):
preprocessed
=
article
[
0
]
.
replace
(
"
\r
"
,
""
)
.
replace
(
"
\n
"
,
""
)
data
=
nltk_cleaning
(
preprocessed
)
return
data
,
article
[
1
]
def
load_paper
(
labels
):
result
=
[]
articles
=
Paper
.
query
.
filter
(
Paper
.
Abstract
!=
""
)
.
with_entities
(
Paper
.
Abstract
,
Paper
.
PaperKey
)
.
all
()
with
Pool
()
as
pool
:
result
=
pool
.
map
(
tokenize
,
articles
)
for
item
in
result
:
labels
.
append
(
gensim
.
models
.
doc2vec
.
LabeledSentence
(
words
=
item
[
0
],
tags
=
[
item
[
1
]]))
return
labels
def
train
():
def
train
():
#print(Paper.query.count())
labels
=
[]
print
(
Paper
.
query
.
count
())
dataset
=
load_paper
(
labels
)
load_paper
()
model
=
gensim
.
models
.
Doc2Vec
(
size
=
300
,
min_count
=
0
,
alpha
=
0.025
,
min_alpha
=
0.025
)
print
(
"hello"
)
model
.
build_vocab
(
dataset
)
\ No newline at end of file
for
epoch
in
range
(
100
):
print
(
'iteration'
+
str
(
epoch
+
1
))
model
.
train
(
labels
,
epochs
=
model
.
iter
,
total_examples
=
model
.
corpus_count
)
model
.
alpha
-=
0.002
model
.
min_alpha
=
model
.
alpha
model
.
save
(
'testModel.model'
)
\ No newline at end of file
main.py
View file @
cfb01eb5
from
lib
import
trainCall
,
predict
Call
from
lib
import
Train
Call
import
argparse
import
argparse
def
main
():
def
main
():
...
@@ -9,7 +9,7 @@ def main():
...
@@ -9,7 +9,7 @@ def main():
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
(
args
.
run_opt
==
2
):
if
(
args
.
run_opt
==
2
):
t
rainCall
.
train
()
T
rainCall
.
train
()
else
:
else
:
predictCall
.
predict
()
predictCall
.
predict
()
...
...
testModel.model
0 → 100644
View file @
cfb01eb5
File added
testModel.model.trainables.syn1neg.npy
0 → 100644
View file @
cfb01eb5
File added
testModel.model.wv.vectors.npy
0 → 100644
View file @
cfb01eb5
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment