From 8715c00c714216f8f946583d633df5a381b8ca1f Mon Sep 17 00:00:00 2001 From: Umang Varma Date: Wed, 20 Jun 2018 00:15:54 -0400 Subject: [PATCH] Fix linear decay for learning rate in `Doc2Vec.infer_vector`. Fix #2061 (#2063) * Linear decay for learning rate in infer_vector * remove whitespace --- gensim/models/doc2vec.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gensim/models/doc2vec.py b/gensim/models/doc2vec.py index f57694273d..f79f0153a5 100644 --- a/gensim/models/doc2vec.py +++ b/gensim/models/doc2vec.py @@ -546,6 +546,8 @@ def infer_vector(self, doc_words, alpha=0.1, min_alpha=0.0001, steps=5): if not self.sg: neu1 = matutils.zeros_aligned(self.trainables.layer1_size, dtype=REAL) + alpha_delta = (alpha - min_alpha) / (steps - 1) + for i in range(steps): if self.sg: train_document_dbow( @@ -562,7 +564,7 @@ def infer_vector(self, doc_words, alpha=0.1, min_alpha=0.0001, steps=5): self, doc_words, doctag_indexes, alpha, work, neu1, learn_words=False, learn_hidden=False, doctag_vectors=doctag_vectors, doctag_locks=doctag_locks ) - alpha = ((alpha - min_alpha) / (steps - i)) + min_alpha + alpha -= alpha_delta return doctag_vectors[0]