Skip to content

Commit

Permalink
Fix local import degrading the performance of word2vec model loading (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lopusz authored and mpenkov committed Nov 21, 2019
1 parent 1052b9b commit e7c9f0e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gensim/models/utils_any2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import logging
from gensim import utils
import gensim.models.keyedvectors

from numpy import zeros, dtype, float32 as REAL, ascontiguousarray, frombuffer

Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit e7c9f0e

Please sign in to comment.