Python 如何将word2vec转换为手套格式

Python 如何将word2vec转换为手套格式,python,nlp,gensim,word2vec,word-embedding,Python,Nlp,Gensim,Word2vec,Word Embedding,我做了一些研究,发现gensim有一个脚本可以将glove转换为word2vec。我希望做相反的事情 使用gensim或任何其他库是否有简单的转换方法手套矢量文件格式和word2vec文件格式之间的唯一区别是word2vec格式的.txt开头有一行 否则,向量以相同的方式表示。我们不需要改变向量来改变格式 引用您在问题中链接的页面: Both files are presented in text format and almost identical except that word2vec

我做了一些研究,发现gensim有一个脚本可以将glove转换为word2vec。我希望做相反的事情


使用gensim或任何其他库是否有简单的转换方法

手套矢量文件格式和word2vec文件格式之间的唯一区别是word2vec格式的
.txt
开头有一行

否则,向量以相同的方式表示。我们不需要改变向量来改变格式

引用您在问题中链接的页面:

Both files are
presented in text format and almost identical except that word2vec includes
number of vectors and its dimension which is only difference regard to GloVe.
Notes
-----
GloVe format (real example can be founded `on Stanford size <https://nlp.stanford.edu/projects/glove/>`_) ::
    word1 0.123 0.134 0.532 0.152
    word2 0.934 0.412 0.532 0.159
    word3 0.334 0.241 0.324 0.188
    ...
    word9 0.334 0.241 0.324 0.188
Word2Vec format (real example can be founded `on w2v old repository <https://code.google.com/archive/p/word2vec/>`_) ::
    9 4
    word1 0.123 0.134 0.532 0.152
    word2 0.934 0.412 0.532 0.159
    word3 0.334 0.241 0.324 0.188
    ...
    word9 0.334 0.241 0.324 0.188
两个文件都是
以文本格式呈现,除了word2vec包括
向量的数量和它的维数是手套唯一的区别。
笔记
-----
手套格式(实例可在“斯坦福尺码”上找到)::
word1 0.123 0.134 0.532 0.152
word2 0.934 0.412 0.532 0.159
word3 0.334 0.241 0.324 0.188
...
字9 0.334 0.241 0.324 0.188
Word2Vec格式(可以在w2v旧存储库上找到真实示例):
9 4
word1 0.123 0.134 0.532 0.152
word2 0.934 0.412 0.532 0.159
word3 0.334 0.241 0.324 0.188
...
字9 0.334 0.241 0.324 0.188
在上面的例子中,word2vec的第一行
94
告诉我们词汇表中有9个单词,每个单词有4个维度

TL;DR 因此,要从
w2v
->
手套
:从
w2v
中删除
行。不管怎样,你都可以从文件中推断出来

要从
手套
->
w2v
:将
行添加到
手套

您可以手动执行,但gensim提供了一种从一个到另一个的方法