Add better logging error when JSON loads fails
Browse files- hplt_monolingual_v1_2.py +12 -2
hplt_monolingual_v1_2.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
"""Data loading script for HPLT Monolingual Release v1.2."""
|
| 2 |
|
| 3 |
import json
|
|
|
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
from typing import List
|
| 6 |
|
|
@@ -183,8 +185,16 @@ class Hplt_monolingual_v1_2(datasets.GeneratorBasedBuilder):
|
|
| 183 |
|
| 184 |
for pfin in pfs_data:
|
| 185 |
with pfin.open(encoding="utf-8") as fhin:
|
| 186 |
-
for line in fhin:
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
yield document_idx, {
|
| 189 |
"id": document_idx,
|
| 190 |
"document_lang": data["document_lang"],
|
|
|
|
| 1 |
"""Data loading script for HPLT Monolingual Release v1.2."""
|
| 2 |
|
| 3 |
import json
|
| 4 |
+
import logging
|
| 5 |
+
from json import JSONDecodeError
|
| 6 |
from pathlib import Path
|
| 7 |
from typing import List
|
| 8 |
|
|
|
|
| 185 |
|
| 186 |
for pfin in pfs_data:
|
| 187 |
with pfin.open(encoding="utf-8") as fhin:
|
| 188 |
+
for line_idx, line in enumerate(fhin, 1):
|
| 189 |
+
line = line.strip()
|
| 190 |
+
if not line:
|
| 191 |
+
continue
|
| 192 |
+
try:
|
| 193 |
+
data = json.loads(line)
|
| 194 |
+
except JSONDecodeError as exc:
|
| 195 |
+
logging.error(f"Error parsing JSON! Line will be skipped...\n- file {pfin}\n- line no. {line_idx:,}\n- line: {line}\n- error: {exc}")
|
| 196 |
+
continue
|
| 197 |
+
|
| 198 |
yield document_idx, {
|
| 199 |
"id": document_idx,
|
| 200 |
"document_lang": data["document_lang"],
|