Skip to content

Instantly share code, notes, and snippets.

@HeshamMeneisi
Last active May 23, 2018 15:52
Show Gist options
  • Save HeshamMeneisi/f56889eb20afa3b543355ef25ee8f01c to your computer and use it in GitHub Desktop.
Save HeshamMeneisi/f56889eb20afa3b543355ef25ee8f01c to your computer and use it in GitHub Desktop.
from gensim.models import Doc2Vec
import pickle
with open('./docs_proc.pkl', 'rb') as file:
docs = pickle.load(file)
model = Doc2Vec(docs, vector_size = 500, window = 9, min_count = 20, workers=8, dm=0)
with open('./d2v_model.pkl', 'wb') as file:
pickle.dump(model, file)
epochs = 5
start_alpha = 0.025
end_alpha = 0.0001
alpha_change = (start_alpha-end_alpha)/epochs
assert gensim.models.doc2vec.FAST_VERSION > -1
for i in range(epochs):
print('Epoch', i)
model.train(docs, total_examples=model.corpus_count, epochs=1)
model.alpha -= alpha_change
model.min_alpha = model.alpha
with open('./d2v_model_trained.pkl', 'wb') as file:
pickle.dump(model, file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment