-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: elronbandel <[email protected]>
- Loading branch information
1 parent
2ef9091
commit 14401eb
Showing
9 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from typing import Any, Dict | ||
|
||
from unitxt.blocks import LoadHF, TaskCard | ||
from unitxt.collections_operators import DuplicateBySubLists, Pop, Wrap | ||
from unitxt.operator import InstanceOperator | ||
from unitxt.operators import AddID, Copy, FieldOperator, ZipFieldValues | ||
from unitxt.test_utils.card import test_card | ||
|
||
|
||
class Pass(InstanceOperator): | ||
def process( | ||
self, instance: Dict[str, Any], stream_name: str | None = None | ||
) -> Dict[str, Any]: | ||
return instance | ||
|
||
|
||
class ToDialog(FieldOperator): | ||
def process_value(self, value: Any) -> Any: | ||
dialog = [] | ||
for question, answer in value: | ||
dialog.append({"role": "user", "content": question}) | ||
dialog.append({"role": "agent", "content": answer}) | ||
return dialog | ||
|
||
|
||
card = TaskCard( | ||
loader=LoadHF(path="stanfordnlp/coqa"), | ||
preprocess_steps=[ | ||
"splitters.small_no_test", | ||
AddID(), | ||
Copy(field="id", to_field="conversation/id"), | ||
ZipFieldValues( | ||
fields=["questions", "answers/input_text"], | ||
to_field="dialog", | ||
), | ||
DuplicateBySubLists(field="dialog"), | ||
ToDialog(field="dialog"), | ||
Pop(field="dialog", item=-1, to_field="last_turn"), | ||
Copy( | ||
field_to_field={"last_turn/content": "answer", "story": "context"}, | ||
), | ||
Wrap( | ||
field="answer", | ||
inside="list", | ||
to_field="answers", | ||
), | ||
Copy(field="dialog", to_field="conversation/dialog"), | ||
], | ||
task="tasks.qa.extractive.multi_turn", | ||
templates=["templates.qa.multi_turn.with_context.simple"], | ||
__tags__={ | ||
"annotations_creators": "crowdsourced", | ||
"arxiv": ["1808.07042", "1704.04683", "1506.03340"], | ||
"flags": ["conversational-qa"], | ||
"language": "en", | ||
"language_creators": "found", | ||
"license": "other", | ||
"multilinguality": "monolingual", | ||
"region": "us", | ||
"size_categories": "1K<n<10K", | ||
"source_datasets": [ | ||
"extended|race", | ||
"extended|cnn_dailymail", | ||
"extended|wikipedia", | ||
"extended|other", | ||
], | ||
"task_categories": "question-answering", | ||
"task_ids": "extractive-qa", | ||
}, | ||
__description__=( | ||
"CoQA is a large-scale dataset for building Conversational Question Answering systems. \n" | ||
"Our dataset contains 127k questions with answers, obtained from 8k conversations about text passages from seven diverse domains. The questions are conversational, and the answers are free-form text with their corresponding evidence highlighted in the passage. Supported Tasks and Leaderboards More Information Needed… See the full description on the dataset page: https://huggingface.co/datasets/stanfordnlp/coqa." | ||
), | ||
) | ||
|
||
test_card(card) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"__type__": "task", | ||
"__description__": "", | ||
"input_fields": { | ||
"context": "Union[Text, Table]", | ||
"conversation": "Conversation" | ||
}, | ||
"reference_fields": { | ||
"answers": "List[str]" | ||
}, | ||
"prediction_type": "str", | ||
"metrics": [ | ||
"metrics.squad" | ||
], | ||
"default_template": "templates.qa.extractive", | ||
"augmentable_inputs": [ | ||
"context" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/unitxt/catalog/templates/qa/multi_turn/with_context/simple.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"__type__": "multi_reference_template", | ||
"input_format": "Context: {context}\n{conversation}", | ||
"references_field": "answers" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters