From 65c5bc49884354114ecfaf2003e3d83df2824072 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 19 Jan 2016 19:11:02 +0100 Subject: [PATCH] * Add add_label method, to allow users to register new entity types and dependency labels. --- spacy/syntax/parser.pyx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spacy/syntax/parser.pyx b/spacy/syntax/parser.pyx index bcc0d7737..b5642a0a3 100644 --- a/spacy/syntax/parser.pyx +++ b/spacy/syntax/parser.pyx @@ -105,6 +105,7 @@ cdef class Parser: cdef Pool mem = Pool() cdef ExampleC eg = self.model.allocate(mem) + words = [t.text for t in tokens] while not stcls.is_final(): self.model.set_features(&eg, stcls) self.moves.set_valid(eg.is_valid, stcls) @@ -129,7 +130,6 @@ cdef class Parser: cdef Pool mem = Pool() cdef ExampleC eg = self.model.allocate(mem) cdef weight_t loss = 0 - words = [w.orth_ for w in tokens] cdef Transition action while not stcls.is_final(): self.model.set_features(&eg, stcls) @@ -145,6 +145,15 @@ cdef class Parser: def step_through(self, Doc doc): return StepwiseState(self, doc) + def add_label(self, label): + for action in self.moves.action_types: + self.moves.add_action(action, label) + # This seems pretty dangerous. However, thinc uses sparse vectors for + # classes, so it doesn't need to have the classes pre-specified. Things + # get dicey if people have an Exampe class around, which is being reused. + self.model.nr_class = self.moves.n_moves + + cdef class StepwiseState: cdef readonly StateClass stcls