Skip to content

Commit

Permalink
Updated n_similarity method
Browse files Browse the repository at this point in the history
Fixes Issue piskvorky#743, n_similarity method now raises ZeroDivisionError if atleast one empty list is passed to it.
  • Loading branch information
pranay360 authored Sep 25, 2016
1 parent 6238481 commit 809f2ba
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,15 @@ def n_similarity(self, ws1, ws2):
True
"""
v1 = [self[word] for word in ws1]
v2 = [self[word] for word in ws2]
return dot(matutils.unitvec(array(v1).mean(axis=0)), matutils.unitvec(array(v2).mean(axis=0)))
if len(ws1) > 0 and len(ws2) > 0:
v1 = [self[word] for word in ws1]
v2 = [self[word] for word in ws2]
return dot(matutils.unitvec(array(v1).mean(axis=0)),
matutils.unitvec(array(v2).mean(axis=0)))
else:
raise ZeroDivisionError('Atleast one of the passed list is empty.')
return


def init_sims(self, replace=False):
"""
Expand Down

0 comments on commit 809f2ba

Please sign in to comment.