我有一个用Gensim创建的FastText模型,该模型使用回调保存每个纪元,导致a known bug出现问题,但是解决方法之后,我仍然无法导入该模型。当我尝试加载它时,我现在得到一个KeyError
:
KeyError Traceback (most recent call last)
<ipython-input-19-c0dfceee0796> in <module>
----> 1 vocab_model = gensim.models.FastText.load('vocab/ft_256_min_50_model_30eps')
~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\fasttext.py in load(cls, *args, **kwargs)
1038 """
1039 try:
-> 1040 model = super(FastText, cls).load(*args, **kwargs)
1041
1042 if not hasattr(model.trainables, 'vectors_vocab_lockf') and hasattr(model.wv, 'vectors_vocab'):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\base_any2vec.py in load(cls, *args, **kwargs)
1248 model.vocabulary.ns_exponent = 0.75
1249 if model.negative and hasattr(model.wv, 'index2word'):
-> 1250 model.vocabulary.make_cum_table(model.wv) # rebuild cum_table from vocabulary
1251 if not hasattr(model, 'corpus_count'):
1252 model.corpus_count = None
~\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\word2vec.py in make_cum_table(self, wv, domain)
1795 train_words_pow = 0.0
1796 for word_index in range(vocab_size):
-> 1797 train_words_pow += wv.vocab[wv.index2word[word_index]].count**self.ns_exponent
1798 cumulative = 0.0
1799 for word_index in range(vocab_size):
KeyError: 'news'
在以前的word2vec模型中,“新闻”位于索引0(我认为是保留的,但无论如何),pdb
确认FastText模型也是如此:
ipdb> wv.vocab['news']
*** KeyError: 'news'
ipdb> wv.index2word[0]
'news'
可能是什么原因造成的?