[英]Can't load saved gensim word2vec model
I tried saving a word2vec model that I had trained with gensim like so: 我尝试保存用gensim训练过的word2vec模型,如下所示:
from gensim.models import Word2Vec
model = Word2Vec(sentences, parameters)
model.save('modelfile.model')
Now when I try Word2Vec.load('modelfile.model')
, I get: 现在,当我尝试
Word2Vec.load('modelfile.model')
,我得到:
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
Can post the full traceback if it helps. 如果有帮助,可以发布完整的回溯。
That's odd. 真奇怪 Are you using the exact same Python environment & gensim version for the
load()
as the save()
? 您是否使用与
save()
完全相同的Python环境和gensim版本的load()
save()
? How did you install gensim & numpy? 您是如何安装gensim和numpy的?
When I search for that error, I find other discussions that suggest it may be a symptom of having pickled (saved) a numpy array from numpy 1.16. 当我搜索该错误时,我发现其他讨论表明这可能是从numpy 1.16腌制(保存)一个numpy数组的症状。 but trying to unpickle (load) it in an earlier numpy.
但尝试在较早的numpy中解开(加载)它。 See for example:
参见例如:
https://github.com/numpy/numpy/issues/12825#issuecomment-456561919 https://github.com/numpy/numpy/issues/12825#issuecomment-456561919
It looks like numpy has recently merged a fix – https://github.com/numpy/numpy/issues/12837 – but in the meantime your best bet might be making sure the place where you're loading is using numpy 1.16.0+. 它看起来像numpy的最近合并的修复- https://github.com/numpy/numpy/issues/12837 -但在此期间你最好的选择可能是确保你在哪里装载利用numpy的1.16.0的地方+。
I would try virtualenv
just to avoid any conflicts among packages and environments. 我会尝试使用
virtualenv
以避免软件包和环境之间的任何冲突。 Virtualenv
is a tool to create isolated Python environments. Virtualenv
是用于创建隔离的Python环境的工具。 Here are the quick steps to setup virtualenv
and give it a try to load your word2vec
model. 以下是设置
virtualenv
并尝试加载word2vec
模型的快速步骤。
sudo pip install virtualenv # install virtualenv
virtualenv test1 # create an env named test1
cd test1 # go ot test1
source bin/activate # activate test1
pip install gensim # install your packages for test1 env
python path-to-your-file.py # run your program
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.