gpt4 book ai didi

python - 如何将word2vec转为glove格式

转载 作者:太空宇宙 更新时间:2023-11-04 04:30:26 24 4
gpt4 key购买 nike

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

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

最佳答案

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

<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 个维度。

长话短说因此,要从 w2v 转换-> glove : 删除 <num words> <num dimensions>来自 w2v 的行.无论如何,您都可以从文件中推断出它。

glove 转换-> w2v : 添加 <num words> <num dimensions>线到 glove .

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

关于python - 如何将word2vec转为glove格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52725193/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com