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
b2b5a122
Commit
b2b5a122
authored
Jan 30, 2021
by
Leo Gao
Browse files
Handle aliases correctly in TriviaQA
parent
0601d0bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
+19
-5
lm_eval/tasks/triviaqa.py
lm_eval/tasks/triviaqa.py
+19
-5
No files found.
lm_eval/tasks/triviaqa.py
View file @
b2b5a122
...
@@ -40,16 +40,30 @@ class TriviaQA(Dataset):
...
@@ -40,16 +40,30 @@ class TriviaQA(Dataset):
return
''
.
join
([
'Q:'
,
doc
[
'Question'
],
'
\n\n
'
,
'A:'
])
return
''
.
join
([
'Q:'
,
doc
[
'Question'
],
'
\n\n
'
,
'A:'
])
def
doc_to_target
(
self
,
doc
):
def
doc_to_target
(
self
,
doc
):
return
doc
[
'Answer'
][
'Aliases'
][
0
]
return
" "
+
doc
[
'Answer'
][
'Value'
]
def
_remove_prefixes
(
self
,
aliases
):
# Optimization: Remove any alias that has a strict prefix elsewhere in the list
# we can do this because if the prefix is acceptable by isgreedy, we can stop looking
aliases
.
sort
()
ret
=
[
aliases
[
0
]]
for
alias
in
aliases
[
1
:]:
if
not
alias
.
startswith
(
ret
[
-
1
]):
ret
.
append
(
alias
)
return
ret
def
construct_requests
(
self
,
doc
,
ctx
):
def
construct_requests
(
self
,
doc
,
ctx
):
ll
,
is_prediction
=
rf
.
loglikelihood
(
ctx
,
doc
[
'Answer'
][
'Value'
])
ret
=
[]
return
is_prediction
for
alias
in
self
.
_remove_prefixes
(
doc
[
'Answer'
][
'Aliases'
]):
_
,
is_prediction
=
rf
.
loglikelihood
(
ctx
,
" "
+
alias
)
ret
.
append
(
is_prediction
)
return
ret
def
process_results
(
self
,
doc
,
results
):
def
process_results
(
self
,
doc
,
results
):
is_prediction
=
results
return
{
return
{
"acc"
:
float
(
is_prediction
[
1
]
)
"acc"
:
float
(
any
(
results
)
)
}
}
def
aggregation
(
self
):
def
aggregation
(
self
):
...
...
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