I have trained a word2vec model in tensorflow. But when I save the session, it only outputted model.ckpt.data
/ .index
/ .meta
files.
I was thinking of implementing KNN method in retrieving nearest words. I saw answers of using gensim, but how can I save my tensorflow word2vec model into .txt
first?
I just had the same problem and tried Maxim's solution.
You need to replace the line:
with
You can simply reverse the word_to_idx-dictionary with the following code:
Except for that, his solution works fine.
Simply evaluate the embeddings matrix into a numpy array and write it to the file along with resolved words. Sample code: