# coding=utf-8 # Lint as: python3 """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=1s7ok8_DqYDtboOHubesK43yohmTkZiGk" 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+"/UnibQuAD/UnibQuAD_train.json"}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files+"/UnibQuAD/UnibQuAD_test.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, }