Download quad3.py from fedryanto/quad3: direct link, hf CLI and curl.
- Browser
- Download file 3.39 kB
-
https://huggingface.co/datasets/fedryanto/quad3/resolve/main/quad3.py
- Command line
-
hf download hf://datasets/fedryanto/quad3/quad3.py
-
curl -L -o quad3.py https://huggingface.co/datasets/fedryanto/quad3/resolve/main/quad3.py
3.39 kB
| """UnibQuAD: A Indonesian-Language Question Answering Dataset Base On University Of Bengkulu.""" | |
| import json | |
| import datasets | |
| logger = datasets.logging.get_logger(__name__) | |
| _CITATION = """ """ | |
| _DESCRIPTION = """ """ | |
| _URL = "https://drive.google.com/uc?export=download&id=14hqePCXk2SFnmgrFomVqI6Qi3cmKSb0H" | |
| class UnibQuADConfig(datasets.BuilderConfig): | |
| """BuilderConfig for UnibQuAD.""" | |
| def __init__(self, **kwargs): | |
| """BuilderConfig for UnibQuAD. | |
| Args: | |
| **kwargs: keyword arguments forwarded to super. | |
| """ | |
| super(UnibQuADConfig, self).__init__(**kwargs) | |
| class UnibDPR(datasets.GeneratorBasedBuilder): | |
| """UnibQuAD: A Indonesian-Language Question Answering Dataset Base On University Of Bengkulu.""" | |
| BUILDER_CONFIGS = [ | |
| UnibQuADConfig( | |
| name="plain_text", | |
| version=datasets.Version("1.0.0", ""), | |
| description="Plain text", | |
| ), | |
| ] | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=datasets.Features( | |
| { | |
| "id": datasets.Value("string"), | |
| "context": datasets.Value("string"), | |
| "question": datasets.Value("string"), | |
| "answers": datasets.features.Sequence( | |
| { | |
| "text": datasets.Value("string"), | |
| "answer_start": datasets.Value("int32"), | |
| } | |
| ) | |
| } | |
| ), | |
| # No default supervised_keys (as we have to pass both question | |
| # and context as input). | |
| supervised_keys=None, | |
| homepage=" ", | |
| citation=_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager): | |
| downloaded_files = dl_manager.download_and_extract(_URL) | |
| return [ | |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files+"/quad3/train_quad3.json"}), | |
| datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files+"/quad3/test_quad3.json"}), | |
| ] | |
| def _generate_examples(self, filepath): | |
| """This function returns the examples in the raw (text) form.""" | |
| logger.info("generating examples from = %s", filepath) | |
| with open(filepath, encoding="utf-8") as f: | |
| UnibQuAD = json.load(f) | |
| for article in UnibQuAD["data"]: | |
| for paragraph in article["paragraphs"]: | |
| context = paragraph["context"] | |
| document_id = paragraph["document_id"] | |
| for qa in paragraph["qas"]: | |
| question = qa["question"] | |
| id_ = qa["id"] | |
| answers = [{"answer_start": answer["answer_start"], "text": answer["text"]} for answer in qa["answers"]] | |
| # Features currently used are "context", "question", and "answers". | |
| # Others are extracted here for the ease of future expansions. | |
| yield id_, { | |
| "context": context, | |
| "question": question, | |
| "id": id_, | |
| "answers": answers, | |
| } |