Fixed error on for uncompressed files
#8
by
malteos
- opened
- proof-pile-2.py +23 -11
proof-pile-2.py
CHANGED
@@ -185,15 +185,27 @@ class ProofPile2(datasets.GeneratorBasedBuilder):
|
|
185 |
(datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST)
|
186 |
)
|
187 |
]
|
188 |
-
|
189 |
def _generate_examples(self, data_files):
|
190 |
-
key = 0
|
191 |
-
for name in data_files:
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
if
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
(datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST)
|
186 |
)
|
187 |
]
|
|
|
188 |
def _generate_examples(self, data_files):
|
189 |
+
key = 0
|
190 |
+
for name in data_files:
|
191 |
+
try:
|
192 |
+
with zstd.open(open(name, "rb"), "rt", encoding="utf-8") as f:
|
193 |
+
for x in f.readlines():
|
194 |
+
instance = json.loads(x)
|
195 |
+
if instance:
|
196 |
+
if "meta" not in instance:
|
197 |
+
instance["meta"] = dict()
|
198 |
+
yield key, {"text": instance["text"], "meta": json.dumps(instance["meta"])}
|
199 |
+
key += 1
|
200 |
+
# it seems already extracted...
|
201 |
+
except:
|
202 |
+
with open(name, "r", encoding="utf-8") as f:
|
203 |
+
for x in f.readlines():
|
204 |
+
instance = json.loads(x)
|
205 |
+
if instance:
|
206 |
+
if "meta" not in instance:
|
207 |
+
instance["meta"] = dict()
|
208 |
+
yield key, {"text": instance["text"], "meta": json.dumps(instance["meta"])}
|
209 |
+
key += 1
|
210 |
+
|
211 |
+
|