Skip to content

Instantly share code, notes, and snippets.

@mino98
Created January 24, 2018 15:50
Show Gist options
  • Save mino98/f876cff1f747cdd0b858b7a7d995e2f9 to your computer and use it in GitHub Desktop.
Save mino98/f876cff1f747cdd0b858b7a7d995e2f9 to your computer and use it in GitHub Desktop.
Testcase for #1019
from gensim.models import doc2vec
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.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)
# from pprint import pprint
# pprint(model.docvecs.doctag_syn0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment