AttributeError: Can't get attribute on <module 'gensim.models.word2vec'

AttributeError: Can't get attribute on <module 'gensim.models.word2vec'

我在带有 M1 芯片的 macOS Big Sur 上使用 python 3.9.1。 而且,gensim是4.0.1

我尝试使用预训练的 Word2Vec 模型并 运行 下面的代码:

from gensim.models.word2vec import Word2Vec

model_path = '/path/to/word2vec.gensim.model'

model = Word2Vec.load(model_path)

但是,我收到以下错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-11-4c1c2f93fadb> in <module>
      1 from gensim.models.word2vec import Word2Vec
      2 
----> 3 model = Word2Vec.load(model_path)

~/opt/miniconda3/lib/python3.9/site-packages/gensim/models/word2vec.py in load(cls, rethrow, *args, **kwargs)
   1932                 "Try loading older model using gensim-3.8.3, then re-saving, to restore "
   1933                 "compatibility with current code.")
-> 1934             raise ae
   1935 
   1936     def _load_specials(self, *args, **kwargs):

~/opt/miniconda3/lib/python3.9/site-packages/gensim/models/word2vec.py in load(cls, rethrow, *args, **kwargs)
   1920         """
   1921         try:
-> 1922             model = super(Word2Vec, cls).load(*args, **kwargs)
   1923             if not isinstance(model, Word2Vec):
   1924                 rethrow = True

~/opt/miniconda3/lib/python3.9/site-packages/gensim/utils.py in load(cls, fname, mmap)
    484         compress, subname = SaveLoad._adapt_by_suffix(fname)
    485 
--> 486         obj = unpickle(fname)
    487         obj._load_specials(fname, mmap, compress, subname)
    488         obj.add_lifecycle_event("loaded", fname=fname)

~/opt/miniconda3/lib/python3.9/site-packages/gensim/utils.py in unpickle(fname)
   1456     """
   1457     with open(fname, 'rb') as f:
-> 1458         return _pickle.load(f, encoding='latin1')  # needed because loading from S3 doesn't support readline()
   1459 
   1460 

AttributeError: Can't get attribute 'Vocab' on <module 'gensim.models.word2vec' from '/Users//opt/miniconda3/lib/python3.9/site-packages/gensim/models/word2vec.py'>

这里是 link 我得到这个模型的地方 https://github.com/shiroyagicorp/japanese-word2vec-model-builder

提前致谢。

问题是引用的存储库在 incredibly old version of GenSim 上训练了一个模型,这使得它与当前版本不兼容。

您可以检查 lifecycle meta data 是否为您提供有关实际版本的任何指示,然后尝试从那里更新您的模型。 该文档还提供了一些提示 upgrading your older trained models, but even those are relatively weak and point mostly to re-training. Similarly, even migrating from GenSim 3.X to 4.X 没有引用直接升级方法,但可以让您了解具体要注意哪些参数。

我的建议是尝试用任何以前的 3.X 版本加载它,看看你在那里加载它是否更成功。