mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-26 09:14:32 +03:00
* Add Parser.predict method, and clean up Parser.get_state
This commit is contained in:
parent
04fccfb984
commit
9c090945e0
|
@ -16,3 +16,4 @@ cdef class Parser:
|
||||||
cdef readonly TransitionSystem moves
|
cdef readonly TransitionSystem moves
|
||||||
|
|
||||||
cdef void parse(self, StateClass stcls, ExampleC eg) nogil
|
cdef void parse(self, StateClass stcls, ExampleC eg) nogil
|
||||||
|
cdef void predict(self, StateClass stcls, ExampleC* eg) nogil
|
||||||
|
|
|
@ -97,11 +97,7 @@ cdef class Parser:
|
||||||
self.model.n_feats, self.model.n_feats)
|
self.model.n_feats, self.model.n_feats)
|
||||||
for action_name in initial_actions:
|
for action_name in initial_actions:
|
||||||
if action_name == '_':
|
if action_name == '_':
|
||||||
memset(eg.c.scores, 0, eg.c.nr_class * sizeof(weight_t))
|
self.predict(stcls, &eg.c)
|
||||||
self.moves.set_valid(eg.c.is_valid, stcls)
|
|
||||||
fill_context(eg.c.atoms, stcls)
|
|
||||||
self.model.set_scores(eg.c.scores, eg.c.atoms)
|
|
||||||
eg.c.guess = arg_max_if_true(eg.c.scores, eg.c.is_valid, self.model.n_classes)
|
|
||||||
action = self.moves.c[eg.c.guess]
|
action = self.moves.c[eg.c.guess]
|
||||||
else:
|
else:
|
||||||
action = self.moves.lookup_transition(action_name)
|
action = self.moves.lookup_transition(action_name)
|
||||||
|
@ -111,13 +107,16 @@ cdef class Parser:
|
||||||
tokens.set_parse(stcls._sent)
|
tokens.set_parse(stcls._sent)
|
||||||
return stcls
|
return stcls
|
||||||
|
|
||||||
|
cdef void predict(self, StateClass stcls, ExampleC* eg) nogil:
|
||||||
|
memset(eg.scores, 0, eg.nr_class * sizeof(weight_t))
|
||||||
|
self.moves.set_valid(eg.is_valid, stcls)
|
||||||
|
fill_context(eg.atoms, stcls)
|
||||||
|
self.model.set_scores(eg.scores, eg.atoms)
|
||||||
|
eg.guess = arg_max_if_true(eg.scores, eg.is_valid, self.model.n_classes)
|
||||||
|
|
||||||
cdef void parse(self, StateClass stcls, ExampleC eg) nogil:
|
cdef void parse(self, StateClass stcls, ExampleC eg) nogil:
|
||||||
while not stcls.is_final():
|
while not stcls.is_final():
|
||||||
memset(eg.scores, 0, eg.nr_class * sizeof(weight_t))
|
self.predict(stcls, &eg)
|
||||||
self.moves.set_valid(eg.is_valid, stcls)
|
|
||||||
fill_context(eg.atoms, stcls)
|
|
||||||
self.model.set_scores(eg.scores, eg.atoms)
|
|
||||||
eg.guess = arg_max_if_true(eg.scores, eg.is_valid, self.model.n_classes)
|
|
||||||
self.moves.c[eg.guess].do(stcls, self.moves.c[eg.guess].label)
|
self.moves.c[eg.guess].do(stcls, self.moves.c[eg.guess].label)
|
||||||
self.moves.finalize_state(stcls)
|
self.moves.finalize_state(stcls)
|
||||||
|
|
||||||
|
@ -132,13 +131,9 @@ cdef class Parser:
|
||||||
cdef Transition G
|
cdef Transition G
|
||||||
while not stcls.is_final():
|
while not stcls.is_final():
|
||||||
memset(eg.c.scores, 0, eg.c.nr_class * sizeof(weight_t))
|
memset(eg.c.scores, 0, eg.c.nr_class * sizeof(weight_t))
|
||||||
|
|
||||||
self.moves.set_costs(eg.c.is_valid, eg.c.costs, stcls, gold)
|
self.moves.set_costs(eg.c.is_valid, eg.c.costs, stcls, gold)
|
||||||
|
|
||||||
fill_context(eg.c.atoms, stcls)
|
fill_context(eg.c.atoms, stcls)
|
||||||
|
|
||||||
self.model.train(eg)
|
self.model.train(eg)
|
||||||
|
|
||||||
G = self.moves.c[eg.c.guess]
|
G = self.moves.c[eg.c.guess]
|
||||||
|
|
||||||
self.moves.c[eg.c.guess].do(stcls, self.moves.c[eg.c.guess].label)
|
self.moves.c[eg.c.guess].do(stcls, self.moves.c[eg.c.guess].label)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user