gpt4 book ai didi

nlp - wmd(词移动距离)和基于 wmd 的相似度有什么区别?

转载 作者:行者123 更新时间:2023-12-02 22:31:11 26 4
gpt4 key购买 nike

我正在使用 WMD 来计算句子之间的相似度。例如:

distance = model.wmdistance(sentence_obama, sentence_president)

引用:https://markroxor.github.io/gensim/static/notebooks/WMD_tutorial.html

但是,还有基于 WMD 的相似性方法(WmdSimilarity)。

引用: https://markroxor.github.io/gensim/static/notebooks/WMD_tutorial.html

除了明显的一个是距离,另一个是相似之外,两者之间还有什么区别?

更新:除了表示方式不同之外,两者完全相同。

n_queries = len(query)
result = []
for qidx in range(n_queries):
# Compute similarity for each query.
qresult = [self.w2v_model.wmdistance(document, query[qidx]) for document in self.corpus]
qresult = numpy.array(qresult)
qresult = 1./(1.+qresult) # Similarity is the negative of the distance.

# Append single query result to list of all results.
result.append(qresult)

https://github.com/RaRe-Technologies/gensim/blob/develop/gensim/similarities/docsim.py

最佳答案

我认为通过“更新”,您或多或少回答了自己的问题。

一个是距离,另一个是相似度,这是两种计算之间的唯一区别。作为笔记本,您可以在 relevant section 中链接笔记:

WMD is a measure of distance. The similarities in WmdSimilarity are simply the negative distance. Be careful not to confuse distances and similarities. Two similar documents will have a high similarity score and a small distance; two very different documents will have low similarity score, and a large distance.

正如您摘录的代码所示,所使用的相似性度量并不完全是“负”距离,而是经过缩放的,因此所有相似性值都从 0.0(不包括)到 1.0(包括)。 (也就是说,零距离变为 1.0 相似度,但距离越来越大,相似度越来越接近 0.0。)

关于nlp - wmd(词移动距离)和基于 wmd 的相似度有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45502464/

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