zl程序教程

您现在的位置是:首页 >  其他

当前栏目

word2vec:将bin转换为txt

转换 txt bin Word2Vec
2023-09-14 09:11:23 时间

转自: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)