From 63f977a216d26b3acfb1e7c709ac5d4d5ae3edc2 Mon Sep 17 00:00:00 2001 From: lunastera Date: Fri, 4 Sep 2020 12:36:00 +0900 Subject: [PATCH] Integrate what is essentially the same process --- gensim/models/word2vec.py | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/gensim/models/word2vec.py b/gensim/models/word2vec.py index 7abb409511..5a74796c3c 100755 --- a/gensim/models/word2vec.py +++ b/gensim/models/word2vec.py @@ -1105,7 +1105,7 @@ def _job_producer(self, data_iterator, job_queue, cur_epoch=0, total_examples=No """ job_batch, batch_size = [], 0 pushed_words, pushed_examples = 0, 0 - next_alpha = self._get_current_alpha(cur_epoch) + next_alpha = self._get_next_alpha(0.0, cur_epoch) job_no = 0 for data_idx, data in enumerate(data_iterator): @@ -1129,7 +1129,7 @@ def _job_producer(self, data_iterator, job_queue, cur_epoch=0, total_examples=No # words-based decay pushed_words += self._raw_word_count(job_batch) epoch_progress = 1.0 * pushed_words / total_words - next_alpha = self._update_alpha(next_alpha, epoch_progress, cur_epoch) + next_alpha = self._get_next_alpha(epoch_progress, cur_epoch) # add the sentence that didn't fit as the first item of a new job job_batch, batch_size = [data], data_length @@ -1342,30 +1342,11 @@ def _train_epoch(self, data_iterable, cur_epoch=0, total_examples=None, total_wo return trained_word_count, raw_word_count, job_tally - def _get_current_alpha(self, cur_epoch): - """Get the learning rate used in the current epoch. - - Parameters - ---------- - cur_epoch : int - Current iteration through the corpus - - Returns - ------- - float - The learning rate for this epoch (it is linearly reduced with epochs from `self.alpha` to `self.min_alpha`). - - """ - alpha = self.alpha - ((self.alpha - self.min_alpha) * float(cur_epoch) / self.epochs) - return alpha - - def _update_alpha(self, alpha, epoch_progress, cur_epoch): + def _get_next_alpha(self, epoch_progress, cur_epoch): """Get the correct learning rate for the next iteration. Parameters ---------- - alpha : float - UNUSED. epoch_progress : float Ratio of finished work in the current epoch. cur_epoch : int