how to extract embedding layer weights and update the word2vec model

538 views
Skip to first unread message

haobangpig

unread,
Dec 5, 2017, 2:16:51 PM12/5/17
to gensim
Recent days, I want to figure out what has changed in the word2vec, when I used the non-static cnn channel in the paper "Convolutional Neural Networks for Sentence Classification keras". And I find that it has been perfactly implemented in keras <https://github.com/alexander-rakhlin/CNN-for-Sentence-Classification-in-Keras>.

So my question is, when we use the pre-trained word embedding vector as the embedding layer's weights, and it will be fine tuned by the back-propagation. So how to set the embedding layer weights (has been trained by the BP) as word2vec model weights and calculate the cosine similarity after bp training. (Like in the paper, the right part in table 3, how to get that)

Is that any way to achieve that?

Ivan Menshikh

unread,
Dec 6, 2017, 9:34:38 AM12/6/17
to gensim
Hi,

You have 2 variants
1. Gensim w2v Keras integration, look at example
2. Extract word vectors manually: model.wv.syn0 - matrix (word X embedding_size), model.wv.index2word - array with words
Reply all
Reply to author
Forward
0 new messages