mod loading script
Browse files- minipileoflaw.py +15 -15
minipileoflaw.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
|
4 |
import gzip
|
5 |
import json
|
|
|
6 |
|
7 |
import datasets
|
8 |
try:
|
@@ -90,23 +91,22 @@ class MiniPileOfLaw(datasets.GeneratorBasedBuilder):
|
|
90 |
),
|
91 |
]
|
92 |
|
|
|
93 |
def _generate_examples(self, filepaths):
|
94 |
-
"""This function returns the examples in the raw (text) form by iterating on all the files."""
|
95 |
id_ = 0
|
96 |
for filepath in filepaths:
|
97 |
logger.info("Generating examples from = %s", filepath)
|
98 |
try:
|
99 |
-
with
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
except:
|
112 |
-
print("Error reading file:", filepath)
|
|
|
3 |
|
4 |
import gzip
|
5 |
import json
|
6 |
+
import csv
|
7 |
|
8 |
import datasets
|
9 |
try:
|
|
|
91 |
),
|
92 |
]
|
93 |
|
94 |
+
|
95 |
def _generate_examples(self, filepaths):
|
96 |
+
"""This function returns the examples in the raw (text) form by iterating on all the CSV files."""
|
97 |
id_ = 0
|
98 |
for filepath in filepaths:
|
99 |
logger.info("Generating examples from = %s", filepath)
|
100 |
try:
|
101 |
+
with open(filepath, "r", encoding="utf-8") as file:
|
102 |
+
reader = csv.DictReader(file)
|
103 |
+
for row in reader:
|
104 |
+
yield id_, {
|
105 |
+
"text": row.get("text", ""),
|
106 |
+
"created_timestamp": row.get("created_timestamp", ""),
|
107 |
+
"downloaded_timestamp": row.get("downloaded_timestamp", ""),
|
108 |
+
"url": row.get("url", "")
|
109 |
+
}
|
110 |
+
id_ += 1
|
111 |
+
except Exception as e:
|
112 |
+
print(f"Error reading file: {filepath}, Error: {e}")
|
|
|
|