我有以下代码:
from gensim.models import Word2Vec
model = Word2Vec.load('model2')
X = model[model.wv.vocab]
这段代码适用于我的一台机器,但不适用于另一台机器。模型文件是一样的。这是怎么回事?我收到的错误消息如下:
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/gensim/models/word2vec.py", line 1330, in load
model = super(Word2Vec, cls).load(*args, **kwargs)
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/gensim/models/base_any2vec.py", line 1244, in load
model = super(BaseWordEmbeddingsModel, cls).load(*args, **kwargs)
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/gensim/models/base_any2vec.py", line 603, in load
return super(BaseAny2VecModel, cls).load(fname_or_handle, **kwargs)
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/gensim/utils.py", line 427, in load
obj._load_specials(fname, mmap, compress, subname)
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/gensim/utils.py", line 458, in _load_specials
getattr(self, attrib)._load_specials(cfname, mmap, compress, subname)
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/gensim/utils.py", line 469, in _load_specials
val = np.load(subname(fname, attrib), mmap_mode=mmap)
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/numpy/lib/npyio.py", line 440, in load
pickle_kwargs=pickle_kwargs)
File "/home/ec2-user/miniconda3/envs/word2vec/lib/python3.7/site-packages/numpy/lib/format.py", line 771, in read_array
array.shape = shape
ValueError: cannot reshape array of size 16777184 into shape (134441,128)
为了安装 gensim,我使用了conda install -c anaconda gensim
冉冉说
相关分类