From 781e95cf536cd5720d07ec80b2cb89eaa4b41290 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Tue, 11 Feb 2020 02:31:49 +0100 Subject: [PATCH] Ensure doc.similarity returns a float (on develop) (#4969) --- spacy/tokens/doc.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index 15f77d621..aec06d620 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -391,7 +391,9 @@ cdef class Doc: return 0.0 vector = self.vector xp = get_array_module(vector) - return xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm) + result = xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm) + # ensure we get a scalar back (numpy does this automatically but cupy doesn't) + return result.item() @property def has_vector(self):