Use iter_files
Browse files
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 =
|
| 236 |
|
| 237 |
return [
|
| 238 |
datasets.SplitGenerator(
|
| 239 |
name=datasets.Split.TRAIN,
|
| 240 |
-
gen_kwargs={"
|
| 241 |
)
|
| 242 |
]
|
| 243 |
|
| 244 |
-
def _generate_examples(self,
|
| 245 |
if self.config.schema == "source":
|
| 246 |
fix_offsets = "fixed" in self.config.subset_id
|
| 247 |
|
| 248 |
-
for
|
|
|
|
| 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
|
|
|
|
| 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 |
|