Fix streaming TAR archive
Browse files- scicite.py +12 -8
scicite.py
CHANGED
|
@@ -29,7 +29,6 @@ TODO: Use standard BigBio missing values.
|
|
| 29 |
"""
|
| 30 |
|
| 31 |
import json
|
| 32 |
-
import os
|
| 33 |
from typing import Dict, List, Tuple
|
| 34 |
|
| 35 |
import datasets
|
|
@@ -147,37 +146,42 @@ class SciciteDataset(datasets.GeneratorBasedBuilder):
|
|
| 147 |
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
| 148 |
"""Returns SplitGenerators."""
|
| 149 |
urls = _URLS[_DATASETNAME]
|
| 150 |
-
data_dir = dl_manager.
|
| 151 |
|
| 152 |
return [
|
| 153 |
datasets.SplitGenerator(
|
| 154 |
name=datasets.Split.TRAIN,
|
| 155 |
gen_kwargs={
|
| 156 |
-
"
|
|
|
|
| 157 |
"split": "train",
|
| 158 |
},
|
| 159 |
),
|
| 160 |
datasets.SplitGenerator(
|
| 161 |
name=datasets.Split.TEST,
|
| 162 |
gen_kwargs={
|
| 163 |
-
"
|
|
|
|
| 164 |
"split": "test",
|
| 165 |
},
|
| 166 |
),
|
| 167 |
datasets.SplitGenerator(
|
| 168 |
name=datasets.Split.VALIDATION,
|
| 169 |
gen_kwargs={
|
| 170 |
-
"
|
|
|
|
| 171 |
"split": "dev",
|
| 172 |
},
|
| 173 |
),
|
| 174 |
]
|
| 175 |
|
| 176 |
-
def _generate_examples(self, filepath, split: str) -> Tuple[int, Dict]:
|
| 177 |
"""Yields examples as (key, example) tuples."""
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
| 181 |
|
| 182 |
# Preprocesses examples
|
| 183 |
keys = set()
|
|
|
|
| 29 |
"""
|
| 30 |
|
| 31 |
import json
|
|
|
|
| 32 |
from typing import Dict, List, Tuple
|
| 33 |
|
| 34 |
import datasets
|
|
|
|
| 146 |
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
| 147 |
"""Returns SplitGenerators."""
|
| 148 |
urls = _URLS[_DATASETNAME]
|
| 149 |
+
data_dir = dl_manager.download(urls)
|
| 150 |
|
| 151 |
return [
|
| 152 |
datasets.SplitGenerator(
|
| 153 |
name=datasets.Split.TRAIN,
|
| 154 |
gen_kwargs={
|
| 155 |
+
"archive": dl_manager.iter_archive(data_dir),
|
| 156 |
+
"filepath": "scicite/train.jsonl",
|
| 157 |
"split": "train",
|
| 158 |
},
|
| 159 |
),
|
| 160 |
datasets.SplitGenerator(
|
| 161 |
name=datasets.Split.TEST,
|
| 162 |
gen_kwargs={
|
| 163 |
+
"archive": dl_manager.iter_archive(data_dir),
|
| 164 |
+
"filepath": "scicite/test.jsonl",
|
| 165 |
"split": "test",
|
| 166 |
},
|
| 167 |
),
|
| 168 |
datasets.SplitGenerator(
|
| 169 |
name=datasets.Split.VALIDATION,
|
| 170 |
gen_kwargs={
|
| 171 |
+
"archive": dl_manager.iter_archive(data_dir),
|
| 172 |
+
"filepath": "scicite/dev.jsonl",
|
| 173 |
"split": "dev",
|
| 174 |
},
|
| 175 |
),
|
| 176 |
]
|
| 177 |
|
| 178 |
+
def _generate_examples(self, archive, filepath, split: str) -> Tuple[int, Dict]:
|
| 179 |
"""Yields examples as (key, example) tuples."""
|
| 180 |
|
| 181 |
+
for path, file in archive:
|
| 182 |
+
if path == filepath:
|
| 183 |
+
examples = [json.loads(line) for line in file]
|
| 184 |
+
break
|
| 185 |
|
| 186 |
# Preprocesses examples
|
| 187 |
keys = set()
|