* Add add_label method, to allow users to register new entity types and dependency labels.

This commit is contained in:
Matthew Honnibal 2016-01-19 19:11:02 +01:00
parent 151aa0b0e2
commit 65c5bc4988
1 changed files with 10 additions and 1 deletions

View File

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