AttributeError: 'Word2Vec' object has no attribute 'syn0'

11,920 views
Skip to first unread message

Kunwoo Park

unread,
Mar 6, 2017, 2:48:37 AM3/6/17
to gensim
Hi,

I am Kunwoo who has used nlp models on gensim.
I've found an error when I tried to run code examples on word2vec, which is available on Kaggle.

>>> model = Word2Vec.load(FILE_PATH)
>>> type(model.syn0)

Error message:
AttributeError: 'Word2Vec' object has no attribute 'syn0'

I found similar errors happen when others try to access vocabulary of word2vec models (model.vocab), after the major upgrade of gensim (v1.0.1). So I guess this error is also from the same reason.

Does anyone know how to access syn0 matrix on gensim v1.0.1?
Thank you so much in advance!

Best regards,

Lev Konstantinovskiy

unread,
Mar 6, 2017, 6:49:20 AM3/6/17
to gensim
Hi Kunwoo,

In order to share word vector querying code between different training algos(Word2Vec, Fastext, WordRank, VarEmbed) we have separated storage and querying of word vectors into a separate class KeyedVectors.

Two methods and several attributes in word2vec class have been deprecated. The methods are load_word2vec_format and save_word2vec_format. The attributes are syn0normsyn0vocabindex2word . They have been moved to KeyedVectors class.

After upgrading to this release you might get exceptions about deprecated methods or missing attributes.

DeprecationWarning: Deprecated. Use model.wv.save_word2vec_format instead.
AttributeError: 'Word2Vec' object has no attribute 'vocab'

To remove the exceptions, you should use
KeyedVectors.load_word2vec_format instead of  Word2Vec.load_word2vec_format
word2vec_model.wv.save_word2vec_format instead of  word2vec_model.save_word2vec_format
model.wv.syn0norm instead of  model.syn0norm
model.wv.syn0 instead of  model.syn0
model.wv.vocab instead of model.vocab
model.wv.index2word instead of  model.index2word


See more information in the release notes.

There was also warning shown in 0.13.4 December release to encourage users to update the code:

WARNING:gensim.models.word2vec:direct access to syn0 will not be supported in future gensim releases, please use model.wv.syn0


Regards
Lev

Kunwoo Park

unread,
Mar 6, 2017, 6:56:56 AM3/6/17
to gen...@googlegroups.com
Hi Lev,
Thank you so much for your detailed explanations. Now everything is clear.

Best regards,
Kunwoo


--
You received this message because you are subscribed to a topic in the Google Groups "gensim" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gensim/hlYgjqEVocw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gensim+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages