【问题标题】:Is there a way to use only the word result of most_similar function of gensim?有没有办法只使用 gensim 的 most_similar 函数的单词结果?
【发布时间】:2022-01-19 06:56:43
【问题描述】:

我正在尝试使用最相似的 gensim 函数,但结果以列表的形式出现,让我们说 a=(单词,余弦相似度)。但是我无法通过 a[0] 检索单词。有没有办法访问单词本身?我需要将其用作输入。

【问题讨论】:

    标签: trigonometry gensim word2vec similarity


    【解决方案1】:

    most_similar() 返回的排序结果列表是一个列表,其中每个项目是一个单词及其相似度值的元组。

    之后……

    sims = model.wv.most_similar(my_word)
    top_word = sims[0][0]
    

    ...top_word 的单词与my_word 最相似。

    【讨论】:

    • 你错过了一个括号,但它完全有效,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2020-11-06
    • 2019-07-01
    • 1970-01-01
    • 2019-06-02
    • 2013-04-06
    相关资源
    最近更新 更多