Skip to content

Commit

Permalink
Make SparseTermSimilarityMatrix constructor defensive about most_simi…
Browse files Browse the repository at this point in the history
…lar(topn=0)
  • Loading branch information
Witiko committed May 17, 2019
1 parent b34b06e commit b588bd7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions gensim/similarities/termsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ def __init__(self, source, dictionary=None, tfidf=None, symmetric=True, positive
num_rows = nonzero_limit - num_nonzero
most_similar = [
(dictionary.token2id[term], similarity)
for term, similarity in index.most_similar(t1, num_rows)
if term in dictionary.token2id]
for term, similarity in index.most_similar(t1, topn=num_rows)
if term in dictionary.token2id
] if num_rows > 0 else []

if tfidf is None:
rows = sorted(most_similar)
Expand Down

0 comments on commit b588bd7

Please sign in to comment.