-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_sft_data_format.py
More file actions
56 lines (48 loc) · 1.94 KB
/
convert_sft_data_format.py
File metadata and controls
56 lines (48 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# convert tulu and lang_select datasets to sharegpt jsonl
import os
from datasets import load_dataset
import pandas as pd
import argparse
import jsonlines
from pathlib import Path
parser = argparse.ArgumentParser(description="convert tulu and lang_select datasets to sharegpt jsonl")
parser.add_argument("--dataset_type", default="tulu", help="tulu or lang_select")
parser.add_argument("--dataset_dir", default="data/tulu-3-sft-mixture", help="path to the original dataset")
parser.add_argument("--output_dir", default="data/tulu-3-sft-mixture/converted", help="where to put the converted dataset")
args = parser.parse_args()
dataset_dir = Path(args.dataset_dir)
output_dir = Path(args.output_dir)
os.makedirs(output_dir, exist_ok=True)
# load the original dataset
if args.dataset_type == "tulu":
ori_ds = load_dataset(args.dataset_dir, split="train")
print(f"loaded {len(ori_ds)} data samples from {args.dataset_dir}")
output_entries = []
# convert dataset
for item in ori_ds:
output_entries.append(
{
"id": item["id"],
"messages": item["messages"],
"source": item["source"]
}
)
elif args.dataset_type == "lang_select":
for subfolder in ["openr1-math"]:
ori_ds = pd.read_parquet(dataset_dir / subfolder / "train.parquet")
print(f"loaded {len(ori_ds)} data samples from {args.dataset_dir}/{subfolder}")
output_entries = []
for row in ori_ds.itertuples():
messages = [
{"role": "user", "content": row[3]},
{"role": "assistant", "content": row[4]}
]
output_entries.append(
{
"id": row[1],
"messages": messages
}
)
# write the entries
with jsonlines.open(os.path.join(args.output_dir, f"{subfolder}_train.jsonl"), "w") as writer:
writer.write_all(output_entries)