"""TODO: DATASET SHORT DESCRIPTION""" import json import datasets from datasets.tasks import TextClassification _DESCRIPTION = """TODO: DATASET DESCRIPTION""" _CITATION = """TODO: CITATIONS""" _URL = "https://huggingface.co/datasets/rsgrava/deepage2_qa_dataset/resolve/main/" _URLS = { "train": _URL + "expanded_ds-train.json", "dev": _URL + "expanded_ds-dev.json", } class SquadV1PtBr(datasets.GeneratorBasedBuilder): """TODO: SHORT DATASET DESCRIPTION""" VERSION = datasets.Version("1.1.0") def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "question": datasets.Value("string"), "answer": datasets.Value("string"), } ), # No default supervised_keys (as we have to pass both question and context as input). supervised_keys=None, homepage="TODO: HOMEPAGE", citation=_CITATION, ) def _split_generators(self, dl_manager): urls_to_download = _URLS downloaded_files = dl_manager.download_and_extract(urls_to_download) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), ] def _generate_examples(self, filepath): with open(filepath) as f: key = 0 ds = [] for line in f: ds.append(json.loads(line)) for example in ds: yield key, { "question": example["question"], "answer": example["answer"], } key += 1