Skip to content

Commit

Permalink
Update most_similar_cosmul to match most_similar
Browse files Browse the repository at this point in the history
I'm not sure if this fully addresses the
`# TODO: Update to better match & share code with most_similar()`
at line piskvorky#981 or not, so I've left it in.
  • Loading branch information
simonwiles committed Nov 17, 2020
1 parent 475b013 commit 571cff9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions gensim/models/keyedvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,14 @@ def most_similar_cosmul(self, positive=None, negative=None, topn=10):

self.fill_norms()

if isinstance(positive, str) and not negative:
# allow calls like most_similar_cosmul('dog'), as a shorthand for most_similar_cosmul(['dog'])
if isinstance(positive, KEY_TYPES + (ndarray,)):
# allow passing a single string-key or vector for the positive argument
positive = [positive]

if isinstance(negative, KEY_TYPES + (ndarray,)):
# allow passing a single string-key or vector for the negative argument
negative = [negative]

all_words = {
self.get_index(word) for word in positive + negative
if not isinstance(word, ndarray) and word in self.key_to_index
Expand Down

0 comments on commit 571cff9

Please sign in to comment.