From a323ef90df7c5a72e9deb9272fdb39a40fa8a9b5 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Sun, 7 Feb 2021 00:51:56 +0100 Subject: [PATCH] ensure the loss value is cast as float (#6928) --- spacy/pipeline/entity_linker.py | 2 +- spacy/pipeline/multitask.pyx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spacy/pipeline/entity_linker.py b/spacy/pipeline/entity_linker.py index 6ea735dde..262bcf677 100644 --- a/spacy/pipeline/entity_linker.py +++ b/spacy/pipeline/entity_linker.py @@ -273,7 +273,7 @@ class EntityLinker(TrainablePipe): gradients = self.distance.get_grad(sentence_encodings, entity_encodings) loss = self.distance.get_loss(sentence_encodings, entity_encodings) loss = loss / len(entity_encodings) - return loss, gradients + return float(loss), gradients def predict(self, docs: Iterable[Doc]) -> List[str]: """Apply the pipeline's model to a batch of docs, without modifying them. diff --git a/spacy/pipeline/multitask.pyx b/spacy/pipeline/multitask.pyx index cfb492612..990b6a1de 100644 --- a/spacy/pipeline/multitask.pyx +++ b/spacy/pipeline/multitask.pyx @@ -197,7 +197,7 @@ class ClozeMultitask(TrainablePipe): target = vectors[ids] gradient = self.distance.get_grad(prediction, target) loss = self.distance.get_loss(prediction, target) - return loss, gradient + return float(loss), gradient def update(self, examples, *, drop=0., sgd=None, losses=None): pass