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
gaoqiong
lm-evaluation-harness
Commits
5be42b4d
Commit
5be42b4d
authored
Mar 23, 2021
by
Charles Foster
Browse files
SQuAD fixed to use loglikelihood API to calculate the probability of an unanswerable question.
parent
884c29fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
lm_eval/tasks/squad.py
lm_eval/tasks/squad.py
+9
-6
No files found.
lm_eval/tasks/squad.py
View file @
5be42b4d
import
datasets
from
lm_eval.base
import
rf
,
f1_score
,
mean
from
math
import
exp
from
lm_eval.base
import
rf
from
lm_eval.metrics
import
f1_score
,
mean
from
.
common
import
HFTask
class
SQuAD
(
HFTask
):
...
...
@@ -48,7 +50,8 @@ class SQuAD(HFTask):
part of the document for `doc`.
"""
continuation
=
rf
.
greedy_until
(
ctx
,
[
'
\n
'
])
return
continuation
is_unanswerable
=
rf
.
loglikelihood
(
ctx
,
[
' unanswerable'
])
return
continuation
,
is_unanswerable
def
process_results
(
self
,
doc
,
results
):
"""Take a single document and the LM results and evaluates, returning a
...
...
@@ -62,12 +65,12 @@ class SQuAD(HFTask):
"""
squad_metric
=
datasets
.
load_metric
(
"squad_v2"
)
continuation
,
=
results
continuation
,
is_unanswerable
=
results
no_answer_probability
=
0.0
if
continuation
.
startswith
(
' unanswerable'
):
no_answer_probability
=
1.0
logprob_unanswerable
,
is_greedy
=
is_unanswerable
no_answer_probability
=
exp
(
logprob_unanswerable
)
predictions
=
[{
'id'
:
doc
[
'id'
],
'prediction_text'
:
continuation
,
...
...
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