From b65b0c07bf95ccf28f5c108219b22b07e8fad15a Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Mon, 19 Jan 2015 19:59:55 +1100 Subject: [PATCH] * Messily hook up vector in tokens --- spacy/tokens.pxd | 4 +++- spacy/tokens.pyx | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spacy/tokens.pxd b/spacy/tokens.pxd index 1dba9234d..ae35d6fa6 100644 --- a/spacy/tokens.pxd +++ b/spacy/tokens.pxd @@ -1,6 +1,6 @@ from libc.stdint cimport uint32_t -from cython.view cimport array as cvarray +from numpy cimport ndarray from cymem.cymem cimport Pool from thinc.typedefs cimport atom_t @@ -62,3 +62,5 @@ cdef class Token: cdef readonly univ_tag_t pos cdef readonly attr_t tag cdef readonly attr_t dep + + cdef readonly ndarray vec diff --git a/spacy/tokens.pyx b/spacy/tokens.pyx index 18866d386..28f6751ce 100644 --- a/spacy/tokens.pyx +++ b/spacy/tokens.pyx @@ -10,6 +10,9 @@ from .typedefs cimport LEMMA from .typedefs cimport ID, SIC, NORM1, NORM2, SHAPE, PREFIX, SUFFIX, LENGTH, CLUSTER from .typedefs cimport POS, LEMMA +cimport numpy +import numpy + cimport cython @@ -201,6 +204,10 @@ cdef class Token: self.tag = t.tag self.dep = t.dep + self.vec = numpy.ndarray(shape=(300,), dtype=numpy.float32) + for i in range(300): + self.vec[i] = t.lex.vec[i] + def __unicode__(self): cdef const TokenC* t = &self._seq.data[self.i] cdef int end_idx = t.idx + t.lex.length