Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get weight matrices from gensim word2Vec

I am using gensim word2vec package in python. I would like to retrieve the W and W' weight matrices that have been learn during the skip-gram learning.

It seems to me that model.syn0 gives me the first one but I am not sure how I can get the other one. Any idea?

I would actually love to find any exhaustive documentation on models accessible attributes because the official one does not seem to be precise (for instance syn0 is not described as an attribute)

like image 965
Arcyno Avatar asked Dec 15 '16 11:12

Arcyno


1 Answers

The model.wv.syn0 contains the input embedding matrix. Output embedding is stored in model.syn1 when it's trained with hierarchical softmax (hs=1) or in model.syn1neg when it uses negative sampling (negative>0). That's it! When both hierarchical softmax and negative sampling are not enabled, Word2Vec uses a single weight matrix model.wv.syn0 for training.

See also a related discussion here.

like image 93
Maxim Avatar answered Sep 20 '22 14:09

Maxim