提交 ddd2a977 编写于 作者: H Hai Liang Wang

[nearby] Check eq before computing sim

上级 2dca2a1b
......@@ -13,7 +13,7 @@ Welcome
setup(
name='synonyms',
version='3.3',
version='3.3.1',
description='Chinese Synonyms for Natural Language Processing and Understanding',
long_description=LONGDOC,
author='Hai Liang Wang, Hu Ying Xi',
......
......@@ -233,13 +233,15 @@ class KeyedVectors():
"""
Get nearest words with KDTree, ranking by cosine distance
"""
word = word.strip()
v = self.word_vec(word)
[distances], [points] = self.kdt.query(array([v]), k = size, return_distance = True)
assert len(distances) == len(points), "distances and points should be in same shape."
words, scores = [], {}
for (x,y) in zip(points, distances):
w = self.index2word[x]
s = utils.cosine(v, self.syn0[x])
if w == word: s = 1.0
else: s = utils.cosine(v, self.syn0[x])
if s < 0: s = abs(s)
words.append(w)
scores[w] = min(s, 1.0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册