Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
d0b5ed11
Unverified
Commit
d0b5ed11
authored
Feb 01, 2022
by
Sylvain Gugger
Committed by
GitHub
Feb 01, 2022
Browse files
Harder check for IndexErrors in QA scripts (#15438)
* Harder check for IndexErrors in QA scripts * Make test stronger
parent
8e5d4e49
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
0 deletions
+9
-0
examples/flax/question-answering/utils_qa.py
examples/flax/question-answering/utils_qa.py
+3
-0
examples/pytorch/question-answering/utils_qa.py
examples/pytorch/question-answering/utils_qa.py
+3
-0
examples/tensorflow/question-answering/utils_qa.py
examples/tensorflow/question-answering/utils_qa.py
+3
-0
No files found.
examples/flax/question-answering/utils_qa.py
View file @
d0b5ed11
...
...
@@ -137,7 +137,9 @@ def postprocess_qa_predictions(
start_index
>=
len
(
offset_mapping
)
or
end_index
>=
len
(
offset_mapping
)
or
offset_mapping
[
start_index
]
is
None
or
len
(
offset_mapping
[
start_index
])
<
2
or
offset_mapping
[
end_index
]
is
None
or
len
(
offset_mapping
[
end_index
])
<
2
):
continue
# Don't consider answers with a length that is either < 0 or > max_answer_length.
...
...
@@ -147,6 +149,7 @@ def postprocess_qa_predictions(
# provided).
if
token_is_max_context
is
not
None
and
not
token_is_max_context
.
get
(
str
(
start_index
),
False
):
continue
prelim_predictions
.
append
(
{
"offsets"
:
(
offset_mapping
[
start_index
][
0
],
offset_mapping
[
end_index
][
1
]),
...
...
examples/pytorch/question-answering/utils_qa.py
View file @
d0b5ed11
...
...
@@ -137,7 +137,9 @@ def postprocess_qa_predictions(
start_index
>=
len
(
offset_mapping
)
or
end_index
>=
len
(
offset_mapping
)
or
offset_mapping
[
start_index
]
is
None
or
len
(
offset_mapping
[
start_index
])
<
2
or
offset_mapping
[
end_index
]
is
None
or
len
(
offset_mapping
[
end_index
])
<
2
):
continue
# Don't consider answers with a length that is either < 0 or > max_answer_length.
...
...
@@ -147,6 +149,7 @@ def postprocess_qa_predictions(
# provided).
if
token_is_max_context
is
not
None
and
not
token_is_max_context
.
get
(
str
(
start_index
),
False
):
continue
prelim_predictions
.
append
(
{
"offsets"
:
(
offset_mapping
[
start_index
][
0
],
offset_mapping
[
end_index
][
1
]),
...
...
examples/tensorflow/question-answering/utils_qa.py
View file @
d0b5ed11
...
...
@@ -137,7 +137,9 @@ def postprocess_qa_predictions(
start_index
>=
len
(
offset_mapping
)
or
end_index
>=
len
(
offset_mapping
)
or
offset_mapping
[
start_index
]
is
None
or
len
(
offset_mapping
[
start_index
])
<
2
or
offset_mapping
[
end_index
]
is
None
or
len
(
offset_mapping
[
end_index
])
<
2
):
continue
# Don't consider answers with a length that is either < 0 or > max_answer_length.
...
...
@@ -147,6 +149,7 @@ def postprocess_qa_predictions(
# provided).
if
token_is_max_context
is
not
None
and
not
token_is_max_context
.
get
(
str
(
start_index
),
False
):
continue
prelim_predictions
.
append
(
{
"offsets"
:
(
offset_mapping
[
start_index
][
0
],
offset_mapping
[
end_index
][
1
]),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment