From 03b5b9727a5733869a7e604ab9fbb3b3b400f35b Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 22 Aug 2017 19:52:19 +0200 Subject: [PATCH] Fix Doc.vector for empty doc objects --- spacy/tokens/doc.pyx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index b9941b50b..3b1f38b68 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -303,7 +303,10 @@ cdef class Doc: return self.user_hooks['vector'](self) if self._vector is not None: return self._vector - elif self.has_vector and len(self): + elif not len(self): + self._vector = numpy.zeros((self.vocab.vectors_length,), dtype='f') + return self._vector + elif self.has_vector: vector = numpy.zeros((self.vocab.vectors_length,), dtype='f') for token in self.c[:self.length]: vector += self.vocab.get_vector(token.lex.orth)