From aa08ad8b4448a3cca2ee5ef85b611d32a8b7319d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Novotn=C3=BD?= Date: Sat, 12 Jan 2019 03:11:52 +0100 Subject: [PATCH] Make WordEmbeddingSimilarityIndex.most_similar easier to read --- gensim/models/keyedvectors.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gensim/models/keyedvectors.py b/gensim/models/keyedvectors.py index 92747f8684..1529668423 100644 --- a/gensim/models/keyedvectors.py +++ b/gensim/models/keyedvectors.py @@ -1367,9 +1367,8 @@ def most_similar(self, t1, topn=10): if t1 not in self.keyedvectors.vocab: logger.debug('an out-of-dictionary term "%s"', t1) else: - for _, (t2, similarity) in zip( - range(topn), self.keyedvectors.most_similar( - positive=[t1], topn=topn, **self.kwargs)): + most_similar = self.keyedvectors.most_similar(positive=[t1], topn=topn, **self.kwargs) + for t2, similarity in most_similar: if similarity > self.threshold: yield (t2, similarity**self.exponent)