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
ModelZoo
ResNet50_tensorflow
Commits
25160730
Commit
25160730
authored
May 18, 2020
by
Saurabh Saxena
Committed by
A. Unique TensorFlower
May 18, 2020
Browse files
Handle corner case in squad_lib when best_non_null_entry is None.
PiperOrigin-RevId: 312193729
parent
3ef7bbcf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
official/nlp/data/squad_lib.py
official/nlp/data/squad_lib.py
+23
-7
No files found.
official/nlp/data/squad_lib.py
View file @
25160730
...
@@ -35,7 +35,18 @@ from official.nlp.bert import tokenization
...
@@ -35,7 +35,18 @@ from official.nlp.bert import tokenization
class
SquadExample
(
object
):
class
SquadExample
(
object
):
"""A single training/test example for simple sequence classification.
"""A single training/test example for simple sequence classification.
For examples without an answer, the start and end position are -1.
For examples without an answer, the start and end position are -1.
Attributes:
qas_id: ID of the question-answer pair.
question_text: Original text for the question.
doc_tokens: The list of tokens in the context obtained by splitting
on whitespace only.
orig_answer_text: Original text for the answer.
start_position: Starting index of the answer in `doc_tokens`.
end_position: Ending index of the answer in `doc_tokens`.
is_impossible: Whether the question is impossible to answer given the
context. Only used in SQuAD 2.0.
"""
"""
def
__init__
(
self
,
def
__init__
(
self
,
...
@@ -695,13 +706,18 @@ def postprocess_output(all_examples,
...
@@ -695,13 +706,18 @@ def postprocess_output(all_examples,
else
:
else
:
# pytype: disable=attribute-error
# pytype: disable=attribute-error
# predict "" iff the null score - the score of best non-null > threshold
# predict "" iff the null score - the score of best non-null > threshold
score_diff
=
score_null
-
best_non_null_entry
.
start_logit
-
(
if
best_non_null_entry
is
not
None
:
best_non_null_entry
.
end_logit
)
score_diff
=
score_null
-
best_non_null_entry
.
start_logit
-
(
scores_diff_json
[
example
.
qas_id
]
=
score_diff
best_non_null_entry
.
end_logit
)
if
score_diff
>
null_score_diff_threshold
:
scores_diff_json
[
example
.
qas_id
]
=
score_diff
all_predictions
[
example
.
qas_id
]
=
""
if
score_diff
>
null_score_diff_threshold
:
all_predictions
[
example
.
qas_id
]
=
""
else
:
all_predictions
[
example
.
qas_id
]
=
best_non_null_entry
.
text
else
:
else
:
all_predictions
[
example
.
qas_id
]
=
best_non_null_entry
.
text
logging
.
warning
(
"best_non_null_entry is None"
)
scores_diff_json
[
example
.
qas_id
]
=
score_null
all_predictions
[
example
.
qas_id
]
=
""
# pytype: enable=attribute-error
# pytype: enable=attribute-error
all_nbest_json
[
example
.
qas_id
]
=
nbest_json
all_nbest_json
[
example
.
qas_id
]
=
nbest_json
...
...
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