mirror of https://github.com/explosion/spaCy.git
* Clean up GreedyParser.train function a bit
This commit is contained in:
parent
b3157927e6
commit
6a6085f8b9
|
@ -94,27 +94,24 @@ cdef class GreedyParser:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def train(self, Tokens tokens, GoldParse gold, force_gold=False):
|
def train(self, Tokens tokens, GoldParse gold, force_gold=False):
|
||||||
cdef:
|
|
||||||
int n_feats
|
|
||||||
int cost
|
|
||||||
const Feature* feats
|
|
||||||
const weight_t* scores
|
|
||||||
Transition guess
|
|
||||||
Transition best
|
|
||||||
|
|
||||||
atom_t[CONTEXT_SIZE] context
|
|
||||||
|
|
||||||
self.moves.preprocess_gold(gold)
|
self.moves.preprocess_gold(gold)
|
||||||
cdef Pool mem = Pool()
|
cdef Pool mem = Pool()
|
||||||
cdef State* state = new_state(mem, tokens.data, tokens.length)
|
cdef State* state = new_state(mem, tokens.data, tokens.length)
|
||||||
self.moves.first_state(state)
|
self.moves.first_state(state)
|
||||||
|
|
||||||
|
cdef int cost
|
||||||
|
cdef const Feature* feats
|
||||||
|
cdef const weight_t* scores
|
||||||
|
cdef Transition guess
|
||||||
|
cdef Transition best
|
||||||
|
cdef atom_t[CONTEXT_SIZE] context
|
||||||
|
|
||||||
while not is_final(state):
|
while not is_final(state):
|
||||||
fill_context(context, state)
|
fill_context(context, state)
|
||||||
scores = self.model.score(context)
|
scores = self.model.score(context)
|
||||||
guess = self.moves.best_valid(scores, state)
|
guess = self.moves.best_valid(scores, state)
|
||||||
best = self.moves.best_gold(scores, state, gold)
|
best = self.moves.best_gold(scores, state, gold)
|
||||||
cost = guess.get_cost(&guess, state, gold)
|
cost = guess.get_cost(&guess, state, gold)
|
||||||
assert cost < 9000
|
|
||||||
|
|
||||||
self.model.update(context, guess.clas, best.clas, cost)
|
self.model.update(context, guess.clas, best.clas, cost)
|
||||||
if force_gold:
|
if force_gold:
|
||||||
|
|
Loading…
Reference in New Issue