From 931b3e112bcdae2523b9188e63c568ffc5375c90 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 31 Oct 2021 01:27:36 +0200 Subject: [PATCH] Fix empty doc in update --- spacy/pipeline/transition_parser.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spacy/pipeline/transition_parser.pyx b/spacy/pipeline/transition_parser.pyx index 047805239..597fe3c8d 100644 --- a/spacy/pipeline/transition_parser.pyx +++ b/spacy/pipeline/transition_parser.pyx @@ -237,7 +237,7 @@ class Parser(TrainablePipe): if n_examples == 0: return losses 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)) if sum(s.shape[0] for s in scores) == 0: return losses @@ -289,6 +289,8 @@ class Parser(TrainablePipe): states = moves.init_batch([eg.x for eg in examples]) cdef int i = 0 for eg, state, history in zip(examples, states, histories): + if len(history) == 0: + continue gold = moves.init_gold(state, eg) for clas in history: moves.set_costs(is_valid, &c_costs[i*nO], state.c, gold)