Word2VecAndTsne
Word2VecAndTsne copied to clipboard
TwoStageReduce.py AttributeError: 'Word2Vec' object has no attribute 'vocab'
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:
- modify TrainModel.py line 38 to: model.train(sentences, total_examples=model.corpus_count, epochs=model.iter) as noted in #3
- python TrainModel.py
- 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'
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?
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:
Great! Please let me know if you hit any other errors and I'll update the repo.
if word in word2vec_model.wv.vocab: TypeError: unhashable type: 'list'