【发布时间】:2021-03-22 10:06:52
【问题描述】:
我试图找出 2 个句子的相似程度。 为此,我使用了 gensim word mover distance,因为我试图找到它的相似性,所以我喜欢它:
sim = 1 - wv.wmdistance(sentence_obama, sentence_president)
我输入的是 2 个字符串:
sentence_obama = 'Obama speaks to the media in Illinois'
sentence_president = 'The president greets the press in Chicago'
我使用的模型是您可以在网上找到的模型:word2vec-google-news-300 我用这段代码加载它:
wv = api.load("word2vec-google-news-300")
它给了我合理的结果。 这就是问题开始的地方。 对于我可以从文档here 中读到的内容,似乎 wmd 将字符串列表而不是像我这样的字符串作为输入!
def preprocess(sentence):
return [w for w in sentence.lower().split() if w not in stop_words]
sentence_obama = preprocess(sentence_obama)
sentence_president = preprocess(sentence_president)
sim = 1 - wv.wmdistance(sentence_obama, sentence_president)
当我遵循文档时,我得到的结果真的不同:
wmd using string as input: 0.5562025871542842
wmd using list of string as input: -0.0174646259300113
我真的很困惑。为什么它使用字符串作为输入并且比我提供文档要求的效果更好?
【问题讨论】: