如何在Gensim中加载对齐的word2vec模型?

时间:2018-11-26 01:58:56

标签: python nlp gensim word2vec

我有一个时间序列数据集。因此,对于每个时间段,我训练了一个word2vec模型并重新调整了模型。

但是,当我尝试按以下方式加载对齐的word2vec模型时,出现以下错误。

#Load model
model = word2vec.Word2Vec.load('model_1970')

错误:

train_words_pow += wv.vocab[wv.index2word[word_index]].count**power
KeyError: 'ctrx'

有没有办法解决此错误? :)

我已经附上了一个经过训练的word2vec模型样本,该模型会出于测试目的而给出错误

链接:https://drive.google.com/file/d/1IBbUgeAubr2xzNYLKZgPt34xOEsW92bO/view?usp=sharing

编辑: 下面是我程序的日志。

2018-11-30 14:23:43,897 : INFO : loading Word2Vec object from model_1970
2018-11-30 14:23:43,961 : INFO : loading wv recursively from model_1970.wv.* with mmap=None
2018-11-30 14:23:43,965 : INFO : loading vectors from model_1970.wv.vectors.npy with mmap=None
2018-11-30 14:23:44,005 : INFO : setting ignored attribute vectors_norm to None
2018-11-30 14:23:44,009 : INFO : loading vocabulary recursively from model_1970.vocabulary.* with mmap=None
2018-11-30 14:23:44,009 : INFO : loading trainables recursively from model_1970.trainables.* with mmap=None
2018-11-30 14:23:44,009 : INFO : loading syn1neg from model_1970.trainables.syn1neg.npy with mmap=None
2018-11-30 14:23:44,053 : INFO : setting ignored attribute cum_table to None
2018-11-30 14:23:44,053 : INFO : loaded model_1970
Reloaded modules: __mp_main__
Traceback (most recent call last):

  File "<ipython-input-3-3b9230dacba9>", line 1, in <module>
    runfile('C:/Users/Emi/Desktop/code/word2vec_distance.py', wdir='C:/Users/Emi/Desktop/code')

  File "C:\Users\Emi\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "C:\Users\Emi\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Emi/Desktop/code/word2vec_distance.py", line 26, in <module>
    model_1 = word2vec.Word2Vec.load(word2vec_model_name_1)

  File "C:\Users\Emi\Anaconda3\lib\site-packages\gensim\models\word2vec.py", line 975, in load
    return super(Word2Vec, cls).load(*args, **kwargs)

  File "C:\Users\Emi\Anaconda3\lib\site-packages\gensim\models\base_any2vec.py", line 631, in load
    model.vocabulary.make_cum_table(model.wv)  # rebuild cum_table from vocabulary

  File "C:\Users\Emi\Anaconda3\lib\site-packages\gensim\models\word2vec.py", line 1383, in make_cum_table
    train_words_pow += wv.vocab[wv.index2word[word_index]].count**power

KeyError: 'cmnx'

0 个答案:

没有答案