【发布时间】:2017-08-04 08:59:17
【问题描述】:
我正在使用 WMD 来计算句子之间的相似度。例如:
distance = model.wmdistance(sentence_obama, sentence_president)
参考:https://markroxor.github.io/gensim/static/notebooks/WMD_tutorial.html
不过也有基于大规模杀伤性武器的相似方法(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
【问题讨论】:
-
当您说“还有 WMD 相似选项”时,您指的是什么? (我搜索了 gensim word2vec.py 和 keyedvectors.py 文件,并没有明白你的意思。只有词向量到词向量的相似性方法,这与 Word Mover 的距离完全不同向量集的计算。)通常的情况是,“相似性”度量只是 (1.0 - scaled_distance),但最好知道您正在比较什么。跨度>
-
@gojomo 我的意思是 Word movers 基于距离的相似性。我将在问题中添加详细信息。
-
感谢您提供准确的代码参考。
标签: nlp nltk gensim word2vec word-embedding