Word2VecAndTsne icon indicating copy to clipboard operation
Word2VecAndTsne copied to clipboard

TwoStageReduce.py AttributeError: 'Word2Vec' object has no attribute 'vocab'

Open washingon opened this issue 7 years ago • 4 comments
trafficstars

Jeff - I get error AttributeError: 'Word2Vec' object has no attribute 'vocab' in TwoStageReduce.py

Environment: Ubuntu 16.04.3 LTS python 2.7 gensim (3.2.0) Steps to reproduce error:

  1. modify TrainModel.py line 38 to: model.train(sentences, total_examples=model.corpus_count, epochs=model.iter) as noted in #3
  2. python TrainModel.py
  3. python TwoStageReduce.py
loading model...
- done
converting model/words to numpy array...
- loading 50000 most common words...
- creating list of words/vectors for reduction...
  - keeping only 50000 most common words
Traceback (most recent call last):
  File "TwoStageReduce.py", line 99, in <module>
    for word in model.vocab:
AttributeError: 'Word2Vec' object has no attribute 'vocab'

washingon avatar Dec 12 '17 01:12 washingon

Hmm, I think it's due to a change in gensim. This post seems to suggest you have to change the syntax for accessing the vocab.

Can you try changing the line to for word in model.wv.vocab: and see if it works?

jeffThompson avatar Dec 12 '17 15:12 jeffThompson

yes, I can correct the error by changing line 99 in TwoStageReduce.py from: for word in model.vocab: to: for word in model.wv.vocab:

washingon avatar Dec 12 '17 15:12 washingon

Great! Please let me know if you hit any other errors and I'll update the repo.

jeffThompson avatar Dec 12 '17 15:12 jeffThompson

if word in word2vec_model.wv.vocab: TypeError: unhashable type: 'list'

kusumlata123 avatar Oct 09 '19 05:10 kusumlata123