Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
albertvillanova HF staff commited on
Commit
d1d4571
·
verified ·
1 Parent(s): f1025a3

Use iter_files

Browse files
Files changed (1) hide show
  1. chia.py +7 -5
chia.py CHANGED
@@ -232,20 +232,21 @@ class ChiaDataset(datasets.GeneratorBasedBuilder):
232
  url_key += "_wo_scope"
233
 
234
  urls = _URLS[url_key]
235
- data_dir = Path(dl_manager.download_and_extract(urls))
236
 
237
  return [
238
  datasets.SplitGenerator(
239
  name=datasets.Split.TRAIN,
240
- gen_kwargs={"data_dir": data_dir},
241
  )
242
  ]
243
 
244
- def _generate_examples(self, data_dir: Path) -> Iterator[Tuple[str, Dict]]:
245
  if self.config.schema == "source":
246
  fix_offsets = "fixed" in self.config.subset_id
247
 
248
- for file in data_dir.iterdir():
 
249
  if not file.name.endswith(".txt"):
250
  continue
251
 
@@ -256,7 +257,8 @@ class ChiaDataset(datasets.GeneratorBasedBuilder):
256
  yield source_example["id"], source_example
257
 
258
  elif self.config.schema == "bigbio_kb":
259
- for file in data_dir.iterdir():
 
260
  if not file.name.endswith(".txt"):
261
  continue
262
 
 
232
  url_key += "_wo_scope"
233
 
234
  urls = _URLS[url_key]
235
+ data_dir = dl_manager.download_and_extract(urls)
236
 
237
  return [
238
  datasets.SplitGenerator(
239
  name=datasets.Split.TRAIN,
240
+ gen_kwargs={"file_paths": dl_manager.iter_files(data_dir)},
241
  )
242
  ]
243
 
244
+ def _generate_examples(self, file_paths: Iterator[str]) -> Iterator[Tuple[str, Dict]]:
245
  if self.config.schema == "source":
246
  fix_offsets = "fixed" in self.config.subset_id
247
 
248
+ for file_path in file_paths:
249
+ file = Path(file_path)
250
  if not file.name.endswith(".txt"):
251
  continue
252
 
 
257
  yield source_example["id"], source_example
258
 
259
  elif self.config.schema == "bigbio_kb":
260
+ for file_path in file_paths:
261
+ file = Path(file_path)
262
  if not file.name.endswith(".txt"):
263
  continue
264