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
cb485883
Commit
cb485883
authored
Aug 24, 2023
by
lintangsutawika
Browse files
filter takes docs as argument in case filtering requires it
parent
7d16a7cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
lm_eval/api/filter.py
lm_eval/api/filter.py
+4
-4
lm_eval/api/task.py
lm_eval/api/task.py
+13
-4
No files found.
lm_eval/api/filter.py
View file @
cb485883
...
...
@@ -2,7 +2,7 @@ from dataclasses import dataclass
from
typing
import
List
from
lm_eval.api.instance
import
Instance
from
datasets
import
Dataset
class
Filter
:
"""
...
...
@@ -18,7 +18,7 @@ class Filter:
Can define custom behavior here, if an individual instantiation of a Filter class should have state.
"""
def
apply
(
self
,
resps
):
def
apply
(
self
,
resps
,
docs
):
"""
Defines the operation to perform on a list of the `inst.resps` properties of `Instance` objects.
Should return the list of (filtered) response lists *in the same order as they were input*, e.g.
...
...
@@ -40,14 +40,14 @@ class FilterEnsemble:
name
:
str
filters
:
List
[
Filter
]
def
apply
(
self
,
instances
:
List
[
Instance
]):
def
apply
(
self
,
instances
:
List
[
Instance
]
,
docs
:
List
[
Dataset
]
):
resps
=
[
inst
.
resps
for
inst
in
instances
]
# operate just on the model responses
for
f
in
self
.
filters
:
# apply filters in sequence
resps
=
f
.
apply
(
resps
)
resps
=
f
.
apply
(
resps
,
docs
)
# add the end results after filtering to filtered_requests of their respective source instances.
# has key `self.name`: each FilterEnsemble applied in a given run should use a different name.
...
...
lm_eval/api/task.py
View file @
cb485883
...
...
@@ -627,19 +627,19 @@ class ConfigurableTask(Task):
)
if
self
.
has_test_docs
():
docs
=
self
.
test_docs
()
self
.
task_
docs
=
self
.
test_docs
()
elif
self
.
has_validation_docs
():
docs
=
self
.
validation_docs
()
self
.
task_
docs
=
self
.
validation_docs
()
else
:
assert
(
False
),
f
"Task dataset (path=
{
self
.
DATASET_PATH
}
, name=
{
self
.
DATASET_NAME
}
) must have valid or test docs!"
# Test One Doc
self
.
features
=
list
(
docs
.
features
.
keys
())
self
.
features
=
list
(
self
.
task_
docs
.
features
.
keys
())
self
.
multiple_input
=
0
self
.
multiple_target
=
0
test_doc
=
docs
[
0
]
test_doc
=
self
.
task_
docs
[
0
]
test_text
=
self
.
doc_to_text
(
test_doc
)
test_target
=
self
.
doc_to_target
(
test_doc
)
...
...
@@ -743,6 +743,15 @@ class ConfigurableTask(Task):
)
return
super
().
fewshot_docs
()
def
apply_filters
(
self
):
if
hasattr
(
self
,
"_filters"
):
for
f
in
self
.
_filters
:
f
.
apply
(
self
.
_instances
,
self
.
task_docs
)
else
:
eval_logger
.
warning
(
"No filter defined, passing through instances"
)
return
self
.
_instances
def
should_decontaminate
(
self
):
return
self
.
_config
.
should_decontaminate
...
...
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