Commit
·
523bcc3
1
Parent(s):
7553784
script to normalize scrolls data
Browse files
normalize_raw_data/normalize_scrolls.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import shutil
|
3 |
+
from fire import Fire
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
|
7 |
+
def normalize_example(example):
|
8 |
+
return {"source": example["input"],
|
9 |
+
"target": example["output"],
|
10 |
+
"id": example["id"],
|
11 |
+
"pid": example["pid"]}
|
12 |
+
|
13 |
+
|
14 |
+
def main(dataset_name, num_proc=5):
|
15 |
+
dataset = load_dataset("tau/scrolls", dataset_name)
|
16 |
+
dataset = dataset.map(normalize_example, num_proc=num_proc)
|
17 |
+
dir_name = f"../data/{dataset_name}"
|
18 |
+
os.makedirs(dir_name, exist_ok=True)
|
19 |
+
for split in dataset:
|
20 |
+
dataset[split].to_json(os.path.join(dir_name, f"{split}.jsonl"))
|
21 |
+
shutil.make_archive(dir_name, 'zip', dir_name)
|
22 |
+
|
23 |
+
|
24 |
+
if __name__ == '__main__':
|
25 |
+
Fire(main)
|