From 0551b7b03a2d725ea56aac589dcf8308e9c6903e Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 22 Aug 2017 19:46:52 +0200 Subject: [PATCH] Fix doc.vector --- 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 dd52c4cbf..b9941b50b 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -304,7 +304,10 @@ cdef class Doc: if self._vector is not None: return self._vector elif self.has_vector and len(self): - self._vector = sum(t.vector for t in self) / len(self) + vector = numpy.zeros((self.vocab.vectors_length,), dtype='f') + for token in self.c[:self.length]: + vector += self.vocab.get_vector(token.lex.orth) + self._vector = vector / len(self) return self._vector elif self.tensor is not None: self._vector = self.tensor.mean(axis=0)