mirror of
https://github.com/explosion/spaCy.git
synced 2025-04-29 13:23:40 +03:00
Better approach for handling zero suggestions
This commit is contained in:
parent
a3fad0b983
commit
8c4eee28bc
|
@ -266,9 +266,12 @@ class Exclusive_SpanCategorizer(SpanCategorizer):
|
||||||
) -> SpanGroup:
|
) -> SpanGroup:
|
||||||
scores = self.model.ops.to_numpy(scores)
|
scores = self.model.ops.to_numpy(scores)
|
||||||
indices = self.model.ops.to_numpy(indices)
|
indices = self.model.ops.to_numpy(indices)
|
||||||
if scores.size != 0:
|
|
||||||
predicted = scores.argmax(axis=1)
|
|
||||||
|
|
||||||
|
# Handle cases when there are zero suggestions
|
||||||
|
if scores.size == 0:
|
||||||
|
return SpanGroup(doc, name=self.key)
|
||||||
|
|
||||||
|
predicted = scores.argmax(axis=1)
|
||||||
# Remove samples where the negative label is the argmax
|
# Remove samples where the negative label is the argmax
|
||||||
positive = numpy.where(predicted != self._negative_label)[0]
|
positive = numpy.where(predicted != self._negative_label)[0]
|
||||||
predicted = predicted[positive]
|
predicted = predicted[positive]
|
||||||
|
@ -284,8 +287,6 @@ class Exclusive_SpanCategorizer(SpanCategorizer):
|
||||||
sort_idx = (argmax_probs * -1).argsort()
|
sort_idx = (argmax_probs * -1).argsort()
|
||||||
predicted = predicted[sort_idx]
|
predicted = predicted[sort_idx]
|
||||||
indices = indices[sort_idx]
|
indices = indices[sort_idx]
|
||||||
else:
|
|
||||||
predicted = []
|
|
||||||
|
|
||||||
seen = Ranges()
|
seen = Ranges()
|
||||||
spans = SpanGroup(doc, name=self.key)
|
spans = SpanGroup(doc, name=self.key)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user