Search code examples
pythongensimword2vec

Error while loading Word2Vec model in gensim


I'm getting an AttributeError while loading the gensim model available at word2vec repository:

from gensim import models
w = models.Word2Vec()
w.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True)
print w["queen"]

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-8219e36ba1f6> in <module>()
----> 1 w["queen"]

C:\Anaconda64\lib\site-packages\gensim\models\word2vec.pyc in __getitem__(self, word)
    761 
    762         """
--> 763         return self.syn0[self.vocab[word].index]
    764 
    765 

AttributeError: 'Word2Vec' object has no attribute 'syn0'

Is this a known issue ?


Solution

  • Fixed the problem with:

    from gensim import models
    w = models.Word2Vec.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True)
    print w["queen"]