From 97fd9741c60bb1f49de54d096045d972413e3d36 Mon Sep 17 00:00:00 2001 From: kadarakos Date: Fri, 3 Mar 2023 15:41:41 +0000 Subject: [PATCH] don't keep recomputing self._label_map for each span --- spacy/pipeline/spancat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spacy/pipeline/spancat.py b/spacy/pipeline/spancat.py index a1e9a8931..d6e887218 100644 --- a/spacy/pipeline/spancat.py +++ b/spacy/pipeline/spancat.py @@ -567,6 +567,7 @@ class SpanCategorizer(TrainablePipe): if self.add_negative_label: negative_spans = numpy.ones((scores.shape[0])) offset = 0 + label_map = self._label_map for i, eg in enumerate(examples): # Map (start, end) offset of spans to the row in the d_scores array, # so that we can adjust the gradient for predictions that were @@ -581,7 +582,7 @@ class SpanCategorizer(TrainablePipe): key = (gold_span.start, gold_span.end) if key in spans_index: row = spans_index[key] - k = self._label_map[gold_span.label_] + k = label_map[gold_span.label_] target[row, k] = 1.0 if self.add_negative_label: # delete negative label target.