Word2vec bin文件转txt文件

深度学习模型训练时,常常需要下载pretrained embedding,而embedding保存的格式常有.bin和txt。

将.bin文件转为.txt文件。

dependencies:python gensim

from gensim.models.keyedvectors import KeyedVectors

model = KeyedVectors.load_word2vec_format('file.bin', binary=True)
model.save_word2vec_format('file.txt', binary=False)

将txt格式转为gensim格式:

word_vectors=KeyedVectors.load_word2vec_format('/path/to/fasttext/embeddings.txt', binary=False)
word_vectors.save('/path/to/converted') 



作者:codefisher
链接:https://www.jianshu.com/p/558c6bb74210
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自blog.csdn.net/lrt366/article/details/88386024