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
c827e4ce
Commit
c827e4ce
authored
Jul 13, 2023
by
lintangsutawika
Browse files
reformat
parent
d1bb50e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
11 deletions
+16
-11
lm_eval/evaluator.py
lm_eval/evaluator.py
+4
-1
lm_eval/tasks/pubmedqa/preprocess_pubmedqa.py
lm_eval/tasks/pubmedqa/preprocess_pubmedqa.py
+4
-6
lm_eval/tasks/race/preprocess_race.py
lm_eval/tasks/race/preprocess_race.py
+8
-4
No files found.
lm_eval/evaluator.py
View file @
c827e4ce
...
@@ -200,7 +200,10 @@ def evaluate(
...
@@ -200,7 +200,10 @@ def evaluate(
# aggregate Instances by LM method requested to get output.
# aggregate Instances by LM method requested to get output.
reqtype
=
(
reqtype
=
(
"loglikelihood"
"loglikelihood"
if
(
task
.
OUTPUT_TYPE
==
"multiple_choice"
or
task
.
OUTPUT_TYPE
==
"winograd_schema"
)
if
(
task
.
OUTPUT_TYPE
==
"multiple_choice"
or
task
.
OUTPUT_TYPE
==
"winograd_schema"
)
else
task
.
OUTPUT_TYPE
else
task
.
OUTPUT_TYPE
)
# TODO: this is hacky, fix in task.py
)
# TODO: this is hacky, fix in task.py
requests
[
reqtype
].
extend
(
task
.
instances
)
requests
[
reqtype
].
extend
(
task
.
instances
)
...
...
lm_eval/tasks/pubmedqa/preprocess_pubmedqa.py
View file @
c827e4ce
...
@@ -4,13 +4,11 @@ def doc_to_text(doc):
...
@@ -4,13 +4,11 @@ def doc_to_text(doc):
ctxs
,
doc
[
"question"
],
doc
[
"final_decision"
]
ctxs
,
doc
[
"question"
],
doc
[
"final_decision"
]
)
)
def
doc_to_target
(
doc
):
def
doc_to_target
(
doc
):
return
" {}"
.
format
(
doc
[
"final_decision"
])
return
" {}"
.
format
(
doc
[
"final_decision"
])
def
gold_alias
(
doc
):
def
gold_alias
(
doc
):
dict_to_label
=
{
dict_to_label
=
{
"yes"
:
0
,
"no"
:
1
,
"maybe"
:
2
}
'yes'
:
0
,
return
dict_to_label
[
doc
[
"final_decision"
]]
'no'
:
1
,
'maybe'
:
2
}
return
dict_to_label
[
doc
[
"final_decision"
]]
\ No newline at end of file
lm_eval/tasks/race/preprocess_race.py
View file @
c827e4ce
import
ast
import
ast
def
process_ast
(
string
):
def
process_ast
(
string
):
return
ast
.
literal_eval
(
string
)
return
ast
.
literal_eval
(
string
)
def
last_problem
(
doc
):
def
last_problem
(
doc
):
return
process_ast
(
doc
[
"problems"
])[
-
1
]
return
process_ast
(
doc
[
"problems"
])[
-
1
]
def
get_answer_option
(
problem
):
def
get_answer_option
(
problem
):
letter_to_num
=
{
"A"
:
0
,
"B"
:
1
,
"C"
:
2
,
"D"
:
3
}
letter_to_num
=
{
"A"
:
0
,
"B"
:
1
,
"C"
:
2
,
"D"
:
3
}
answer
=
letter_to_num
[
problem
[
"answer"
]]
answer
=
letter_to_num
[
problem
[
"answer"
]]
return
problem
[
"options"
][
answer
]
return
problem
[
"options"
][
answer
]
def
create_choices
(
doc
):
def
create_choices
(
doc
):
problem
=
last_problem
(
doc
)
problem
=
last_problem
(
doc
)
choices
=
[
problem
[
"options"
][
i
]
for
i
in
range
(
4
)]
choices
=
[
problem
[
"options"
][
i
]
for
i
in
range
(
4
)]
return
choices
return
choices
def
doc_to_text
(
doc
):
def
doc_to_text
(
doc
):
text
=
"Article: "
+
doc
[
"article"
]
+
"
\n\n
"
text
=
"Article: "
+
doc
[
"article"
]
+
"
\n\n
"
for
problem
in
process_ast
(
doc
[
"problems"
])[:
-
1
]:
for
problem
in
process_ast
(
doc
[
"problems"
])[:
-
1
]:
if
problem
[
"question"
][
-
6
:]
==
" _ ."
:
if
problem
[
"question"
][
-
6
:]
==
" _ ."
:
text
+=
(
text
+=
problem
[
"question"
][
-
5
:]
+
get_answer_option
(
problem
)
+
"
\n
"
problem
[
"question"
][
-
5
:]
+
get_answer_option
(
problem
)
+
"
\n
"
)
else
:
else
:
question
=
"Question: "
+
problem
[
"question"
]
+
"
\n
"
question
=
"Question: "
+
problem
[
"question"
]
+
"
\n
"
answer
=
"Answer: "
+
get_answer_option
(
problem
)
+
"
\n
"
answer
=
"Answer: "
+
get_answer_option
(
problem
)
+
"
\n
"
...
@@ -30,6 +33,7 @@ def doc_to_text(doc):
...
@@ -30,6 +33,7 @@ def doc_to_text(doc):
text
+=
last_problem
(
doc
)[
"question"
]
text
+=
last_problem
(
doc
)[
"question"
]
return
text
return
text
def
doc_to_target
(
doc
):
def
doc_to_target
(
doc
):
letter_to_num
=
{
"A"
:
0
,
"B"
:
1
,
"C"
:
2
,
"D"
:
3
}
letter_to_num
=
{
"A"
:
0
,
"B"
:
1
,
"C"
:
2
,
"D"
:
3
}
answer
=
letter_to_num
[
last_problem
(
doc
)[
"answer"
]]
answer
=
letter_to_num
[
last_problem
(
doc
)[
"answer"
]]
...
...
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