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
96157fc7
Commit
96157fc7
authored
Feb 08, 2021
by
Leo Gao
Browse files
Fix
parent
c3f724cf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
13 deletions
+14
-13
lm_eval/tasks/glue.py
lm_eval/tasks/glue.py
+11
-11
lm_eval/tasks/superglue.py
lm_eval/tasks/superglue.py
+2
-1
lm_eval/utils.py
lm_eval/utils.py
+1
-1
No files found.
lm_eval/tasks/glue.py
View file @
96157fc7
...
...
@@ -68,19 +68,19 @@ class SST(HFTask):
return
True
def
fewshot_description
(
self
):
return
"Indicate if each sentence is
P
ositive or
N
egative."
return
"Indicate if
the sentiment of
each sentence is
p
ositive or
n
egative."
def
doc_to_text
(
self
,
doc
):
return
"{}
\n
Question: Is this sentence
P
ositive or
N
egative?
\n
Answer:"
.
format
(
return
"{}
\n
Question: Is this sentence
p
ositive or
n
egative?
\n
Answer:"
.
format
(
general_detokenize
(
doc
[
"sentence"
]),
)
def
doc_to_target
(
self
,
doc
):
return
" {}"
.
format
({
1
:
"
P
ositive"
,
0
:
"
N
egative"
}[
doc
[
"label"
]])
return
" {}"
.
format
({
1
:
"
p
ositive"
,
0
:
"
n
egative"
}[
doc
[
"label"
]])
def
construct_requests
(
self
,
doc
,
ctx
):
ll_positive
,
_
=
rf
.
loglikelihood
(
ctx
,
"
P
ositive"
)
ll_negative
,
_
=
rf
.
loglikelihood
(
ctx
,
"
N
egative"
)
ll_positive
,
_
=
rf
.
loglikelihood
(
ctx
,
"
p
ositive"
)
ll_negative
,
_
=
rf
.
loglikelihood
(
ctx
,
"
n
egative"
)
return
ll_positive
,
ll_negative
def
process_results
(
self
,
doc
,
results
):
...
...
@@ -129,7 +129,7 @@ class MNLI(HFTask):
def
doc_to_text
(
self
,
doc
):
return
"{}
\n
Question: {} True, False or Neither?
\n
Answer:"
.
format
(
doc
[
"premise"
],
doc
[
"hypothesis"
]
+
(
''
if
doc
[
"hypothesis"
].
endswith
(
'.'
)
else
'.'
),
doc
[
"hypothesis"
]
.
strip
()
+
(
''
if
doc
[
"hypothesis"
].
strip
().
endswith
(
'.'
)
else
'.'
),
)
def
doc_to_target
(
self
,
doc
):
...
...
@@ -195,11 +195,11 @@ class QNLI(HFTask):
def
doc_to_target
(
self
,
doc
):
# True = entailment
# False = not entailment
return
" {}"
.
format
({
0
:
"
Y
es"
,
1
:
"
N
o"
}[
doc
[
"label"
]])
return
" {}"
.
format
({
0
:
"
y
es"
,
1
:
"
n
o"
}[
doc
[
"label"
]])
def
construct_requests
(
self
,
doc
,
ctx
):
ll_yes
,
_
=
rf
.
loglikelihood
(
ctx
,
"
Y
es"
)
ll_no
,
_
=
rf
.
loglikelihood
(
ctx
,
"
N
o"
)
ll_yes
,
_
=
rf
.
loglikelihood
(
ctx
,
"
y
es"
)
ll_no
,
_
=
rf
.
loglikelihood
(
ctx
,
"
n
o"
)
return
ll_yes
,
ll_no
def
process_results
(
self
,
doc
,
results
):
...
...
@@ -347,8 +347,8 @@ class MRPC(HFTask):
return
" {}"
.
format
(
yesno
(
doc
[
"label"
]))
def
construct_requests
(
self
,
doc
,
ctx
):
ll_yes
,
_
=
rf
.
loglikelihood
(
ctx
,
"
Y
es"
)
ll_no
,
_
=
rf
.
loglikelihood
(
ctx
,
"
N
o"
)
ll_yes
,
_
=
rf
.
loglikelihood
(
ctx
,
"
y
es"
)
ll_no
,
_
=
rf
.
loglikelihood
(
ctx
,
"
n
o"
)
return
ll_yes
,
ll_no
def
process_results
(
self
,
doc
,
results
):
...
...
lm_eval/tasks/superglue.py
View file @
96157fc7
...
...
@@ -8,6 +8,7 @@ from . common import HFTask, yesno
from
lm_eval.base
import
rf
,
mean
,
acc_all
,
metric_max_over_ground_truths
import
sklearn
import
transformers.data.metrics.squad_metrics
as
squad_metrics
from
..utils
import
general_detokenize
class
BoolQ
(
HFTask
):
...
...
@@ -221,7 +222,7 @@ class MultiRC(HFTask):
@
staticmethod
def
format_answer
(
answer
,
label
):
label_str
=
"
Y
es"
if
label
else
"
N
o"
label_str
=
"
y
es"
if
label
else
"
n
o"
return
f
"
{
label_str
}
,
{
answer
}
"
def
construct_requests
(
self
,
doc
,
ctx
):
...
...
lm_eval/utils.py
View file @
96157fc7
...
...
@@ -48,5 +48,5 @@ def general_detokenize(string):
string
=
string
.
replace
(
"( "
,
"("
)
string
=
string
.
replace
(
"
\"
"
,
"
\"
"
)
string
=
string
.
replace
(
"
\"
"
,
"
\"
"
)
string
=
re
.
sub
(
r
" (['.,])"
,
r
"\1"
)
string
=
re
.
sub
(
r
" (['.,])"
,
r
"\1"
,
string
)
return
string
\ No newline at end of file
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