From dea229c634ea029a1582725ba57c66b93e62af44 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 19 Aug 2017 16:24:28 +0200 Subject: [PATCH] Fix Span.to_array method --- spacy/tokens/span.pyx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index 9625b5547..7e29cccf4 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -151,10 +151,11 @@ cdef class Span: # Make an array from the attributes --- otherwise our inner loop is Python # dict iteration. cdef np.ndarray[attr_t, ndim=1] attr_ids = numpy.asarray(py_attr_ids, dtype=numpy.uint64) - output = numpy.ndarray(shape=(self.length, len(attr_ids)), dtype=numpy.uint64) + cdef int length = self.end - self.start + output = numpy.ndarray(shape=(length, len(attr_ids)), dtype=numpy.uint64) for i in range(self.start, self.end): for j, feature in enumerate(attr_ids): - output[i, j] = get_token_attr(&self.doc.c[i], feature) + output[i-self.start, j] = get_token_attr(&self.doc.c[i], feature) return output cpdef int _recalculate_indices(self) except -1: