[Word2Vec] バイナリファイルからテキストファイル、テキストファイルからバイナリファイルへ変換

w2vで処理したのはいいけどバイナリファイルにするの忘れてた!とか、テキストファイルが欲しくなった!とかに使えそうなやつです。
gensimが必要になります。

$ pip install gensim

バイナリファイルからテキストファイルへ変換する場合は、テキストファイルのサイズが大きくなるのでHDD/SSDの記憶容量にご注意ください。
処理にそこそこ時間がかかります。

https://pastebin.com/2w2Bc8eT


from gensim.models.keyedvectors import KeyedVectors
 
# Convert binary file to text file
w2v_model = KeyedVectors.load_word2vec_format('Path to bin file', binary=True)
w2v_model.save_word2vec_format('Path to output', binary=False)
 
# Convert text file to binary file
w2v_model = KeyedVectors.load_word2vec_format('Path to text file', binary=False)
w2v_model.save_word2vec_format('Path to output', binary=True)

SNSでもご購読できます。

コメントを残す