I'm new to deeplearning4j, i want to make sentence classifier using words vector as input for the classifier. I was using python before, where the vector model was generated using gensim, and i want to use that model for this new classifier. Is it possible to use gensim's word2vec model in deeplearning4j.word2vec and how i can do that?
Asked
Active
Viewed 3,395 times
6
-
Please ask this on our Gitter channel. https://gitter.im/deeplearning4j/deeplearning4j There are 4300 DL4J users there. – racknuf Apr 26 '17 at 20:16
-
thanks, i'll try asking there – zunzelf Apr 27 '17 at 05:14
-
Did you get an answer? If so, could you post it here? – Stefan Falk Jun 22 '17 at 00:52
1 Answers
10
Yes, it's possible since Word2Vec implementation defines a standard to structure its model.
To do this:
Using gensim, save the model compatible with Word2Vec implementation:
w2v_model.wv.save_word2vec_format("path/to/w2v_model.bin", binary=True)
From DL4J, load the same pre-trained model:
Word2Vec w2vModel = WordVectorSerializer.readWord2VecModel("path/to/w2v_model.bin");
In fact, you could test the model in both codes and you should see the same results, for instance:
With gensim:
print(w2v_model.most_similar("love"))
print(w2v_model.n_similarity(["man"], ["king"]))
And with DL4J:
System.out.println(w2vModel.wordsNearest("love", 10));
System.out.println(w2vModel.similarity("man", "king"));

Danizz
- 136
- 2
- 7