Skip to content
Snippets Groups Projects
Commit 03728b20 authored by Max Kimmich's avatar Max Kimmich
Browse files

Improve prompt extraction

parent 36eef613
No related branches found
No related tags found
No related merge requests found
......@@ -250,14 +250,18 @@ class DifferentialEvolution(EvolutionAlgorithm):
),
)
matches = re.findall(
# TODO make sure that regex matches also if </prompt> is missing
r"<prompt>(.*?)</prompt>",
# regex that matches any characters between last pair of <prompt></prompt>, also if </prompt> is missing
r"<prompt>(?!.*<prompt>)(?:(.*)</prompt>|(.*))",
evolved_prompt,
flags=(re.IGNORECASE | re.DOTALL),
)
if matches:
# we expect that the last match is where we find the prompt, other matches are part of the instruction (which the model repeats)
evolved_prompt = matches[-1]
if matches and any(matches[0]):
# there is always only a single match, and one group should be non-empty
if matches[0][0]:
evolved_prompt = matches[0][0]
else:
assert matches[0][1]
evolved_prompt = matches[0][1]
else:
# TODO what to do in this case? Discard generated prompt directly?
pass
......
......@@ -102,7 +102,7 @@ def get_de_prompt_template(use_demonstration_example: bool, task: None | Task =
if use_demonstration_example:
assert (
task is not None
), "Task cannot be done if demonstation data should be used."
), "Task cannot be None if demonstation data should be used."
if isinstance(task, (TextClassification, Summarization)):
return DE_PROMPT_WITH_DEMONSTRATION_SIM
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment