【问题标题】:How to create gensim word2vec model using pre trained word vectors?如何使用预训练的词向量创建 gensim word2vec 模型?
【发布时间】:2017-10-12 03:59:07
【问题描述】:

我使用分布式 word2vec 算法创建了词向量。现在我有了单词和它们对应的向量。如何使用这些词和向量构建 gensim word2vec 模型?

【问题讨论】:

    标签: nlp gensim word2vec text-analysis word-embedding


    【解决方案1】:

    我不确定您是否使用 gensim 或其他工具创建了 word2vec 模型,但如果正确理解您的问题,您只想使用 gensim 加载 word2vec 模型。这是通过以下方式完成的:

    import gensim
    w2v_file = codecs.open(WORD2VEC_PATH, encoding='utf-8')
    model = gensim.models.KeyedVectors.load_word2vec_format(w2v_file, binary=True)  # or binary=False if the model is not compressed
    

    但是,如果您想做的是纯粹使用 gensim 从头开始​​(即从原始文本)训练 word2vec 模型,这里是 tutorial on how to train word2vec model using gensim

    【讨论】:

    • 谢谢,这正是我要找的。​​span>
    • 您能否提供样本 w2v_file 或帮我生成该格式?我将单词及其向量放在一行中,由空格分隔,单词由行分隔。谢谢你。 @sophros
    • 你试过下面的方法吗? from gensim.models import word2vec model = word2vec.Word2Vec.load_word2vec_format('path/to/GoogleNews-vectors-negative300.bin', binary=False) 重要的部分是binary=False
    • 它确实帮助了我,谢谢。我使用 Microsoft multiverso 训练了我的语料库。现在我可以使用 load_word2vec_format 来创建我的模型了。
    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 2015-06-17
    • 2017-11-25
    • 2019-07-12
    • 2022-01-03
    • 2020-06-02
    相关资源
    最近更新 更多