【问题标题】:How to find the similar sentence based on keyword that does not directly appear in sentences?如何根据不直接出现在句子中的关键字找到相似的句子?
【发布时间】:2021-02-21 13:41:17
【问题描述】:

我需要返回一个包含关键字的文本。让我们考虑以下示例:

keyword = "configure"
texts = [ 
   "The system configuration document should be uploaded to the repository. Please contact the dev team.",
   "To do the system setup, please follow the instructions." 
]

关键字configure 没有出现在任何文本中。但是类似的词configuration出现在第一句。因此预期的输出是:

The system configuration document should be uploaded to the repository. Please contact the dev team.

我知道可以计算[单词和文本之间的语义相似度][1]。但是,对于我的案例,它经常返回不准确的结果。

我正在评估的另一种方法是应用词干提取和词形还原。但是,configureconfiguration 有不同的词干。

最后我还考虑了Word2Vec 模型...但是,在这种情况下,我不确定如何有效地使用这种方法。

import gensim.downloader as api

word_vectors = api.load("glove-wiki-gigaword-100") 

word_vectors.similarity("configure","configuration")

是否有任何最先进的方法来处理我的任务? [1]:https://medium.com/@adriensieg/text-similarities-da019229c894

【问题讨论】:

    标签: python nlp gensim word2vec


    【解决方案1】:

    如果你的句子长度不是太长,你可以尝试对句子中单词的向量求和,然后搜索你的关键字和这个和的相似度。

    否则,您可以尝试从句子中提取关键字,然后将它们的向量相加,以搜索最接近您的关键字。

    【讨论】:

    • 在您的场景中,我如何确定最近的向量具有相同的根?例如,在某些句子中,最接近activate 的单词可能是restart,但这对我来说是不正确的。我只需要获取包含具有相同根的关键字的文本。你知道我怎样才能得到词根(不是词干)吗?
    • 其实activate 并不是最好的例子。让我们以diagnosediagnosisdiagnostic 为例。如果我进行词干提取,我会得到diagnosdiagnosidiagnost...我怎样才能得到diagnos(最短的一个)以便所有人能够比较它们?
    • 试试看polyglot库,它可以提取词根、后缀、词尾等词素...polyglot.readthedocs.io/en/latest/MorphologicalAnalysis.html
    猜你喜欢
    • 2021-11-15
    • 2015-01-23
    • 2010-11-22
    • 2021-03-29
    • 2020-12-22
    • 1970-01-01
    • 2012-02-19
    • 2021-10-08
    • 1970-01-01
    相关资源
    最近更新 更多