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