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
e4bdffd0
Commit
e4bdffd0
authored
Sep 15, 2023
by
haileyschoelkopf
Browse files
add first_n sampler
parent
cc547c7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
3 deletions
+30
-3
lm_eval/api/samplers.py
lm_eval/api/samplers.py
+30
-3
No files found.
lm_eval/api/samplers.py
View file @
e4bdffd0
class
Sampler
:
class
Context
Sampler
:
def
__init__
(
self
,
docs
,
task
,
fewshot_indices
=
None
,
rnd
=
None
)
->
None
:
self
.
rnd
=
rnd
assert
self
.
rnd
,
"must pass rnd to FewShotSampler!"
...
...
@@ -71,7 +71,19 @@ class Sampler:
return
self
.
rnd
.
sample
(
self
.
docs
,
n
)
class
BalancedSampler
(
Sampler
):
class
FirstNSampler
(
ContextSampler
):
def
sample
(
self
,
n
)
->
None
:
"""
Draw the first `n` samples in order from the specified split.
Used for tasks with "canonical" ordered fewshot examples, such as MMLU and CMMLU.
"""
assert
n
<=
len
(
self
.
docs
),
f
"Error: number of fewshot samples requested exceeds the
{
len
(
self
.
docs
)
}
that are available."
return
self
.
docs
[:
n
]
class
BalancedSampler
(
ContextSampler
):
def
sample
(
self
,
n
)
->
None
:
"""
TODO: this should return approximately class-balanced samples from our fewshot examples.
...
...
@@ -81,12 +93,27 @@ class BalancedSampler(Sampler):
pass
class
ManualSampler
(
Sampler
):
class
ManualSampler
(
Context
Sampler
):
def
sample
(
self
,
n
)
->
None
:
""" """
pass
SAMPLER_REGISTRY
=
{
"default"
:
ContextSampler
,
"first_n"
:
FirstNSampler
,
}
def
get_sampler
(
name
):
try
:
return
SAMPLER_REGISTRY
[
name
]
except
KeyError
:
raise
ValueError
(
f
"Attempted to use contextsampler '
{
name
}
', but no sampling strategy for this name found! Supported model names:
{
', '
.
join
(
SAMPLER_REGISTRY
.
keys
())
}
"
)
# TODO: how should we do design here? might be better to have a single sampler and pass more kwargs at init.
# Depends what's easier for new user to add own functionality on top of
...
...
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