Support streaming
#1
by
albertvillanova
HF Staff
- opened
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 |
|
|
@@ -518,9 +520,11 @@ def parse_brat_file(txt_file: Path, annotation_file_suffixes: List[str] = None)
|
|
| 518 |
ann_lines = []
|
| 519 |
for suffix in annotation_file_suffixes:
|
| 520 |
annotation_file = txt_file.with_suffix(suffix)
|
| 521 |
-
|
| 522 |
with annotation_file.open() as f:
|
| 523 |
ann_lines.extend(f.readlines())
|
|
|
|
|
|
|
| 524 |
|
| 525 |
example["text_bound_annotations"] = []
|
| 526 |
example["events"] = []
|
|
|
|
| 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 |
|
|
|
|
| 520 |
ann_lines = []
|
| 521 |
for suffix in annotation_file_suffixes:
|
| 522 |
annotation_file = txt_file.with_suffix(suffix)
|
| 523 |
+
try:
|
| 524 |
with annotation_file.open() as f:
|
| 525 |
ann_lines.extend(f.readlines())
|
| 526 |
+
except Exception:
|
| 527 |
+
continue
|
| 528 |
|
| 529 |
example["text_bound_annotations"] = []
|
| 530 |
example["events"] = []
|