When I was trying to use a trained word2vec model to find the similar word, it showed that 'Word2Vec' object has no attribute 'most_similar'.
I haven't seen that what are changed of the 'most_similar' attribute from gensim 4.0. When I was using the gensim in Earlier versions, most_similar() can be used as:
model_hasTrain=word2vec.Word2Vec.load(saveBinPath)
y=model_hasTrain.most_similar('price',topn=100)
I don't know that are most_similar() removed or changed? Or do I need to reinstall the gensim? Thank you for solving my problem. Thanks very much.
Please provide the output of:
Windows-2012Server-6.2.9200-SP0
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]
Bits 64
NumPy 1.18.5
SciPy 1.5.0
gensim 4.0.0beta
FAST_VERSION 1
most_similar() is now a part of KeyedVectors:
model_hasTrain = word2vec.Word2Vec.load(saveBinPath)
y = model_hasTrain.wv.most_similar('price', topn=100) # <=== note the .wv
@gojomo looking at the migration guide, I see no mention of most_similar. This is a change we introduced in 4.0.0, right?
Thank you very much! Now it is working! Thanks!
@gojomo looking at the migration guide, I see no mention of
most_similar. This is a change we introduced in 4.0.0, right?
@piskvorky Yes - prior to 4.0, using most_similar on the containing model already generated a "Method will be removed in 4.0.0, use self.wv.most_similar() instead" deprecation warning:
It was removed per that warning before 4.0.0beta - but yes, it should also be mentioned in the migration guide, so I'll add a note about this & related methods there.
Thanks. I also extended the docstrings in word2vec to make this point clearer – will push as part of the final clean-up work (event hooks, model versioning etc).
See added subsection at: https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4#7-methods-like-most_similar-wmdistance-doesnt_match-similarity--others-should-now-be-called-only-on-sets-of-word-vectors-not-containing-word2vecdoc2vecfasttext-full-models