KeyedVectors' object has no attribute 'wv for gensim 4.1.2

Question:

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.

Asked By: bigDaddy

||

Answers:

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:

https://github.com/RaRe-Technologies/gensim/wiki/Migrating-from-Gensim-3.x-to-4#4-vocab-dict-became-key_to_index-for-looking-up-a-keys-integer-index-or-get_vecattr-and-set_vecattr-for-other-per-key-attributes

(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.)

Answered By: gojomo

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')

Ref : 'KeyedVectors' object has no attribute 'wv' / The vocab attribute was removed from KeyedVector in Gensim 4.0.0

Answered By: Vaibhav Gaware