From 0aa88518786ca95f5750e3a79a87967bd3558a94 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Wed, 14 Oct 2020 15:00:49 +0200 Subject: [PATCH] always return losses --- spacy/pipeline/tagger.pyx | 5 +++-- spacy/pipeline/trainable_pipe.pyx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spacy/pipeline/tagger.pyx b/spacy/pipeline/tagger.pyx index 1b0f79cea..3be93c32c 100644 --- a/spacy/pipeline/tagger.pyx +++ b/spacy/pipeline/tagger.pyx @@ -195,7 +195,7 @@ class Tagger(TrainablePipe): validate_examples(examples, "Tagger.update") if not any(len(eg.predicted) if eg.predicted else 0 for eg in examples): # Handle cases where there are no tokens in any docs. - return + return losses set_dropout_rate(self.model, drop) tag_scores, bp_tag_scores = self.model.begin_update([eg.predicted for eg in examples]) for sc in tag_scores: @@ -233,7 +233,7 @@ class Tagger(TrainablePipe): return if not any(len(doc) for doc in docs): # Handle cases where there are no tokens in any docs. - return + return losses set_dropout_rate(self.model, drop) guesses, backprop = self.model.begin_update(docs) target = self._rehearsal_model(examples) @@ -243,6 +243,7 @@ class Tagger(TrainablePipe): if losses is not None: losses.setdefault(self.name, 0.0) losses[self.name] += (gradient**2).sum() + return losses def get_loss(self, examples, scores): """Find the loss and gradient of loss for the batch of documents and diff --git a/spacy/pipeline/trainable_pipe.pyx b/spacy/pipeline/trainable_pipe.pyx index 07cb01059..6cd73d256 100644 --- a/spacy/pipeline/trainable_pipe.pyx +++ b/spacy/pipeline/trainable_pipe.pyx @@ -116,7 +116,7 @@ cdef class TrainablePipe(Pipe): validate_examples(examples, "TrainablePipe.update") if not any(len(eg.predicted) if eg.predicted else 0 for eg in examples): # Handle cases where there are no tokens in any docs. - return + return losses set_dropout_rate(self.model, drop) scores, bp_scores = self.model.begin_update([eg.predicted for eg in examples]) loss, d_scores = self.get_loss(examples, scores)