Fix empty doc in update

This commit is contained in:
Matthew Honnibal 2021-10-31 01:27:36 +02:00
parent 79d5957c47
commit 931b3e112b

View File

@ -237,7 +237,7 @@ class Parser(TrainablePipe):
if n_examples == 0: if n_examples == 0:
return losses return losses
set_dropout_rate(self.model, drop) set_dropout_rate(self.model, drop)
docs = [eg.x for eg in examples] docs = [eg.x for eg in examples if len(eg.x)]
(states, scores), backprop_scores = self.model.begin_update((docs, self.moves)) (states, scores), backprop_scores = self.model.begin_update((docs, self.moves))
if sum(s.shape[0] for s in scores) == 0: if sum(s.shape[0] for s in scores) == 0:
return losses return losses
@ -289,6 +289,8 @@ class Parser(TrainablePipe):
states = moves.init_batch([eg.x for eg in examples]) states = moves.init_batch([eg.x for eg in examples])
cdef int i = 0 cdef int i = 0
for eg, state, history in zip(examples, states, histories): for eg, state, history in zip(examples, states, histories):
if len(history) == 0:
continue
gold = moves.init_gold(state, eg) gold = moves.init_gold(state, eg)
for clas in history: for clas in history:
moves.set_costs(is_valid, &c_costs[i*nO], state.c, gold) moves.set_costs(is_valid, &c_costs[i*nO], state.c, gold)