File size: 3,393 Bytes
77add5e
 
 
 
 
 
 
 
 
 
 
 
 
 
fa7ca9c
77add5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""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,
                        }