Skip to content

Commit

Permalink
Fix for Github issue #979 : (#986)
Browse files Browse the repository at this point in the history
Issue: WMD Earth mover Distance for sentences that contain a single word return inf
Fix: Return float 0.0 when the dictionary size is 1 (both sentences are composed with the same token)
  • Loading branch information
rbahumi authored and tmylk committed Oct 31, 2016
1 parent f9a0eab commit 4ee0078
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,10 @@ def wmdistance(self, document1, document2):
dictionary = Dictionary(documents=[document1, document2])
vocab_len = len(dictionary)

if vocab_len == 1:
# Both documents are composed by a single unique token
return 0.0

# Sets for faster look-up.
docset1 = set(document1)
docset2 = set(document2)
Expand Down

0 comments on commit 4ee0078

Please sign in to comment.