Skip to content

Commit c5bb3c2

Browse files
committed
Fix a rare crash when the model outputs our of bounds spans
1 parent 42abc74 commit c5bb3c2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tibert/bertcoref.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,14 @@ def from_wpieced_to_tokenized(
210210
for mention in chain:
211211

212212
new_start_idx = wp_to_token[mention.start_idx]
213-
new_end_idx = wp_to_token[mention.end_idx - 1] + 1
213+
new_end_idx = wp_to_token[mention.end_idx - 1]
214+
# NOTE: this happens in case the model has predicted
215+
# an erroneous mention such as '[CLS]' or '[SEP]'. In
216+
# that case, we simply ignore the mention.
217+
if new_start_idx is None or new_end_idx is None:
218+
continue
219+
new_end_idx += 1
220+
214221
new_mention = Mention(
215222
tokens[new_start_idx:new_end_idx],
216223
new_start_idx,

0 commit comments

Comments
 (0)