From a73ab8f7c3b2f7815590a0861bba1d94eaccc123 Mon Sep 17 00:00:00 2001 From: Michal Lopuszynski Date: Wed, 20 Nov 2019 14:43:59 +0100 Subject: [PATCH] Fix local import degrading the performance of word2vec model loading (#2671) --- gensim/models/utils_any2vec.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gensim/models/utils_any2vec.py b/gensim/models/utils_any2vec.py index 563f26b8f5..afc25c772b 100644 --- a/gensim/models/utils_any2vec.py +++ b/gensim/models/utils_any2vec.py @@ -27,6 +27,7 @@ import logging from gensim import utils +import gensim.models.keyedvectors from numpy import zeros, dtype, float32 as REAL, ascontiguousarray, frombuffer @@ -150,7 +151,7 @@ def _save_word2vec_format(fname, vocab, vectors, fvocab=None, binary=False, tota def _add_word_to_result(result, counts, word, weights, vocab_size): - from gensim.models.keyedvectors import Vocab + word_id = len(result.vocab) if word in result.vocab: logger.warning("duplicate word '%s' in word2vec file, ignoring all but first", word) @@ -165,7 +166,7 @@ def _add_word_to_result(result, counts, word, weights, vocab_size): logger.warning("vocabulary file is incomplete: '%s' is missing", word) word_count = None - result.vocab[word] = Vocab(index=word_id, count=word_count) + result.vocab[word] = gensim.models.keyedvectors.Vocab(index=word_id, count=word_count) result.vectors[word_id] = weights result.index2word.append(word)