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
91a37c90
Unverified
Commit
91a37c90
authored
Sep 18, 2023
by
Lintang Sutawika
Committed by
GitHub
Sep 18, 2023
Browse files
Merge pull request #840 from EleutherAI/qasper
parents
33d52483
11be7c93
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
4 deletions
+77
-4
lm_eval/tasks/qasper/utils.py
lm_eval/tasks/qasper/utils.py
+72
-0
lm_eval/utils.py
lm_eval/utils.py
+5
-4
No files found.
lm_eval/tasks/qasper/utils.py
0 → 100644
View file @
91a37c90
from
datasets
import
Dataset
from
functools
import
partial
def
process_docs
(
dataset
,
set_answer_type
=
"bool"
):
FEATURES
=
[
"title"
,
"abstract"
,
"question"
,
"answer"
,
"answer_type"
]
def
_categorise_answer
(
answer_blob
):
if
answer_blob
[
"unanswerable"
]:
answer
=
"unanswerable"
answer_type
=
"unanswerable"
return
answer
,
answer_type
elif
answer_blob
[
"yes_no"
]:
answer
=
"yes"
answer_type
=
"bool"
return
answer
,
answer_type
elif
answer_blob
[
"free_form_answer"
]:
answer
=
answer_blob
[
"free_form_answer"
]
answer_type
=
"free form answer"
return
answer
,
answer_type
elif
answer_blob
[
"extractive_spans"
]:
answer
=
answer_blob
[
"extractive_spans"
]
answer_type
=
"extractive_spans"
return
answer
,
answer_type
elif
answer_blob
[
"yes_no"
]
is
False
:
answer
=
"no"
answer_type
=
"bool"
return
answer
,
answer_type
def
_flatten
(
doc
):
"""Given a `doc`, flatten it out so that each JSON blob
contains exactly one question and one answer. Logic taken from
the reference implementation available at
https://github.com/allenai/qasper-led-baseline/blob/main/scripts/evaluator.py
"""
obs_list
=
{
"title"
:
[],
"abstract"
:
[],
"question"
:
[],
"answer"
:
[],
"answer_type"
:
[],
}
title
=
doc
.
pop
(
"title"
)
abstract
=
doc
.
pop
(
"abstract"
)
for
question
,
answer_list
in
zip
(
doc
[
"qas"
][
"question"
],
doc
[
"qas"
][
"answers"
]):
for
answer_blob
in
answer_list
[
"answer"
]:
answer
,
answer_type
=
_categorise_answer
(
answer_blob
)
if
answer_type
==
set_answer_type
:
obs_list
[
"title"
].
append
(
title
)
obs_list
[
"abstract"
].
append
(
abstract
)
obs_list
[
"question"
].
append
(
question
)
obs_list
[
"answer_type"
].
append
(
answer_type
)
if
type
(
answer
)
==
list
:
answer
=
", "
.
join
(
answer
)
obs_list
[
"answer"
].
append
(
answer
)
return
obs_list
dataset
=
dataset
.
map
(
_flatten
,
remove_columns
=
[
key
for
key
in
dataset
.
features
.
keys
()
if
key
not
in
FEATURES
],
)
new_dataset
=
{}
for
key
in
dataset
.
features
.
keys
():
new_dataset
[
key
]
=
[
x
for
row
in
dataset
[
key
]
for
x
in
row
]
return
Dataset
.
from_dict
(
new_dataset
)
process_docs_bool
=
partial
(
process_docs
,
set_answer_type
=
"bool"
)
process_docs_freeform
=
partial
(
process_docs
,
set_answer_type
=
"free form answer"
)
lm_eval/utils.py
View file @
91a37c90
...
...
@@ -394,8 +394,10 @@ def import_function(loader, node):
function_name
=
loader
.
construct_scalar
(
node
)
yaml_path
=
os
.
path
.
dirname
(
loader
.
name
)
module_name
,
function_name
=
function_name
.
split
(
"."
)
module_path
=
os
.
path
.
join
(
yaml_path
,
"{}.py"
.
format
(
module_name
))
*
module_name
,
function_name
=
function_name
.
split
(
"."
)
if
type
(
module_name
)
==
list
:
module_name
=
"."
.
join
(
module_name
)
module_path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
yaml_path
,
"{}.py"
.
format
(
module_name
)))
spec
=
importlib
.
util
.
spec_from_file_location
(
module_name
,
module_path
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
...
...
@@ -429,8 +431,7 @@ def load_yaml_config(yaml_path):
# If not found, assume the included yaml
# is in the same dir as the original yaml
if
not
os
.
path
.
isfile
(
path
):
path
=
os
.
path
.
join
(
yaml_dir
,
path
)
path
=
os
.
path
.
normpath
(
os
.
path
.
join
(
yaml_dir
,
path
))
try
:
included_yaml_config
=
load_yaml_config
(
path
)
final_yaml_config
.
update
(
included_yaml_config
)
...
...
Prev
1
2
Next
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