Search code examples
pythonnlpgensimword2vecdoc2vec

AttributeError: 'Word2Vec' object has no attribute 'most_similar' (Word2Vec)


I am using Word2Vec and using a wiki trained model that gives out the most similar words. I ran this before and it worked but now it gives me this error even after rerunning the whole program. I tried to take off return_path=True but im still getting the same error

print(api.load('glove-wiki-gigaword-50', return_path=True))
model.most_similar("glass")

#ERROR:

/Users/me/gensim-data/glove-wiki-gigaword-50/glove-wiki-gigaword-50.gz
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-153-3bf32168d154> in <module>
      1 print(api.load('glove-wiki-gigaword-50', return_path=True))
----> 2 model.most_similar("glass") 

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

#MODEL this is the model I used

    print(
        '%s (%d records): %s' % (
            model_name,
            model_data.get('num_records', -1),
            model_data['description'][:40] + '...',
        )
    )

Edit: here is my gensim download & output

!python -m pip install -U gensim

OUTPUT:

Requirement already satisfied: gensim in ./opt/anaconda3/lib/python3.8/site-packages (4.0.1)

Requirement already satisfied: numpy>=1.11.3 in ./opt/anaconda3/lib/python3.8/site-packages (from gensim) (1.20.1)

Requirement already satisfied: smart-open>=1.8.1 in ./opt/anaconda3/lib/python3.8/site-packages (from gensim) (5.1.0)

Requirement already satisfied: scipy>=0.18.1 in ./opt/anaconda3/lib/python3.8/site-packages (from gensim) (1.6.2)


Solution

  • You are probably looking for <MODEL>.wv.most_similar, so please try:

    model.wv.most_similar("glass")