Skip to content

Commit d0b5ed1

Browse files
authored
Harder check for IndexErrors in QA scripts (#15438)
* Harder check for IndexErrors in QA scripts * Make test stronger
1 parent 8e5d4e4 commit d0b5ed1

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

examples/flax/question-answering/utils_qa.py

+3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def postprocess_qa_predictions(
137137
start_index >= len(offset_mapping)
138138
or end_index >= len(offset_mapping)
139139
or offset_mapping[start_index] is None
140+
or len(offset_mapping[start_index]) < 2
140141
or offset_mapping[end_index] is None
142+
or len(offset_mapping[end_index]) < 2
141143
):
142144
continue
143145
# Don't consider answers with a length that is either < 0 or > max_answer_length.
@@ -147,6 +149,7 @@ def postprocess_qa_predictions(
147149
# provided).
148150
if token_is_max_context is not None and not token_is_max_context.get(str(start_index), False):
149151
continue
152+
150153
prelim_predictions.append(
151154
{
152155
"offsets": (offset_mapping[start_index][0], offset_mapping[end_index][1]),

examples/pytorch/question-answering/utils_qa.py

+3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def postprocess_qa_predictions(
137137
start_index >= len(offset_mapping)
138138
or end_index >= len(offset_mapping)
139139
or offset_mapping[start_index] is None
140+
or len(offset_mapping[start_index]) < 2
140141
or offset_mapping[end_index] is None
142+
or len(offset_mapping[end_index]) < 2
141143
):
142144
continue
143145
# Don't consider answers with a length that is either < 0 or > max_answer_length.
@@ -147,6 +149,7 @@ def postprocess_qa_predictions(
147149
# provided).
148150
if token_is_max_context is not None and not token_is_max_context.get(str(start_index), False):
149151
continue
152+
150153
prelim_predictions.append(
151154
{
152155
"offsets": (offset_mapping[start_index][0], offset_mapping[end_index][1]),

examples/tensorflow/question-answering/utils_qa.py

+3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def postprocess_qa_predictions(
137137
start_index >= len(offset_mapping)
138138
or end_index >= len(offset_mapping)
139139
or offset_mapping[start_index] is None
140+
or len(offset_mapping[start_index]) < 2
140141
or offset_mapping[end_index] is None
142+
or len(offset_mapping[end_index]) < 2
141143
):
142144
continue
143145
# Don't consider answers with a length that is either < 0 or > max_answer_length.
@@ -147,6 +149,7 @@ def postprocess_qa_predictions(
147149
# provided).
148150
if token_is_max_context is not None and not token_is_max_context.get(str(start_index), False):
149151
continue
152+
150153
prelim_predictions.append(
151154
{
152155
"offsets": (offset_mapping[start_index][0], offset_mapping[end_index][1]),

0 commit comments

Comments
 (0)