AttributeError:Gensim 4.0.0中已从KeyedVector中删除vocab属性

 

  File "C:\Python38\lib\site-packages\gensim\models\keyedvectors.py", line 735, in vocab    raise AttributeError(AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0.Use KeyedVector's .key_to_index dict, .index_to_key list, and methods .get_vecattr(key, attr) and .set_vecattr(key, attr, new_val) instead.See https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4

 

方法1.  直接修改代码找到所有的 vocab.keys() 的模块,则将其进行修改:## 错误代码:model = KeyedVectors.load_word2vec_format(word2vec_glove_file)words = np.random.choice(list(model.vocab.keys()), sample)## 正确代码:model = KeyedVectors.load_word2vec_format(word2vec_glove_file)words = np.random.choice(list(model.key_to_index.keys()), sample)  方法2. 安装原来的版本 [可行]!pip install gensim==3.7.3 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

 

 

https://blog.csdn.net/qsx123432/article/details/120572252

 

查看原文