Skip to content

Commit

Permalink
Separate template
Browse files Browse the repository at this point in the history
  • Loading branch information
marukaz authored and elronbandel committed Feb 28, 2024
1 parent 45115d4 commit 9b640fe
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 55 deletions.
15 changes: 1 addition & 14 deletions prepare/cards/ffqa_filtered.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions prepare/templates/qa/with_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,29 @@
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(
[
"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.ffqa",
]
),
"templates.qa.with_context.all",
Expand Down
11 changes: 1 addition & 10 deletions src/unitxt/catalog/cards/ffqa_filtered/16k.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
11 changes: 1 addition & 10 deletions src/unitxt/catalog/cards/ffqa_filtered/2k.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
11 changes: 1 addition & 10 deletions src/unitxt/catalog/cards/ffqa_filtered/4k.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
11 changes: 1 addition & 10 deletions src/unitxt/catalog/cards/ffqa_filtered/8k.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/unitxt/catalog/templates/qa/with_context/all.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
5 changes: 5 additions & 0 deletions src/unitxt/catalog/templates/qa/with_context/ffqa.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 9b640fe

Please sign in to comment.