如何将tensorflow的word2vec保存在文本/二进制文件中以供以后使用kNN输出? [英] How to save the tensorflow's word2vec in text/binary file for later use of kNN output?
问题描述
我已经在tensorflow中训练了word2vec模型.但是当我保存会话时,它仅输出model.ckpt.data
/.index
/.meta
文件.
I have trained a word2vec model in tensorflow. But when I save the session, it only outputted model.ckpt.data
/ .index
/ .meta
files.
我当时正在考虑在检索最接近的单词时实施KNN方法.我看到了使用gensim的答案,但是如何将我的tensorflow word2vec模型首先保存到.txt
中?
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?
推荐答案
我只是遇到了同样的问题,并尝试了Maxim的解决方案.
I just had the same problem and tried Maxim's solution.
您需要替换以下行:
word = word_to_idx[i]
使用
word = idx_to_word[i]
您可以使用以下代码简单地将word_to_idx-dictionary反转:
You can simply reverse the word_to_idx-dictionary with the following code:
idx_to_word = dict(zip(word_to_idx.values(), word_to_idx.keys()))
除此之外,他的解决方案效果很好.
Except for that, his solution works fine.
这篇关于如何将tensorflow的word2vec保存在文本/二进制文件中以供以后使用kNN输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!