CoQCat / OLD /CoQCat.py
AnnaSallesRius's picture
Upload 4 files
21060c8 verified
"""CoQA dataset."""
import json
import datasets
_HOMEPAGE = ""
_CITATION = """\
"""
_DESCRIPTION = """\
CoQCat - Conversational Question Answering in Catalan
"""
_TRAIN_FILE = "train.json"
_DEV_FILE = "dev.json"
_TEST_FILE = "test.json"
class Coqa(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"source": datasets.Value("string"),
"story": datasets.Value("string"),
"questions": datasets.features.Sequence(datasets.Value("string")),
"answers": datasets.features.Sequence(
{
"input_text": datasets.Value("string"),
"answer_start": datasets.Value("int32"),
"answer_end": datasets.Value("int32"),
}
),
}
),
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
"train": f"{_TRAIN_FILE}",
"dev": f"{_DEV_FILE}",
"test": f"{_TEST_FILE}",
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"], "split": "train"}),
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"], "split": "validation"}),
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"], "split": "test"}),
]
def _generate_examples(self, filepath, split):
"""Yields examples."""
with open(filepath, encoding="utf-8") as f:
data = json.load(f)
for row in data["data"]:
questions = [question["input_text"] for question in row["questions"]]
story = row["story"]
source = row["source"]
answers_start = [answer["span_start"] for answer in row["answers"]]
answers_end = [answer["span_end"] for answer in row["answers"]]
answers = [answer["input_text"] for answer in row["answers"]]
yield row["id"], {
"source": source,
"story": story,
"questions": questions,
"answers": {"input_text": answers, "answer_start": answers_start, "answer_end": answers_end},
}