【问题标题】:How to convert word2vec to glove format如何将 word2vec 转换为手套格式
【发布时间】:2018-10-09 16:08:38
【问题描述】:

我做了一些研究,发现 gensim 有一个脚本可以将 glove 转换为 word2vec GLove2Wrod2Vec。我想反其道而行之。

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

【问题讨论】:

    标签: python nlp gensim word2vec word-embedding


    【解决方案1】:

    手套矢量文件格式和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 中删除&lt;num words&gt; &lt;num dimensions&gt; 行。无论如何,您都可以从文件中推断出来。

    要从 glove 转换 -> w2v :将 &lt;num words&gt; &lt;num dimensions&gt; 行添加到 glove

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 2020-08-30
      • 1970-01-01
      • 2019-05-26
      • 2020-12-13
      • 2021-04-09
      相关资源
      最近更新 更多