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
d0a301cc
"docs/vscode:/vscode.git/clone" did not exist on "31654ae2d70c590d1d9b532ef05ed9efcecd1587"
Commit
d0a301cc
authored
Feb 14, 2021
by
&
Browse files
fix metric iterable checks
parent
b1619834
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
lm_eval/metrics.py
lm_eval/metrics.py
+9
-4
No files found.
lm_eval/metrics.py
View file @
d0a301cc
import
math
from
collections
import
Iterable
from
pprint
import
pprint
import
numpy
as
np
...
...
@@ -107,6 +108,10 @@ def ter(items):
return
sacrebleu
.
corpus_ter
(
preds
,
refs
).
score
def
is_non_str_iterable
(
obj
):
return
isinstance
(
obj
,
Iterable
)
and
not
isinstance
(
obj
,
str
)
def
_sacreformat
(
refs
,
preds
):
"""Format refs and preds for sacrebleu corpus calculation. It is very particular"""
# Sacrebleu expects (List[str], List[List[str])
...
...
@@ -118,17 +123,17 @@ def _sacreformat(refs, preds):
# We expect refs to be List[str] or List[List[str]], the outer list corresponding to preds
# Must become List[List[str]] with the inner list corresponding to preds
if
not
is
instance
(
refs
,
list
):
if
not
is
_non_str_iterable
(
refs
):
refs
=
list
(
refs
)
if
not
is
instance
(
refs
[
0
],
list
):
if
not
is
_non_str_iterable
(
refs
):
refs
=
[[
ref
]
for
ref
in
refs
]
refs
=
list
(
zip
(
*
refs
))
# Note the number of refs in each ref list much match the number of preds
# We expect preds to be List[str] or List[List[str]]. Must become List[str]
if
not
is
instanc
e
(
preds
,
list
):
if
not
is
_non_str_iterabl
e
(
preds
):
preds
=
list
(
preds
)
if
is
instanc
e
(
preds
[
0
]
,
list
):
if
is
_non_str_iterabl
e
(
preds
[
0
]):
assert
len
(
preds
[
0
])
==
1
,
f
"Pred must be a str, was
{
preds
[
0
]
}
"
preds
=
[
pred
[
0
]
for
pred
in
preds
]
...
...
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