gensim error: 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.
Solution:
1. directly modify the code
Find all the modules of vocab.keys() and modify them if they are mods defined by gensim.
Show:
## Wrong
model = KeyedVectors.load_word2vec_format(word2vec_glove_file)
words = np.random.choice(list(model.vocab.keys()), sample)
## Right
model = KeyedVectors.load_word2vec_format(word2vec_glove_file)
words = np.random.choice(list(model.key_to_index.keys()), sample)
Method 2: install the original version
!pip install gensim==3.0
Read More:
- jupyter notebook Use pyLDAvis Error: AttributeError: module ‘pyLDAvis‘ has no attribute ‘gensim
- [Solved] module ‘numpy.random‘ has no attribute ‘default_rng‘ gensim.model
- When sending an email, an error was reported: AttributeError:’list’ object has no attribute’encode’
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘map‘
- [Solved] AttributeError: ‘_IncompatibleKeys‘ object has no attribute ‘parameters‘
- [Solved] AttributeError: ‘DataParallel‘ object has no attribute ‘save‘
- [Solved] AttributeError: ‘PngImageFile‘ object has no attribute ‘imshow‘
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute
- [Solved] TUM associate.py Scripte Error: AttributeError: ‘dict_keys‘ object has no attribute ‘remove‘
- [Solved] AttributeError: module ‘pandas‘ has no attribute ‘rolling_count‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [How to Solve]AttributeError: module ‘scipy’ has no attribute ‘io’
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- AttributeError: module ‘time‘ has no attribute ‘clock‘ [How to Solve]
- AttributeError: DatetimeProperties object has no attribute
- [Solved] AttributeError: partially initialized module ‘xlwings’ has no attribute ‘App’
- [Solved] AttributeError: module ‘setuptools._distutils‘ has no attribute ‘version‘
- AttributeError: module ‘enum‘ has no attribute ‘IntFlag‘ [How to Solve]
- [Solved] pandas ExcelWrite AttributeError: ‘NoneType‘ object has no attribute ‘group‘