Datasets:

Languages:
English
ArXiv:
system HF staff commited on
Commit
3301135
1 Parent(s): 3fe2f7b

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. 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 _read_data_from_all_categories(self, directory, config, categories):
227
- lines = []
228
  for category in categories:
229
- data_file = os.path.join(directory, _DATASET_VERSION, category, config)
230
- if os.path.exists(data_file):
231
- with open(data_file, encoding="utf-8") as f:
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
- directory = dl_manager.download_and_extract(_DATA_URL)
246
  config = self.config.name + ".txt"
247
 
248
  return [
249
  datasets.SplitGenerator(
250
  name=datasets.Split.TRAIN,
251
  gen_kwargs={
252
- "directory": directory,
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
- "directory": directory,
261
  "config": config,
262
  "categories": _INTERPOLATE_CATEGORY,
263
  },
264
  ),
265
  ]
266
 
267
- def _generate_examples(self, directory, config, categories):
268
  """Yields examples based on directory, module file.."""
269
 
270
- lines = self._read_data_from_all_categories(directory, config, categories)
271
- logger.info("%s: %s contains total: %d", categories, config, len(lines))
272
- questions = lines[::2]
273
- answers = lines[1::2]
274
-
275
- assert len(answers) == len(questions), "answers: %d do not match questions: %d" % (
276
- len(answers),
277
- len(questions),
278
- )
279
-
280
- for idx, (q, a) in enumerate(zip(questions, answers)):
281
- result = {_QUESTION: q, _ANSWER: a}
282
- if all(result.values()):
283
- yield idx, result
 
 
 
 
 
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)