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
4462e415
Unverified
Commit
4462e415
authored
Apr 10, 2021
by
Leo Gao
Committed by
GitHub
Apr 10, 2021
Browse files
Make piqa inherit MultipleChoiceTask
parent
2522c27f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
26 deletions
+23
-26
lm_eval/tasks/piqa.py
lm_eval/tasks/piqa.py
+23
-26
No files found.
lm_eval/tasks/piqa.py
View file @
4462e415
import
numpy
as
np
import
numpy
as
np
from
lm_eval.base
import
rf
from
lm_eval.base
import
rf
from
..metrics
import
mean
from
..metrics
import
mean
from
.
common
import
HFTask
from
.
common
import
MultipleChoiceTask
,
HFTask
class
PiQA
(
HFTask
):
class
PiQA
(
HFTask
,
MultipleChoiceTask
):
DATASET_PATH
=
"piqa"
DATASET_PATH
=
"piqa"
DATASET_NAME
=
None
DATASET_NAME
=
None
...
@@ -21,32 +21,29 @@ class PiQA(HFTask):
...
@@ -21,32 +21,29 @@ class PiQA(HFTask):
# TODO: figure out fewshot description
# TODO: figure out fewshot description
return
""
return
""
def
doc_to_text
(
self
,
doc
):
def
_convert_standard
(
self
,
doc
):
return
"Question: "
+
doc
[
"goal"
]
+
"
\n
Answer:"
out_doc
=
{
"goal"
:
doc
[
"goal"
],
"choices"
:
[
doc
[
"sol1"
],
doc
[
"sol2"
]],
"gold"
:
doc
[
"label"
],
}
return
out_doc
def
doc_to_target
(
self
,
doc
):
def
_load_docs
(
self
,
doc
s
):
solutions
=
[
doc
[
"sol1"
],
doc
[
"sol2"
]]
for
record
in
docs
:
return
" "
+
solutions
[
doc
[
"label"
]]
yield
self
.
_convert_standard
(
record
)
def
construct_requests
(
self
,
doc
,
ctx
):
def
training_docs
(
self
):
ll_1
,
_
=
rf
.
loglikelihood
(
ctx
,
" "
+
doc
[
'sol1'
])
docs
=
super
().
training_docs
()
ll_2
,
_
=
rf
.
loglikelihood
(
ctx
,
" "
+
doc
[
'sol2'
])
return
self
.
_load_docs
(
docs
)
return
ll_1
,
ll_2
def
process_results
(
self
,
doc
,
results
):
def
validation_docs
(
self
):
completion_len
=
np
.
array
([
float
(
len
(
doc
[
"sol1"
])),
float
(
len
(
doc
[
"sol2"
]))])
docs
=
super
().
validation_docs
()
return
self
.
_load_docs
(
docs
)
return
{
def
test_docs
(
self
):
'acc'
:
np
.
argmax
(
results
)
==
doc
[
"label"
],
docs
=
super
().
test_docs
()
'acc_norm'
:
np
.
argmax
(
results
/
completion_len
)
==
doc
[
"label"
]
return
self
.
_load_docs
(
docs
)
}
def
aggregation
(
self
):
def
doc_to_text
(
self
,
doc
):
return
{
return
"Question: "
+
doc
[
"goal"
]
+
"
\n
Answer:"
'acc'
:
mean
}
def
higher_is_better
(
self
):
return
{
'acc'
:
True
}
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