Skip to content

Commit

Permalink
Fix default format (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavkatz committed May 20, 2024
1 parent 4c376c3 commit f7c5122
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions prepare/formats/empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
model_input_format="{system_prompt}\\N{instruction}\\N{demos}{source}\\N{target_prefix}",
)

default_format = SystemFormat()
assert (
format.demo_format == default_format.demo_format
), f"{format.demo_format} != {default_format.demo_format}"
assert (
format.model_input_format == default_format.model_input_format
), f"{format.model_input_format} != {default_format.model_input_format}"

add_to_catalog(format, "formats.empty", overwrite=True)
2 changes: 1 addition & 1 deletion prepare/templates/classification/multi_class/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

add_to_catalog(
InputOutputTemplate(
input_format="{text_a_type}: {text_a}, {text_b_type}: {text_b}",
input_format="{text_a_type}: {text_a}\n{text_b_type}: {text_b}",
output_format="{label}",
target_prefix="The {type_of_relation} class is ",
instruction="Given a {text_a_type} and {text_b_type} classify the {type_of_relation} of the {text_b_type} to one of {classes}.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "input_output_template",
"input_format": "{text_a_type}: {text_a}, {text_b_type}: {text_b}",
"input_format": "{text_a_type}: {text_a}\n{text_b_type}: {text_b}",
"output_format": "{label}",
"target_prefix": "The {type_of_relation} class is ",
"instruction": "Given a {text_a_type} and {text_b_type} classify the {type_of_relation} of the {text_b_type} to one of {classes}.",
Expand Down
4 changes: 2 additions & 2 deletions src/unitxt/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class SystemFormat(Format):
"""

demos_field: str = "demos"
demo_format: str = "{source}\n{target_prefix}{target}\n\n" # example: "User: {source}\nAgent: {target}\n\n"
demo_format: str = "{source}\\N{target_prefix}{target}\n\n" # example: "User: {source}\nAgent: {target}\n\n"
model_input_format: str = (
"{system_prompt}{instruction}{demos}{source}\n{target_prefix}"
"{system_prompt}\\N{instruction}\\N{demos}{source}\\N{target_prefix}"
)
format_args: Dict[str, str] = OptionalField(default_factory=dict)

Expand Down
4 changes: 2 additions & 2 deletions tests/library/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_produce_with_recipe(self):

target = {
"metrics": ["metrics.f1_micro", "metrics.accuracy", "metrics.f1_macro"],
"source": "Given a premise and hypothesis classify the entailment of the hypothesis to one of entailment, not entailment.premise: Steve follows Fred's example in everything. He influences him hugely., hypothesis: Steve influences him hugely.\nThe entailment class is entailment\n\npremise: The police arrested all of the gang members. They were trying to stop the drug trade in the neighborhood., hypothesis: The police were trying to stop the drug trade in the neighborhood.\nThe entailment class is not entailment\n\npremise: It works perfectly, hypothesis: It works!\nThe entailment class is ",
"source": "Given a premise and hypothesis classify the entailment of the hypothesis to one of entailment, not entailment.\npremise: Steve follows Fred's example in everything. He influences him hugely.\nhypothesis: Steve influences him hugely.\nThe entailment class is entailment\n\npremise: The police arrested all of the gang members. They were trying to stop the drug trade in the neighborhood.\nhypothesis: The police were trying to stop the drug trade in the neighborhood.\nThe entailment class is not entailment\n\npremise: It works perfectly\nhypothesis: It works!\nThe entailment class is ",
"target": "?",
"references": ["?"],
"task_data": '{"text_a": "It works perfectly", '
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_produce_with_recipe_with_list_of_instances(self):

target = {
"metrics": ["metrics.f1_micro", "metrics.accuracy", "metrics.f1_macro"],
"source": "Given a premise and hypothesis classify the entailment of the hypothesis to one of entailment, not entailment.premise: Steve follows Fred's example in everything. He influences him hugely., hypothesis: Steve influences him hugely.\nThe entailment class is entailment\n\npremise: The police arrested all of the gang members. They were trying to stop the drug trade in the neighborhood., hypothesis: The police were trying to stop the drug trade in the neighborhood.\nThe entailment class is not entailment\n\npremise: It works perfectly, hypothesis: It works!\nThe entailment class is ",
"source": "Given a premise and hypothesis classify the entailment of the hypothesis to one of entailment, not entailment.\npremise: Steve follows Fred's example in everything. He influences him hugely.\nhypothesis: Steve influences him hugely.\nThe entailment class is entailment\n\npremise: The police arrested all of the gang members. They were trying to stop the drug trade in the neighborhood.\nhypothesis: The police were trying to stop the drug trade in the neighborhood.\nThe entailment class is not entailment\n\npremise: It works perfectly\nhypothesis: It works!\nThe entailment class is ",
"target": "?",
"references": ["?"],
"task_data": '{"text_a": "It works perfectly", '
Expand Down

0 comments on commit f7c5122

Please sign in to comment.