iro
iro

Reputation: 23

How can I load Word2vec with Gensim without getting an AttributeError?

I am new to Gensim, and I am trying to load my given (pre-trained) Word2vec model. I have 2 files: xxxx.model.wv and a bigger one xxxx.model.wv.syn0.npy.

When I call the following line:

gensim.models.Word2Vec.load('xxxx.model.wv')

I get the following error:

AttributeError: 'EuclideanKeyedVectors' object has no attribute 'negative'

How can I solve this error?

Upvotes: 2

Views: 1188

Answers (2)

JKHenry
JKHenry

Reputation: 11

I face the same question. The main reason is that the model is not a full model object. So, you can load the model use "gensim.models.KeyedVectors.load(model_path)" or "gensim.models.KeyedVectors.load_word2vec_format(model_path, binary=True)". I hope it can solve your question.

Upvotes: 1

gojomo
gojomo

Reputation: 54153

Are you sure your xxxx.model.wv file was a saved full Word2Vec model object?

That error suggests it was instead a EuclideanKeyedVectors – just the vectors, and not a full model with all properties like negative – so you might need to load it as that instead.

Upvotes: 1

Related Questions