From 9b640fe855c104bf35d7bcee6d17978e18274cee Mon Sep 17 00:00:00 2001 From: Kazuki Matsumaru Date: Tue, 27 Feb 2024 10:31:10 +0900 Subject: [PATCH] Separate template --- prepare/cards/ffqa_filtered.py | 15 +-------------- prepare/templates/qa/with_context.py | 16 ++++++++++++++++ src/unitxt/catalog/cards/ffqa_filtered/16k.json | 11 +---------- src/unitxt/catalog/cards/ffqa_filtered/2k.json | 11 +---------- src/unitxt/catalog/cards/ffqa_filtered/4k.json | 11 +---------- src/unitxt/catalog/cards/ffqa_filtered/8k.json | 11 +---------- .../catalog/templates/qa/with_context/all.json | 3 ++- .../catalog/templates/qa/with_context/ffqa.json | 5 +++++ 8 files changed, 28 insertions(+), 55 deletions(-) create mode 100644 src/unitxt/catalog/templates/qa/with_context/ffqa.json diff --git a/prepare/cards/ffqa_filtered.py b/prepare/cards/ffqa_filtered.py index b010cc3a53..c41c3bfab7 100644 --- a/prepare/cards/ffqa_filtered.py +++ b/prepare/cards/ffqa_filtered.py @@ -1,9 +1,7 @@ from src.unitxt.blocks import ( - InputOutputTemplate, LoadHF, SplitRandomMix, TaskCard, - TemplatesList, ) from src.unitxt.catalog import add_to_catalog from src.unitxt.operators import ( @@ -115,18 +113,7 @@ def add_card(split: str): ), ], task="tasks.qa.with_context.extractive", - templates=TemplatesList( - [ - InputOutputTemplate( - input_format="""\ -Answer the question based on the information provided in the document given below. The answer should be a single word or a number or a short phrase of few words -Document: {context} -Question: {question} -Answer: """, - output_format="{answers}", - ), - ] - ), + templates="templates.qa.with_context.all", ) test_card(card) diff --git a/prepare/templates/qa/with_context.py b/prepare/templates/qa/with_context.py index 9db8159ea2..1b18f00ad5 100644 --- a/prepare/templates/qa/with_context.py +++ b/prepare/templates/qa/with_context.py @@ -37,6 +37,21 @@ overwrite=True, ) +# Template from https://huggingface.co/datasets/abacusai/WikiQA-Free_Form_QA +add_to_catalog( + MultiReferenceTemplate( + input_format="""\ +Answer the question based on the information provided in the document given below. The answer should be a single word or a number or a short phrase of few words +Document: {context} +Question: {question} +Answer: """, + references_field="answers", + ), + "templates.qa.with_context.ffqa", + overwrite=True, +) + + add_to_catalog( TemplatesList( [ @@ -44,6 +59,7 @@ "templates.qa.with_context.simple2", "templates.qa.with_context.with_type", "templates.qa.with_context.question_first", + "templates.qa.with_context.ffqa", ] ), "templates.qa.with_context.all", diff --git a/src/unitxt/catalog/cards/ffqa_filtered/16k.json b/src/unitxt/catalog/cards/ffqa_filtered/16k.json index 7e10ba90a7..0c42dadce4 100644 --- a/src/unitxt/catalog/cards/ffqa_filtered/16k.json +++ b/src/unitxt/catalog/cards/ffqa_filtered/16k.json @@ -60,14 +60,5 @@ } ], "task": "tasks.qa.with_context.extractive", - "templates": { - "type": "templates_list", - "items": [ - { - "type": "input_output_template", - "input_format": "Answer the question based on the information provided in the document given below. The answer should be a single word or a number or a short phrase of few words\nDocument: {context}\nQuestion: {question}\nAnswer: ", - "output_format": "{answers}" - } - ] - } + "templates": "templates.qa.with_context.all" } diff --git a/src/unitxt/catalog/cards/ffqa_filtered/2k.json b/src/unitxt/catalog/cards/ffqa_filtered/2k.json index b5eabb23ab..b926393a40 100644 --- a/src/unitxt/catalog/cards/ffqa_filtered/2k.json +++ b/src/unitxt/catalog/cards/ffqa_filtered/2k.json @@ -60,14 +60,5 @@ } ], "task": "tasks.qa.with_context.extractive", - "templates": { - "type": "templates_list", - "items": [ - { - "type": "input_output_template", - "input_format": "Answer the question based on the information provided in the document given below. The answer should be a single word or a number or a short phrase of few words\nDocument: {context}\nQuestion: {question}\nAnswer: ", - "output_format": "{answers}" - } - ] - } + "templates": "templates.qa.with_context.all" } diff --git a/src/unitxt/catalog/cards/ffqa_filtered/4k.json b/src/unitxt/catalog/cards/ffqa_filtered/4k.json index 37e2434633..29b3bd400c 100644 --- a/src/unitxt/catalog/cards/ffqa_filtered/4k.json +++ b/src/unitxt/catalog/cards/ffqa_filtered/4k.json @@ -60,14 +60,5 @@ } ], "task": "tasks.qa.with_context.extractive", - "templates": { - "type": "templates_list", - "items": [ - { - "type": "input_output_template", - "input_format": "Answer the question based on the information provided in the document given below. The answer should be a single word or a number or a short phrase of few words\nDocument: {context}\nQuestion: {question}\nAnswer: ", - "output_format": "{answers}" - } - ] - } + "templates": "templates.qa.with_context.all" } diff --git a/src/unitxt/catalog/cards/ffqa_filtered/8k.json b/src/unitxt/catalog/cards/ffqa_filtered/8k.json index de5cdbac3c..18f01de958 100644 --- a/src/unitxt/catalog/cards/ffqa_filtered/8k.json +++ b/src/unitxt/catalog/cards/ffqa_filtered/8k.json @@ -60,14 +60,5 @@ } ], "task": "tasks.qa.with_context.extractive", - "templates": { - "type": "templates_list", - "items": [ - { - "type": "input_output_template", - "input_format": "Answer the question based on the information provided in the document given below. The answer should be a single word or a number or a short phrase of few words\nDocument: {context}\nQuestion: {question}\nAnswer: ", - "output_format": "{answers}" - } - ] - } + "templates": "templates.qa.with_context.all" } diff --git a/src/unitxt/catalog/templates/qa/with_context/all.json b/src/unitxt/catalog/templates/qa/with_context/all.json index 56b713023b..5d6f83d799 100644 --- a/src/unitxt/catalog/templates/qa/with_context/all.json +++ b/src/unitxt/catalog/templates/qa/with_context/all.json @@ -4,6 +4,7 @@ "templates.qa.with_context.simple", "templates.qa.with_context.simple2", "templates.qa.with_context.with_type", - "templates.qa.with_context.question_first" + "templates.qa.with_context.question_first", + "templates.qa.with_context.ffqa" ] } diff --git a/src/unitxt/catalog/templates/qa/with_context/ffqa.json b/src/unitxt/catalog/templates/qa/with_context/ffqa.json new file mode 100644 index 0000000000..80b6181990 --- /dev/null +++ b/src/unitxt/catalog/templates/qa/with_context/ffqa.json @@ -0,0 +1,5 @@ +{ + "type": "multi_reference_template", + "input_format": "Answer the question based on the information provided in the document given below. The answer should be a single word or a number or a short phrase of few words\nDocument: {context}\nQuestion: {question}\nAnswer: ", + "references_field": "answers" +}