Update files from the datasets library (from 1.16.0)
Browse filesRelease notes: https://github.com/huggingface/datasets/releases/tag/1.16.0
- README.md +1 -0
- math_dataset.py +27 -35
README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
---
|
|
|
2 |
languages:
|
3 |
- en
|
4 |
paperswithcode_id: mathematics
|
|
|
1 |
---
|
2 |
+
pretty_name: Mathematics Dataset
|
3 |
languages:
|
4 |
- en
|
5 |
paperswithcode_id: mathematics
|
math_dataset.py
CHANGED
@@ -16,9 +16,6 @@
|
|
16 |
# Lint as: python3
|
17 |
"""Mathematics database."""
|
18 |
|
19 |
-
|
20 |
-
import os
|
21 |
-
|
22 |
import datasets
|
23 |
|
24 |
|
@@ -223,33 +220,24 @@ class MathDataset(datasets.GeneratorBasedBuilder):
|
|
223 |
citation=_CITATION,
|
224 |
)
|
225 |
|
226 |
-
def
|
227 |
-
|
228 |
for category in categories:
|
229 |
-
data_file =
|
230 |
-
|
231 |
-
|
232 |
-
ls = f.read().split("\n")
|
233 |
-
|
234 |
-
for line in ls[::-1]:
|
235 |
-
if not line:
|
236 |
-
ls.remove(line)
|
237 |
-
|
238 |
-
lines.extend(ls)
|
239 |
-
|
240 |
-
return lines
|
241 |
|
242 |
def _split_generators(self, dl_manager):
|
243 |
"""Returns SplitGenerators."""
|
244 |
|
245 |
-
|
246 |
config = self.config.name + ".txt"
|
247 |
|
248 |
return [
|
249 |
datasets.SplitGenerator(
|
250 |
name=datasets.Split.TRAIN,
|
251 |
gen_kwargs={
|
252 |
-
"
|
253 |
"config": config,
|
254 |
"categories": _TRAIN_CATEGORY,
|
255 |
},
|
@@ -257,27 +245,31 @@ class MathDataset(datasets.GeneratorBasedBuilder):
|
|
257 |
datasets.SplitGenerator(
|
258 |
name=datasets.Split.TEST,
|
259 |
gen_kwargs={
|
260 |
-
"
|
261 |
"config": config,
|
262 |
"categories": _INTERPOLATE_CATEGORY,
|
263 |
},
|
264 |
),
|
265 |
]
|
266 |
|
267 |
-
def _generate_examples(self,
|
268 |
"""Yields examples based on directory, module file.."""
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
|
|
|
|
|
|
|
|
|
16 |
# Lint as: python3
|
17 |
"""Mathematics database."""
|
18 |
|
|
|
|
|
|
|
19 |
import datasets
|
20 |
|
21 |
|
|
|
220 |
citation=_CITATION,
|
221 |
)
|
222 |
|
223 |
+
def _get_filepaths_from_categories(self, config, categories):
|
224 |
+
filepaths = []
|
225 |
for category in categories:
|
226 |
+
data_file = "/".join([_DATASET_VERSION, category, config])
|
227 |
+
filepaths.append(data_file)
|
228 |
+
return set(filepaths)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
def _split_generators(self, dl_manager):
|
231 |
"""Returns SplitGenerators."""
|
232 |
|
233 |
+
archive = dl_manager.download(_DATA_URL)
|
234 |
config = self.config.name + ".txt"
|
235 |
|
236 |
return [
|
237 |
datasets.SplitGenerator(
|
238 |
name=datasets.Split.TRAIN,
|
239 |
gen_kwargs={
|
240 |
+
"files": dl_manager.iter_archive(archive),
|
241 |
"config": config,
|
242 |
"categories": _TRAIN_CATEGORY,
|
243 |
},
|
|
|
245 |
datasets.SplitGenerator(
|
246 |
name=datasets.Split.TEST,
|
247 |
gen_kwargs={
|
248 |
+
"files": dl_manager.iter_archive(archive),
|
249 |
"config": config,
|
250 |
"categories": _INTERPOLATE_CATEGORY,
|
251 |
},
|
252 |
),
|
253 |
]
|
254 |
|
255 |
+
def _generate_examples(self, files, config, categories):
|
256 |
"""Yields examples based on directory, module file.."""
|
257 |
|
258 |
+
idx = 0
|
259 |
+
filepaths = self._get_filepaths_from_categories(config, categories)
|
260 |
+
for path, f in files:
|
261 |
+
if not filepaths:
|
262 |
+
break
|
263 |
+
elif path in filepaths:
|
264 |
+
for question in f:
|
265 |
+
if not question:
|
266 |
+
continue
|
267 |
+
else:
|
268 |
+
for answer in f:
|
269 |
+
if not answer:
|
270 |
+
continue
|
271 |
+
else:
|
272 |
+
yield idx, {_QUESTION: question, _ANSWER: answer}
|
273 |
+
idx += 1
|
274 |
+
break
|
275 |
+
filepaths.remove(path)
|