fedryanto commited on
Commit
3e18e57
·
1 Parent(s): d526b69

Create quad2.py

Browse files
Files changed (1) hide show
  1. quad2.py +92 -0
quad2.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """UnibQuAD: A Indonesian-Language Question Answering Dataset Base On University Of Bengkulu."""
2
+
3
+ import json
4
+
5
+ import datasets
6
+
7
+
8
+ logger = datasets.logging.get_logger(__name__)
9
+
10
+
11
+ _CITATION = """ """
12
+
13
+ _DESCRIPTION = """ """
14
+
15
+ _URL = "https://drive.google.com/uc?export=download&id=1rL3i2ePYM-yVpdCbYQR67wrcgHytqzy8"
16
+
17
+
18
+ class UnibQuADConfig(datasets.BuilderConfig):
19
+ """BuilderConfig for UnibQuAD."""
20
+
21
+ def __init__(self, **kwargs):
22
+ """BuilderConfig for UnibQuAD.
23
+ Args:
24
+ **kwargs: keyword arguments forwarded to super.
25
+ """
26
+ super(UnibQuADConfig, self).__init__(**kwargs)
27
+
28
+
29
+ class UnibDPR(datasets.GeneratorBasedBuilder):
30
+ """UnibQuAD: A Indonesian-Language Question Answering Dataset Base On University Of Bengkulu."""
31
+
32
+ BUILDER_CONFIGS = [
33
+ UnibQuADConfig(
34
+ name="plain_text",
35
+ version=datasets.Version("1.0.0", ""),
36
+ description="Plain text",
37
+ ),
38
+ ]
39
+
40
+ def _info(self):
41
+ return datasets.DatasetInfo(
42
+ description=_DESCRIPTION,
43
+ features=datasets.Features(
44
+ {
45
+ "id": datasets.Value("string"),
46
+ "context": datasets.Value("string"),
47
+ "question": datasets.Value("string"),
48
+ "answers": datasets.features.Sequence(
49
+ {
50
+ "text": datasets.Value("string"),
51
+ "answer_start": datasets.Value("int32"),
52
+ }
53
+ )
54
+ }
55
+ ),
56
+ # No default supervised_keys (as we have to pass both question
57
+ # and context as input).
58
+ supervised_keys=None,
59
+ homepage=" ",
60
+ citation=_CITATION,
61
+ )
62
+
63
+ def _split_generators(self, dl_manager):
64
+ downloaded_files = dl_manager.download_and_extract(_URL)
65
+
66
+ return [
67
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files+"/quad2/train_quad2.json"}),
68
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files+"/quad2/test_quad2.json"}),
69
+ ]
70
+
71
+ def _generate_examples(self, filepath):
72
+ """This function returns the examples in the raw (text) form."""
73
+ logger.info("generating examples from = %s", filepath)
74
+ with open(filepath, encoding="utf-8") as f:
75
+ UnibQuAD = json.load(f)
76
+ for article in UnibQuAD["data"]:
77
+ for paragraph in article["paragraphs"]:
78
+ context = paragraph["context"]
79
+ document_id = paragraph["document_id"]
80
+ for qa in paragraph["qas"]:
81
+ question = qa["question"]
82
+ id_ = qa["id"]
83
+ answers = [{"answer_start": answer["answer_start"], "text": answer["text"]} for answer in qa["answers"]]
84
+
85
+ # Features currently used are "context", "question", and "answers".
86
+ # Others are extracted here for the ease of future expansions.
87
+ yield id_, {
88
+ "context": context,
89
+ "question": question,
90
+ "id": id_,
91
+ "answers": answers,
92
+ }