-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
53 lines (45 loc) · 1.55 KB
/
models.py
File metadata and controls
53 lines (45 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import gensim
from gensim.models.doc2vec import Doc2Vec
from gensim.models.doc2vec import TaggedDocument
class TaggedDocumentIterator(object):
def __init__(self, articles):
self.articles = articles
def __iter__(self):
for a in self.articles:
yield TaggedDocument(a[-1], [a[0]])
class Doc3Vec(object):
assert gensim.models.doc2vec.FAST_VERSION > -1
def __init__(self,
corpus,
epochs,
min_count,
vector_size,
window=5,
negative=5,
compute_loss=False,
dm=0,
workers=5):
self.corpus = corpus
self.epochs = epochs
self.min_count = min_count
self.vector_size = vector_size
self.window = window
self.negative = negative
self.compute_loss = compute_loss
self.dm = dm
self.workers = workers
@property
def model(self):
model = Doc2Vec(epochs=self.epochs,
min_count=self.min_count,
vector_size=self.vector_size,
window=self.window,
negative=self.negative,
compute_loss=self.compute_loss,
dm=self.dm,
workers=self.workers)
model.build_vocab(self.corpus)
model.train(self.corpus,
total_examples=model.corpus_count,
epochs=model.epochs)
return model