如何将word2vec转换为glove形式

2024-09-29 03:40:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了一些研究,发现gensim有一个将glow转换为word2vecGLove2Wrod2Vec的脚本。我想做相反的事。在

有没有简单的方法可以使用gensim或任何其他库进行转换


Tags: 方法脚本gensimglowword2vecglove2wrod2vec
1条回答
网友
1楼 · 发布于 2024-09-29 03:40:05

手套向量文件格式和word2vec文件格式的唯一区别是在word2vec格式的.txt开头的一行

<num words> <num dimensions>

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

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

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的第一行9 4告诉我们词汇表中有9个单词,每个单词有4个维度。在

TL;DR 因此,要从w2v->;glove转换:从w2v中删除{}行。你可以从文件中推断出来。在

要从glove->;w2v转换:将<num words> <num dimensions>行添加到glove。在

你可以手动操作,但是gensim提供了一种从一个到另一个的方法。在

相关问题 更多 >