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
db37024b
Commit
db37024b
authored
Aug 16, 2023
by
lintangsutawika
Browse files
fix doc_to_target processing
parent
8eab2a58
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
lm_eval/api/task.py
lm_eval/api/task.py
+11
-4
lm_eval/tasks/realtoxicityprompts/realtoxicityprompts.yaml
lm_eval/tasks/realtoxicityprompts/realtoxicityprompts.yaml
+1
-1
No files found.
lm_eval/api/task.py
View file @
db37024b
...
@@ -465,8 +465,11 @@ class Task(abc.ABC):
...
@@ -465,8 +465,11 @@ class Task(abc.ABC):
elif
type
(
example
)
==
list
:
elif
type
(
example
)
==
list
:
return
[
labeled_examples
+
ex
for
ex
in
example
]
return
[
labeled_examples
+
ex
for
ex
in
example
]
elif
type
(
example
)
==
int
:
elif
type
(
example
)
==
int
:
if
self
.
_config
.
doc_to_choice
is
not
None
:
choices
=
self
.
doc_to_choice
(
doc
)
choices
=
self
.
doc_to_choice
(
doc
)
return
labeled_examples
+
choices
[
example
]
return
labeled_examples
+
choices
[
example
]
else
:
return
labeled_examples
+
str
(
example
)
def
apply_filters
(
self
):
def
apply_filters
(
self
):
...
@@ -790,7 +793,7 @@ class ConfigurableTask(Task):
...
@@ -790,7 +793,7 @@ class ConfigurableTask(Task):
target_string
=
utils
.
apply_template
(
doc_to_target
,
doc
)
target_string
=
utils
.
apply_template
(
doc_to_target
,
doc
)
if
target_string
.
isdigit
():
if
target_string
.
isdigit
():
return
ast
.
literal_eval
(
target_string
)
return
ast
.
literal_eval
(
target_string
)
elif
(
target_string
[
0
]
==
"["
)
and
(
target_string
[
-
1
]
==
"]"
):
elif
len
(
target_string
)
>=
2
and
(
target_string
[
0
]
==
"["
)
and
(
target_string
[
-
1
]
==
"]"
):
return
ast
.
literal_eval
(
target_string
)
return
ast
.
literal_eval
(
target_string
)
else
:
else
:
return
target_string
return
target_string
...
@@ -1002,9 +1005,13 @@ class ConfigurableTask(Task):
...
@@ -1002,9 +1005,13 @@ class ConfigurableTask(Task):
elif
self
.
OUTPUT_TYPE
==
"greedy_until"
:
elif
self
.
OUTPUT_TYPE
==
"greedy_until"
:
gold
=
self
.
doc_to_target
(
doc
)
gold
=
self
.
doc_to_target
(
doc
)
if
type
(
gold
)
==
int
:
if
self
.
_config
.
doc_to_choice
is
not
None
:
# If you set doc_to_choice,
# it assumes that doc_to_target returns a number.
choices
=
self
.
doc_to_choice
(
doc
)
choices
=
self
.
doc_to_choice
(
doc
)
gold
=
choices
[
gold
]
gold
=
choices
[
gold
]
else
:
gold
=
str
(
gold
)
for
key
,
result
in
zip
(
self
.
_metric_fn_list
.
keys
(),
results
):
for
key
,
result
in
zip
(
self
.
_metric_fn_list
.
keys
(),
results
):
if
self
.
multiple_target
:
if
self
.
multiple_target
:
...
...
lm_eval/tasks/realtoxicityprompts/realtoxicityprompts.yaml
View file @
db37024b
...
@@ -2,7 +2,7 @@ task: realtoxicityprompts
...
@@ -2,7 +2,7 @@ task: realtoxicityprompts
dataset_path
:
"
allenai/real-toxicity-prompts"
dataset_path
:
"
allenai/real-toxicity-prompts"
training_split
:
'
train'
training_split
:
'
train'
test_split
:
'
train'
test_split
:
'
train'
doc_to_text
:
"
{{
'
'+
prompt.text}}"
doc_to_text
:
"
{{prompt.text}}"
doc_to_target
:
"
"
doc_to_target
:
"
"
metric_list
:
metric_list
:
-
metric
:
!function
metric.toxicity_perspective_api
-
metric
:
!function
metric.toxicity_perspective_api
...
...
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