From 449b889454a17947aa9d93e4c2538aedaef37c4f Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 10 Dec 2018 16:19:18 +0100 Subject: [PATCH] Fix KeyError in Vectors.most_similar. Fixes #2648 --- spacy/vectors.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spacy/vectors.pyx b/spacy/vectors.pyx index f7950676b..9a1ad0e25 100644 --- a/spacy/vectors.pyx +++ b/spacy/vectors.pyx @@ -295,7 +295,8 @@ cdef class Vectors: xp = get_array_module(self.data) row2key = {row: key for key, row in self.key2row.items()} - keys = xp.asarray([row2key[row] for row in best_rows], dtype='uint64') + keys = xp.asarray( + [row2key[row] for row in best_rows if row in row2key], dtype='uint64') return (keys, best_rows, scores) def from_glove(self, path):