Reputation: 43
i have migrated from gensim 3.8.3 to 4.1.2 and i am using this
claim = [token for token in claim_text if token in w2v_model.wv.vocab]
reference = [token for token in ref_text if token in w2v_model.wv.vocab]
i am not sure how to replace w2v_model.wv.vocab to newer attribute and i am getting this error
KeyedVectors' object has no attribute 'wv' can anyone please help.
Upvotes: 4
Views: 12065
Reputation: 31
KeyedVectors object has no attribute wv
The vocab attribute was removed from KeyedVector in Gensim 4.0.0 If you look for the vector of word 'maybe', instead of using word2vec.wv.['maybe'],use word2vec['maybe']. For more information, Use KeyedVector's .key_to_index dict, .index_to_key list, and methods .get_vecattr(key, attr) and .set_vecattr(key, attr, new_val) instead.
See https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4
model.mv.similarity('woman', 'man') #instead of this use Below
model.similarity('woman', 'man')
Upvotes: 3
Reputation: 54183
You only use the .wv
property to fetch the KeyedVectors
object from another more complete algorithmic model, like a full Word2Vec
model (which contains a KeyedVectors
in its .wv
attribute).
If you're already working with just-the-vectors, there's no need to request the word-vectors subcomponent. Whatever you were going to do, you just do to the KeyedVectors
directly.
However, you're also using the .vocab
attribute, which has been replaced. See the migration FAQ for more details:
(Mainly: instead of doing an in w2v_model.wv.vocab
, you may only need to do in kv_model
or in kv_model.key_to_index
.)
Upvotes: 6