我在PC上训练了LDA模型,并使用model.save()命令将其保存在本地。我可以在PyCharm中加载该模型并输出主题,但是当我尝试在Jupiter Notebook中加载相同的模型时,我得到一个错误。
有人遇到相同的问题并解决吗? 下面是完整的错误输出:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-14-043e6d6083e2> in <module>
1 # Loading saved model
----> 2 model = models.LdaModel.load('information_extraction/optimal_LDA3.model')
3 # model_topics = model.show_topics(formatted=True)
4 # pprint.pprint(model.print_topics(num_words=15))
~/anaconda3/lib/python3.7/site-packages/gensim/models/ldamodel.py in load(cls, fname, *args, **kwargs)
1636 """
1637 kwargs['mmap'] = kwargs.get('mmap', None)
-> 1638 result = super(LdaModel, cls).load(fname, *args, **kwargs)
1639
1640 # check if `random_state` attribute has been set after main pickle load
~/anaconda3/lib/python3.7/site-packages/gensim/utils.py in load(cls, fname, mmap)
424 compress, subname = SaveLoad._adapt_by_suffix(fname)
425
--> 426 obj = unpickle(fname)
427 obj._load_specials(fname, mmap, compress, subname)
428 logger.info("loaded %s", fname)
~/anaconda3/lib/python3.7/site-packages/gensim/utils.py in unpickle(fname)
1382 # Because of loading from S3 load can't be used (missing readline in smart_open)
1383 if sys.version_info > (3, 0):
-> 1384 return _pickle.load(f, encoding='latin1')
1385 else:
1386 return _pickle.loads(f.read())
ModuleNotFoundError: No module named 'numpy.random._pickle'
答案 0 :(得分:0)
已解决: 问题是numpy版本有所不同。我在numpy == 1.17.0上训练了LDA模型,然后安装了Anaconda并以numpy == 1.16.4运行Jupiter。