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
ebcb28f2
Commit
ebcb28f2
authored
Jun 16, 2021
by
Jonathan Tow
Browse files
Add detokenizer
parent
d235355a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
lm_eval/tasks/mutual.py
lm_eval/tasks/mutual.py
+19
-3
No files found.
lm_eval/tasks/mutual.py
View file @
ebcb28f2
...
...
@@ -72,17 +72,33 @@ class MuTualBase(Task):
return
""
def
doc_to_text
(
self
,
doc
):
return
doc
[
"article"
]
return
self
.
detokenize
(
doc
[
"article"
]
)
def
doc_to_target
(
self
,
doc
):
return
" "
+
doc
[
"options"
][
self
.
CHOICES
.
index
(
doc
[
"answers"
])]
return
" "
+
self
.
detokenize
(
doc
[
"options"
][
self
.
CHOICES
.
index
(
doc
[
"answers"
])]
)
def
construct_requests
(
self
,
doc
,
ctx
):
lls
=
[]
for
option
in
doc
[
"options"
]:
lls
.
append
(
rf
.
loglikelihood
(
ctx
,
f
"
{
option
}
"
))
lls
.
append
(
rf
.
loglikelihood
(
ctx
,
f
"
{
self
.
detokenize
(
option
)
}
"
))
return
lls
def
detokenize
(
self
,
text
):
text
=
text
.
replace
(
" '"
,
"'"
)
text
=
text
.
replace
(
"
\n
"
,
"
\n
"
)
text
=
text
.
replace
(
"
\n
"
,
"
\n
"
)
text
=
text
.
replace
(
" n't"
,
"n't"
)
text
=
text
.
replace
(
"`` "
,
'"'
)
text
=
text
.
replace
(
"''"
,
'"'
)
# punctuation
text
=
text
.
replace
(
" :"
,
":"
)
text
=
text
.
replace
(
" ;"
,
";"
)
text
=
text
.
replace
(
" !"
,
"!"
)
text
=
text
.
replace
(
" ?"
,
"?"
)
text
=
text
.
replace
(
" ,"
,
","
)
text
=
text
.
replace
(
" ."
,
"."
)
return
text
def
process_results
(
self
,
doc
,
results
):
gold
=
self
.
CHOICES
.
index
(
doc
[
"answers"
])
r4_1
=
np
.
argmax
(
results
)
==
gold
# r4_1 = accuracy
...
...
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