Dan Fu
commited on
Commit
•
7cfef3d
1
Parent(s):
71d5916
Better error logging
Browse files- RedPajama-Data-1T.py +40 -17
RedPajama-Data-1T.py
CHANGED
@@ -19,7 +19,7 @@
|
|
19 |
import json
|
20 |
|
21 |
import datasets
|
22 |
-
|
23 |
|
24 |
logger = datasets.logging.get_logger(__name__)
|
25 |
|
@@ -112,23 +112,46 @@ class RedPajama1T(datasets.GeneratorBasedBuilder):
|
|
112 |
for path in files[subset]:
|
113 |
with zstd.open(open(path, "rb"), "rt", encoding="utf-8") as f:
|
114 |
for i, row in enumerate(f):
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
else:
|
125 |
for path in files[subset]:
|
126 |
with open(path, encoding="utf-8") as f:
|
127 |
for i, row in enumerate(f):
|
128 |
-
|
129 |
-
|
130 |
-
"
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
import json
|
20 |
|
21 |
import datasets
|
22 |
+
import traceback
|
23 |
|
24 |
logger = datasets.logging.get_logger(__name__)
|
25 |
|
|
|
112 |
for path in files[subset]:
|
113 |
with zstd.open(open(path, "rb"), "rt", encoding="utf-8") as f:
|
114 |
for i, row in enumerate(f):
|
115 |
+
try:
|
116 |
+
data = json.loads(row)
|
117 |
+
text = data["text"]
|
118 |
+
del data["text"]
|
119 |
+
yield key, {
|
120 |
+
"text": text,
|
121 |
+
"meta": json.dumps(data),
|
122 |
+
"red_pajama_subset": subset,
|
123 |
+
}
|
124 |
+
key += 1
|
125 |
+
except Exception as e:
|
126 |
+
print(f'Subset: {subset}')
|
127 |
+
print(f'Path: {path}')
|
128 |
+
print(f'Row: {row}')
|
129 |
+
traceback.print_exc()
|
130 |
+
|
131 |
+
raise e
|
132 |
else:
|
133 |
for path in files[subset]:
|
134 |
with open(path, encoding="utf-8") as f:
|
135 |
for i, row in enumerate(f):
|
136 |
+
try:
|
137 |
+
data = json.loads(row)
|
138 |
+
if "meta" not in data:
|
139 |
+
text = data["text"]
|
140 |
+
del data["text"]
|
141 |
+
yield key, {
|
142 |
+
"text": text,
|
143 |
+
"meta": json.dumps(data),
|
144 |
+
}
|
145 |
+
else:
|
146 |
+
yield key, {
|
147 |
+
"text": data["text"],
|
148 |
+
"meta": data["meta"],
|
149 |
+
}
|
150 |
+
key += 1
|
151 |
+
except Exception as e:
|
152 |
+
print(f'Subset: {subset}')
|
153 |
+
print(f'Path: {path}')
|
154 |
+
print(f'Row: {row}')
|
155 |
+
traceback.print_exc()
|
156 |
+
|
157 |
+
raise e
|