Refix StepwiseState

This commit is contained in:
Matthew Honnibal 2017-04-15 16:00:28 +02:00
parent ed27ca7e21
commit 4884b2c113

View File

@ -366,11 +366,11 @@ cdef class Parser:
def add_label(self, label): def add_label(self, label):
# Doesn't set label into serializer -- subclasses override it to do that. # Doesn't set label into serializer -- subclasses override it to do that.
for action in self.moves.action_types: for action in self.moves.action_types:
self.moves.add_action(action, label) added = self.moves.add_action(action, label)
if 'actions' in self.cfg: if added:
# Important that the labels be stored as a list! We need the # Important that the labels be stored as a list! We need the
# order, or the model goes out of synch # order, or the model goes out of synch
self.cfg['actions'].setdefault(str(action), []).append(label) self.cfg.setdefault('extra_labels', []).append(label)
cdef class StepwiseState: cdef class StepwiseState:
@ -385,11 +385,11 @@ cdef class StepwiseState:
self.doc = doc self.doc = doc
if gold is not None: if gold is not None:
self.gold = gold self.gold = gold
self.parser.moves.preprocess_gold(self.gold)
else: else:
self.gold = GoldParse(doc) self.gold = GoldParse(doc)
self.stcls = StateClass.init(doc.c, doc.length) self.stcls = StateClass.init(doc.c, doc.length)
self.parser.moves.initialize_state(self.stcls.c) self.parser.moves.initialize_state(self.stcls.c)
self.parser.moves.preprocess_gold(gold)
self.eg = Example( self.eg = Example(
nr_class=self.parser.moves.n_moves, nr_class=self.parser.moves.n_moves,
nr_atom=CONTEXT_SIZE, nr_atom=CONTEXT_SIZE,