From f3be9d0a9a7a2e29806d1f1a685ec28dc2f50c7b Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Fri, 14 Oct 2016 03:24:13 +0200 Subject: [PATCH] Add tensor field to Lexeme, Token, Doc and Span, so that users have a place to hang neural network outputs --- spacy/lexeme.pxd | 1 + spacy/tokens/doc.pxd | 2 ++ spacy/tokens/span.pxd | 4 ++++ spacy/tokens/token.pxd | 2 ++ 4 files changed, 9 insertions(+) diff --git a/spacy/lexeme.pxd b/spacy/lexeme.pxd index 12d4e3de3..5cf079236 100644 --- a/spacy/lexeme.pxd +++ b/spacy/lexeme.pxd @@ -15,6 +15,7 @@ cdef class Lexeme: cdef LexemeC* c cdef readonly Vocab vocab cdef readonly attr_t orth + cdef public ndarray tensor @staticmethod cdef inline Lexeme from_ptr(LexemeC* lex, Vocab vocab, int vector_length): diff --git a/spacy/tokens/doc.pxd b/spacy/tokens/doc.pxd index fb068fee1..66c2b9970 100644 --- a/spacy/tokens/doc.pxd +++ b/spacy/tokens/doc.pxd @@ -32,6 +32,8 @@ cdef class Doc: cdef public object _vector cdef public object _vector_norm + cdef public np.ndarray tensor + cdef TokenC* c cdef public bint is_tagged diff --git a/spacy/tokens/span.pxd b/spacy/tokens/span.pxd index eeb663f67..2219cc8bb 100644 --- a/spacy/tokens/span.pxd +++ b/spacy/tokens/span.pxd @@ -1,3 +1,5 @@ +cimport numpy as np + from .doc cimport Doc @@ -9,6 +11,8 @@ cdef class Span: cdef readonly int end_char cdef readonly int label + cdef public np.ndarray tensor + cdef public _vector cdef public _vector_norm diff --git a/spacy/tokens/token.pxd b/spacy/tokens/token.pxd index aa2f09394..f57884b9a 100644 --- a/spacy/tokens/token.pxd +++ b/spacy/tokens/token.pxd @@ -1,3 +1,4 @@ +from numpy cimport ndarray from ..vocab cimport Vocab from ..structs cimport TokenC from ..attrs cimport attr_id_t @@ -9,6 +10,7 @@ cdef class Token: cdef TokenC* c cdef readonly int i cdef readonly Doc doc + cdef public ndarray tensor @staticmethod cdef inline Token cinit(Vocab vocab, const TokenC* token, int offset, Doc doc):