Fix Doc.vector for empty doc objects

This commit is contained in:
Matthew Honnibal 2017-08-22 19:52:19 +02:00
parent 0551b7b03a
commit 03b5b9727a
1 changed files with 4 additions and 1 deletions

View File

@ -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)