tomrb commited on
Commit
5952276
·
1 Parent(s): fad1577
Files changed (1) hide show
  1. minipileoflaw.py +12 -13
minipileoflaw.py CHANGED
@@ -99,17 +99,16 @@ class MiniPileOfLaw(datasets.GeneratorBasedBuilder):
99
  for filepath in filepaths:
100
  logger.info("Generating examples from = %s", filepath)
101
  try:
102
- with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
103
- for line in f:
104
- if line:
105
- example = json.loads(line)
106
- if example is not None and isinstance(example, dict):
107
- yield id_, {
108
- "text": example.get("text", ""),
109
- "created_timestamp": example.get("created_timestamp", ""),
110
- "downloaded_timestamp": example.get("downloaded_timestamp", ""),
111
- "url": example.get("url", "")
112
- }
113
- id_ += 1
114
  except:
115
- print("Error reading file:", filepath)
 
99
  for filepath in filepaths:
100
  logger.info("Generating examples from = %s", filepath)
101
  try:
102
+ with open(filepath, "r", encoding="utf-8") as f:
103
+ data = json.load(f) # Load the entire JSON file
104
+ for example in data: # Iterate over items if the file contains a list of dictionaries
105
+ if example is not None and isinstance(example, dict):
106
+ yield id_, {
107
+ "text": example.get("text", ""),
108
+ "created_timestamp": example.get("created_timestamp", ""),
109
+ "downloaded_timestamp": example.get("downloaded_timestamp", ""),
110
+ "url": example.get("url", "")
111
+ }
112
+ id_ += 1
 
113
  except:
114
+ print("Error reading file:", filepath)