From 95c5bfcc781ff4651a7399cadf7a304af7bf0cae Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Mon, 3 Oct 2022 17:05:55 +0200 Subject: [PATCH 1/2] avoid multiplication with 1.0 Co-authored-by: kadarakos --- spacy/pipeline/spancat_exclusive.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spacy/pipeline/spancat_exclusive.py b/spacy/pipeline/spancat_exclusive.py index d170c65fa..0d783413b 100644 --- a/spacy/pipeline/spancat_exclusive.py +++ b/spacy/pipeline/spancat_exclusive.py @@ -370,7 +370,8 @@ class SpanCategorizerExclusive(TrainablePipe): target[negative_samples, self._negative_label] = 1.0 # type: ignore d_scores = scores - target neg_weight = cast(float, self.cfg["negative_weight"]) - d_scores[negative_samples] *= neg_weight + if neg_weight != 1.0: + d_scores[negative_samples] *= neg_weight loss = float((d_scores**2).sum()) return loss, d_scores From 1b1afd22512b27d516f6b6649994622161260690 Mon Sep 17 00:00:00 2001 From: Lj Miranda <12949683+ljvmiranda921@users.noreply.github.com> Date: Wed, 26 Oct 2022 11:07:57 +0800 Subject: [PATCH 2/2] Update spacy/pipeline/spancat_exclusive.py Co-authored-by: Sofie Van Landeghem --- spacy/pipeline/spancat_exclusive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacy/pipeline/spancat_exclusive.py b/spacy/pipeline/spancat_exclusive.py index 0d783413b..2f4112ac8 100644 --- a/spacy/pipeline/spancat_exclusive.py +++ b/spacy/pipeline/spancat_exclusive.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, cast +from typing import Callable, Dict, Iterable, List, Optional, Tuple, cast import numpy from thinc.api import Config, Model, Ops, Optimizer