我正在创建一个聊天机器人。所以,我需要二进制格式的word2vec文件。 当我加载bin文件时,我收到了这种类型的错误。
import gensim
model = gensim.models.Word2Vec.load('GoogleNews-vectors-negative300.bin')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/surya/anaconda3/lib/python3.6/site-packages/gensim/models/word2vec.py", line 975, in load
return super(Word2Vec, cls).load(*args, **kwargs)
File "/home/surya/anaconda3/lib/python3.6/site-packages/gensim/models/base_any2vec.py", line 629, in load
model = super(BaseWordEmbeddingsModel, cls).load(*args, **kwargs)
File "/home/surya/anaconda3/lib/python3.6/site-packages/gensim/models/base_any2vec.py", line 278, in load
return super(BaseAny2VecModel, cls).load(fname_or_handle, **kwargs)
File "/home/surya/anaconda3/lib/python3.6/site-packages/gensim/utils.py", line 395, in load
obj = unpickle(fname)
File "/home/surya/anaconda3/lib/python3.6/site-packages/gensim/utils.py", line 1302, in unpickle
return _pickle.load(f, encoding='latin1')_pickle.
UnpicklingError: invalid load key, '3'.
答案 0 :(得分:8)
如果是二进制文件,您需要像这样提及:
import gensim.models.keyedvectors as word2vec
model = word2vec.KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True)