ogx786 commited on
Commit
ae5b09f
·
verified ·
1 Parent(s): ddd99c2

Update data_extraction.py

Browse files
Files changed (1) hide show
  1. data_extraction.py +5 -3
data_extraction.py CHANGED
@@ -271,14 +271,16 @@ def train_val_split(examples, val_fraction, seed):
271
  def write_jsonl(path, rows):
272
  with open(path, "w", encoding="utf-8") as fh:
273
  for row in rows:
274
- fh.write(json.dumps(row, ensure_ascii=False) + "\n")
 
275
 
276
 
277
  def write_csv(path, pairs):
278
  with open(path, "w", newline="", encoding="utf-8") as fh:
279
- writer = csv.DictWriter(fh, fieldnames=["field", "urdu", "roman"])
280
  writer.writeheader()
281
- writer.writerows(pairs)
 
282
 
283
 
284
  # --------------------------------------------------------------------------
 
271
  def write_jsonl(path, rows):
272
  with open(path, "w", encoding="utf-8") as fh:
273
  for row in rows:
274
+ output_row = {k: v for k, v in row.items() if k != "field"}
275
+ fh.write(json.dumps(output_row, ensure_ascii=False) + "\n")
276
 
277
 
278
  def write_csv(path, pairs):
279
  with open(path, "w", newline="", encoding="utf-8") as fh:
280
+ writer = csv.DictWriter(fh, fieldnames=["urdu", "roman"])
281
  writer.writeheader()
282
+ for p in pairs:
283
+ writer.writerow({"urdu": p["urdu"], "roman": p["roman"]})
284
 
285
 
286
  # --------------------------------------------------------------------------