Abinaya Mahendiran
commited on
Commit
•
88991a8
1
Parent(s):
c1bf92d
Updated data loader script
Browse files- squad_v2.py +15 -67
squad_v2.py
CHANGED
@@ -28,24 +28,14 @@ _DESCRIPTION = """\
|
|
28 |
"""
|
29 |
|
30 |
_URLS = {
|
31 |
-
"
|
32 |
-
|
33 |
-
"train": "./
|
34 |
-
"test": "./
|
35 |
-
"validation": "./
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
"test": "./challenge_sets/question_type_split/challenge_question_filter_test.json",
|
40 |
-
"validation": "./challenge_sets/question_type_split/challenge_question_filter_validation.json",
|
41 |
-
},
|
42 |
-
"answerable_question_split": {
|
43 |
-
"train": "./challenge_sets/answerable_question_split/challenge_answer_filter_train.json",
|
44 |
-
"test": "./challenge_sets/answerable_question_split/challenge_answer_filter_test.json",
|
45 |
-
"validation": "./challenge_sets/answerable_question_split/challenge_answer_filter_validation.json",
|
46 |
-
},
|
47 |
-
}
|
48 |
-
}
|
49 |
|
50 |
|
51 |
class SquadV2Config(datasets.BuilderConfig):
|
@@ -67,10 +57,10 @@ class SquadV2(datasets.GeneratorBasedBuilder):
|
|
67 |
VERSION_1 = datasets.Version("1.0.0")
|
68 |
|
69 |
BUILDER_CONFIGS = [
|
70 |
-
SquadV2Config(name="
|
71 |
]
|
72 |
|
73 |
-
DEFAULT_CONFIG_NAME = "
|
74 |
|
75 |
def _info(self):
|
76 |
# TODO(squad_v2): Specifies the datasets.DatasetInfo object
|
@@ -116,74 +106,32 @@ class SquadV2(datasets.GeneratorBasedBuilder):
|
|
116 |
datasets.SplitGenerator(
|
117 |
name=datasets.Split.TRAIN,
|
118 |
gen_kwargs={
|
119 |
-
"filepath": downloaded_files["
|
120 |
"split": "train",
|
121 |
},
|
122 |
),
|
123 |
datasets.SplitGenerator(
|
124 |
name=datasets.Split.VALIDATION,
|
125 |
gen_kwargs={
|
126 |
-
"filepath": downloaded_files["
|
127 |
"split": "validation",
|
128 |
},
|
129 |
),
|
130 |
datasets.SplitGenerator(
|
131 |
name=datasets.Split.TEST,
|
132 |
gen_kwargs={
|
133 |
-
"filepath": downloaded_files["
|
134 |
-
"split": "test",
|
135 |
-
},
|
136 |
-
),
|
137 |
-
datasets.SplitGenerator(
|
138 |
-
name="question_type_train",
|
139 |
-
gen_kwargs={
|
140 |
-
"filepath": downloaded_files["question_type_split"]["train"],
|
141 |
-
"split": "train",
|
142 |
-
},
|
143 |
-
),
|
144 |
-
datasets.SplitGenerator(
|
145 |
-
name="question_type_test",
|
146 |
-
gen_kwargs={
|
147 |
-
"filepath": downloaded_files["question_type_split"]["test"],
|
148 |
-
"split": "test",
|
149 |
-
},
|
150 |
-
),
|
151 |
-
datasets.SplitGenerator(
|
152 |
-
name="question_type_validation",
|
153 |
-
gen_kwargs={
|
154 |
-
"filepath": downloaded_files["question_type_split"]["validation"],
|
155 |
-
"split": "validation",
|
156 |
-
},
|
157 |
-
),
|
158 |
-
datasets.SplitGenerator(
|
159 |
-
name="answerable_question_train",
|
160 |
-
gen_kwargs={
|
161 |
-
"filepath": downloaded_files["answerable_question_split"]["train"],
|
162 |
-
"split": "train",
|
163 |
-
},
|
164 |
-
),
|
165 |
-
datasets.SplitGenerator(
|
166 |
-
name="answerable_question_test",
|
167 |
-
gen_kwargs={
|
168 |
-
"filepath": downloaded_files["answerable_question_split"]["test"],
|
169 |
"split": "test",
|
170 |
},
|
171 |
),
|
172 |
-
datasets.SplitGenerator(
|
173 |
-
name="answerable_question_validation",
|
174 |
-
gen_kwargs={
|
175 |
-
"filepath": downloaded_files["answerable_question_split"]["validation"],
|
176 |
-
"split": "validation",
|
177 |
-
},
|
178 |
-
),
|
179 |
]
|
180 |
|
181 |
def _generate_examples(self, filepath, split):
|
182 |
"""Yields examples."""
|
183 |
# TODO(squad_v2): Yields (key, example) tuples from the dataset
|
184 |
with open(filepath, encoding="utf-8") as f:
|
185 |
-
|
186 |
-
|
187 |
# Features currently used are "context", "question", and "answers".
|
188 |
# Others are extracted here for the ease of future expansions.
|
189 |
yield id_, {
|
|
|
28 |
"""
|
29 |
|
30 |
_URLS = {
|
31 |
+
"gem_data_split":
|
32 |
+
{
|
33 |
+
"train": "./gem_data_split/train.json",
|
34 |
+
"test": "./gem_data_split/test.json",
|
35 |
+
"validation": "./gem_data_split/validation.json",
|
36 |
+
},
|
37 |
+
}
|
38 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
|
41 |
class SquadV2Config(datasets.BuilderConfig):
|
|
|
57 |
VERSION_1 = datasets.Version("1.0.0")
|
58 |
|
59 |
BUILDER_CONFIGS = [
|
60 |
+
SquadV2Config(name="gem_data_split", version=VERSION_1, description="SQuAD2.0 - GEM version 1"),
|
61 |
]
|
62 |
|
63 |
+
DEFAULT_CONFIG_NAME = "gem_data_split"
|
64 |
|
65 |
def _info(self):
|
66 |
# TODO(squad_v2): Specifies the datasets.DatasetInfo object
|
|
|
106 |
datasets.SplitGenerator(
|
107 |
name=datasets.Split.TRAIN,
|
108 |
gen_kwargs={
|
109 |
+
"filepath": downloaded_files["gem_data_split"]["train"],
|
110 |
"split": "train",
|
111 |
},
|
112 |
),
|
113 |
datasets.SplitGenerator(
|
114 |
name=datasets.Split.VALIDATION,
|
115 |
gen_kwargs={
|
116 |
+
"filepath": downloaded_files["gem_data_split"]["validation"],
|
117 |
"split": "validation",
|
118 |
},
|
119 |
),
|
120 |
datasets.SplitGenerator(
|
121 |
name=datasets.Split.TEST,
|
122 |
gen_kwargs={
|
123 |
+
"filepath": downloaded_files["gem_data_split"]["test"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
"split": "test",
|
125 |
},
|
126 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
]
|
128 |
|
129 |
def _generate_examples(self, filepath, split):
|
130 |
"""Yields examples."""
|
131 |
# TODO(squad_v2): Yields (key, example) tuples from the dataset
|
132 |
with open(filepath, encoding="utf-8") as f:
|
133 |
+
data = json.load(f)
|
134 |
+
for id_, row in data:
|
135 |
# Features currently used are "context", "question", and "answers".
|
136 |
# Others are extracted here for the ease of future expansions.
|
137 |
yield id_, {
|