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
83f957bc
"git@developer.sourcefind.cn:zhaoyu6/sglang.git" did not exist on "e05555fad85555a8043627a559fe413c85c68509"
Commit
83f957bc
authored
Jun 28, 2023
by
haileyschoelkopf
Browse files
add Grouper
parent
2fef6bc5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
lm_eval/utils.py
lm_eval/utils.py
+58
-0
No files found.
lm_eval/utils.py
View file @
83f957bc
...
...
@@ -230,6 +230,64 @@ class Reorderer:
return
res
class
Grouper
:
"""
takes an array `arr` and function `fn` and returns a dictionary
with keys fn(ob) for each ob in `arr` and with values `self.arr[key]` a list of all
objects in `arr` satisfying `key == fn(ob)`.
"""
def
__init__
(
self
,
arr
,
fn
):
# self.orig_arr = arr
self
.
size
=
len
(
arr
)
arr
=
list
(
enumerate
(
arr
))
def
group_return_dict
(
arr
,
fn
):
res
=
collections
.
defaultdict
(
list
)
for
ob
in
arr
:
res
[
fn
(
ob
)].
append
(
ob
)
return
res
arr
=
group_return_dict
(
arr
,
lambda
x
:
fn
(
x
[
1
]))
# self.arr has format Dict[Tuple[int, <entry from orig. arr>]]
self
.
arr
=
arr
self
.
_grouped
=
None
def
get_grouped
(
self
):
# return the contents but not indices for our grouped dict.
if
self
.
_grouped
:
return
self
.
_grouped
grouped
=
{}
for
key
in
self
.
arr
.
keys
():
# drop the index from each element of self.arr
grouped
[
key
]
=
[
y
[
1
]
for
y
in
self
.
arr
[
key
]]
self
.
_grouped
=
grouped
return
grouped
def
get_original
(
self
,
grouped_dict
):
# take in a grouped dictionary with e.g. results for each key listed
# in the same order as the instances in `self.arr`, and
# return the results in the same (single list) order as `self.orig_arr`.
res
=
[
None
]
*
self
.
size
cov
=
[
False
]
*
self
.
size
# orig = [None] * self.size
assert
grouped_dict
.
keys
()
==
self
.
arr
.
keys
()
for
key
in
grouped_dict
.
keys
():
for
(
ind
,
_
),
v
in
zip
(
self
.
arr
[
key
],
grouped_dict
[
key
]):
res
[
ind
]
=
v
cov
[
ind
]
=
True
# orig[ind] = _
assert
all
(
cov
)
# assert orig == self.orig_arr
return
res
def
make_table
(
result_dict
):
"""Generate table of results."""
from
pytablewriter
import
MarkdownTableWriter
,
LatexTableWriter
...
...
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