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
6399ef9e
Commit
6399ef9e
authored
May 19, 2023
by
lintangsutawika
Browse files
handles prompt from promptsource
parent
c41bb266
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
13 deletions
+38
-13
lm_eval/api/task.py
lm_eval/api/task.py
+22
-4
lm_eval/prompts/__init__.py
lm_eval/prompts/__init__.py
+16
-9
No files found.
lm_eval/api/task.py
View file @
6399ef9e
...
@@ -584,23 +584,41 @@ class ConfigurableTask(Task):
...
@@ -584,23 +584,41 @@ class ConfigurableTask(Task):
def
doc_to_text
(
self
,
doc
):
def
doc_to_text
(
self
,
doc
):
if
self
.
_config
.
use_prompt
is
not
None
:
if
self
.
_config
.
use_prompt
is
not
None
:
doc_to_text
=
get_prompt
(
self
.
_config
.
use_prompt
)
doc_to_text
=
get_prompt
(
self
.
_config
.
use_prompt
,
self
.
DATASET_NAME
,
self
.
DATASET_PATH
)
else
:
else
:
doc_to_text
=
self
.
_config
.
doc_to_text
doc_to_text
=
self
.
_config
.
doc_to_text
if
type
(
doc_to_text
)
==
str
:
if
type
(
doc_to_text
)
==
str
:
return
utils
.
apply_template
(
doc_to_text
,
doc
)
return
utils
.
apply_template
(
doc_to_text
,
doc
)
elif
callable
(
doc_to_text
):
elif
callable
(
doc_to_text
):
return
doc_to_text
(
doc
)
if
hasattr
(
doc_to_text
,
"apply"
):
return
doc_to_text
.
apply
(
doc
)[
0
]
else
:
return
doc_to_text
(
doc
)
else
:
else
:
raise
TypeError
raise
TypeError
def
doc_to_target
(
self
,
doc
):
def
doc_to_target
(
self
,
doc
):
doc_to_target
=
self
.
_config
.
doc_to_target
if
self
.
_config
.
use_prompt
is
not
None
:
doc_to_target
=
get_prompt
(
self
.
_config
.
use_prompt
,
self
.
DATASET_NAME
,
self
.
DATASET_PATH
)
else
:
doc_to_target
=
self
.
_config
.
doc_to_target
if
type
(
doc_to_target
)
==
str
:
if
type
(
doc_to_target
)
==
str
:
return
utils
.
apply_template
(
doc_to_target
,
doc
)
return
utils
.
apply_template
(
doc_to_target
,
doc
)
elif
callable
(
doc_to_target
):
elif
callable
(
doc_to_target
):
return
doc_to_target
(
doc
)
if
hasattr
(
doc_to_target
,
"apply"
):
return
doc_to_target
.
apply
(
doc
)[
1
]
else
:
return
doc_to_target
(
doc
)
else
:
else
:
raise
TypeError
raise
TypeError
...
...
lm_eval/prompts/__init__.py
View file @
6399ef9e
...
@@ -6,17 +6,24 @@
...
@@ -6,17 +6,24 @@
PROMPT_REGISTRY
=
{
PROMPT_REGISTRY
=
{
"qa-basic"
:
{
"qa-basic"
:
{
"question-newline-answer"
:
"Question: {{question}}
\n
Answer:"
,
"question-newline-answer"
:
"Question: {{question}}
\n
Answer:"
,
"q-newline-a"
:
"Q: {question}
\n
A:"
"q-newline-a"
:
"Q:
{
{question}
}
\n
A:"
},
},
}
}
def
get_prompt
(
prompt_id
:
str
):
def
get_prompt
(
prompt_id
:
str
,
dataset_name
=
None
,
dataset_path
=
None
):
# unpack prompt name
# unpack prompt name
try
:
category_name
,
prompt_name
=
prompt_id
.
split
(
":"
)
category_name
,
prompt_name
=
prompt_id
.
split
(
":"
)
except
:
if
category_name
==
"promptsource"
:
raise
ValueError
(
from
promptsource.templates
import
DatasetTemplates
f
"expected only a single `:` as separator between
\
if
prompt_name
in
prompts
.
all_template_names
:
prompt category and name, but got `
{
prompt_id
}
` instead"
prompts
=
DatasetTemplates
(
dataset_name
,
dataset_path
)
)
return
prompts
[
prompt_name
]
return
PROMPT_REGISTRY
[
category_name
][
prompt_name
]
else
:
\ No newline at end of file
try
:
return
PROMPT_REGISTRY
[
category_name
][
prompt_name
]
except
:
raise
ValueError
(
f
"expected only a single `:` as separator between
\
prompt category and name, but got `
{
prompt_id
}
` instead"
)
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