Update spacy/pipeline/span_finder.py

Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com>
This commit is contained in:
kadarakos 2023-06-01 17:40:25 +02:00 committed by GitHub
parent 8c7c34d4f4
commit 56de1076a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -272,21 +272,13 @@ class SpanFinder(TrainablePipe):
pred_start_char, pred_end_char = _char_indices(pred_span)
start_match = pred_start_char == ref_start_char
end_match = pred_end_char == ref_end_char
# Tokenizations line up.
if start_match and end_match:
if start_match:
truth[pred_span[0].i, 0] = 1
truth[pred_span[-1].i, 1] = 1
# Start character index lines up, but not the end.
elif start_match and not end_match:
truth[pred_span[0].i, 0] = 1
mask[pred_span[-1].i, 1] = 0
# End character index lines up, but not the start.
elif not start_match and end_match:
truth[pred_span[-1].i, 1] = 1
mask[pred_span[0].i, 0] = 0
# Neither of them match.
else:
mask[pred_span[0].i, 0] = 0
if end_match:
truth[pred_span[-1].i, 1] = 1
else:
mask[pred_span[-1].i, 1] = 0
truths.append(truth)
masks.append(mask)