Created
January 24, 2018 12:16
-
-
Save mino98/1cb7f0f8415a0618e837c7e0f9adfe03 to your computer and use it in GitHub Desktop.
Crash code for gensim issue #1019
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gensim.models import doc2vec | |
from numpy import zeros | |
print("Using optimization: %d" % doc2vec.FAST_VERSION) | |
sentences = [('food', 'I like to eat broccoli and bananas.'), | |
('food', 'I ate a banana and spinach smoothie for breakfast.'), | |
('animals', 'Chinchillas and kittens are cute.'), | |
('animals', 'My sister adopted a kitten yesterday.'), | |
('animals', 'Look at this cute hamster munching on a piece of broccoli.')] | |
convSentences = [] | |
for s in sentences: | |
convSentences.append(doc2vec.LabeledSentence(tags=[s[0]], words = s[1].split())) | |
model = doc2vec.Doc2Vec(size=300, window=8, negative=5, hs=0, min_count=1, workers=8) | |
print("Pass 1:") | |
model.neg_labels = zeros(6) # <=== this is needed on the pure-python implementation | |
model.build_vocab([convSentences[0]]) | |
model.train([convSentences[0]], epochs=model.iter, total_examples=model.corpus_count) | |
print("Pass 2:") | |
model.build_vocab([convSentences[1]], update=True) | |
model.train([convSentences[1]], epochs=model.iter, total_examples=model.corpus_count) | |
print("Pass 3:") | |
model.build_vocab([convSentences[2]], update=True) | |
model.train([convSentences[2]], epochs=model.iter, total_examples=model.corpus_count) | |
print("Pass 4:") | |
model.build_vocab([convSentences[3]], update=True) | |
model.train([convSentences[3]], epochs=model.iter, total_examples=model.corpus_count) | |
print("Pass 5:") | |
model.build_vocab([convSentences[4]], update=True) | |
model.train([convSentences[4]], epochs=model.iter, total_examples=model.corpus_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment