|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""TopiOCQA: Open-domain Conversational Question Answering with Topic Switching""" |
|
|
|
|
|
import json |
|
|
|
import datasets |
|
|
|
|
|
|
|
logger = datasets.logging.get_logger(__name__) |
|
|
|
|
|
_DESCRIPTION = """\ |
|
TopiOCQA is an information-seeking conversational dataset with challenging topic switching phenomena. |
|
""" |
|
|
|
_URLS = { |
|
"train": "data/topiocqa_train.jsonl", |
|
"valid": "data/topiocqa_valid.jsonl", |
|
} |
|
|
|
|
|
class TopiOCQAConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for TopiOCQA.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for TopiOCQA. |
|
|
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(TopiOCQAConfig, self).__init__(**kwargs) |
|
|
|
|
|
class TopiOCQA(datasets.GeneratorBasedBuilder): |
|
"""TopiOCQA: Open-domain Conversational Question Answering with Topic Switching""" |
|
|
|
BUILDER_CONFIGS = [ |
|
TopiOCQAConfig( |
|
name="plain_text", |
|
version=datasets.Version("1.0.1", ""), |
|
description="Plain text", |
|
), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"Conversation_no": datasets.Value("int32"), |
|
"Turn_no": datasets.Value("int32"), |
|
"Question": datasets.Value("string"), |
|
"Answer": datasets.Value("string"), |
|
"Topic": datasets.Value("string"), |
|
"Topic_section": datasets.Value("string"), |
|
"Rationale": datasets.Value("string"), |
|
"is_nq": datasets.Value("bool"), |
|
"Context": datasets.features.Sequence(datasets.Value("string")), |
|
"Additional_answers": datasets.features.Sequence( |
|
{ |
|
"Answer": datasets.Value("string"), |
|
"Topic": datasets.Value("string"), |
|
"Topic_section": datasets.Value("string"), |
|
"Rationale": datasets.Value("string"), |
|
} |
|
), |
|
"Gold_passage": { |
|
"id": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"text": datasets.Value("string"), |
|
} |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage="https://mcgill-nlp.github.io/topiocqa/", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_files = dl_manager.download_and_extract(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), |
|
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""This function returns the examples in the raw (text) form.""" |
|
logger.info("generating examples from = %s", filepath) |
|
key = 0 |
|
with open(filepath, encoding="utf-8") as f: |
|
for line in f: |
|
data = json.loads(line) |
|
yield key, { |
|
"Conversation_no": data["Conversation_no"], |
|
"Turn_no": data["Turn_no"], |
|
"Question": data["Question"], |
|
"Answer": data["Answer"], |
|
"Topic": data["Topic"], |
|
"Topic_section": data["Topic_section"], |
|
"Rationale": data["Rationale"], |
|
"is_nq": data["is_nq"], |
|
"Context": data["Context"], |
|
"Additional_answers": data["Additional_answers"], |
|
"Gold_passage": data["Gold_passage"], |
|
} |
|
key += 1 |
|
|
|
|