word2vec:将bin转换为txt

转自:https://blog.csdn.net/u011684265/article/details/78024064

from gensim.models import word2vec  
  
model = word2vec.Word2Vec.load_word2vec_format('/home/ubuntu/word2vec/PubMed-w2v.bin', binary=True)  
model.save_word2vec_format('/home/ubuntu/word2vec/PubMed-w2v.txt', binary=False) 

但是运行出错:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/gensim/models/word2vec.py", line 1300, in load_word2vec_format
    raise DeprecationWarning("Deprecated. Use gensim.models.KeyedVectors.load_word2vec_format instead.")
DeprecationWarning: Deprecated. Use gensim.models.KeyedVectors.load_word2vec_format instead.

所以使用

from gensim.models import KeyedVectors
model =KeyedVectors.load_word2vec_format('/home/ubuntu/word2vec/PubMed-w2v.bin', binary=True) 
model.save_word2vec_format('/home/ubuntu/word2vec/PubMed-w2v.txt', binary=False) 

 

posted @ 2019-04-11 21:25  lypbendlf  阅读(1445)  评论(0编辑  收藏  举报