ahmedheakl commited on
Commit
acafc25
·
verified ·
1 Parent(s): 23ababd

Create down_openr1.py

Browse files
Files changed (1) hide show
  1. down_openr1.py +63 -0
down_openr1.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from tqdm import tqdm
3
+ from datasets import load_dataset
4
+ import os
5
+
6
+ ds_id = "lmms-lab/multimodal-open-r1-8k-verified"
7
+ out_root = "LLaMA-Factory/data"
8
+ dataset_name = "open_r1_v2"
9
+ ds = load_dataset(ds_id, split="train")
10
+ SYSTEM_PROMPT = (
11
+ "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. The assistant "
12
+ "first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning "
13
+ "process and answer are enclosed within <think> </think> and <answer> </answer> tags, respectively, i.e., "
14
+ "<think> reasoning process here </think><answer> answer here </answer>"
15
+ )
16
+ data = []
17
+ os.makedirs(f"{out_root}/{dataset_name}", exist_ok=True)
18
+ for idx, d in tqdm(enumerate(ds), total=len(ds)):
19
+ base_image_path = f"{dataset_name}/{idx}.png"
20
+ image_path = f"{out_root}/{base_image_path}"
21
+ image = d['image']
22
+ image.save(image_path)
23
+ conversations = [
24
+ {
25
+ "role": "user",
26
+ "content": "<image>\n" + d['problem']
27
+ },
28
+ {
29
+ "role": "assistant",
30
+ "content": d['solution']
31
+ }
32
+ ]
33
+ data.append({
34
+ "conversations": conversations,
35
+ "images": [base_image_path],
36
+ "system": SYSTEM_PROMPT
37
+ })
38
+
39
+ output_path = f"{out_root}/{dataset_name}.json"
40
+ with open(output_path, "w") as f:
41
+ json.dump(data, f, indent=4, ensure_ascii=False)
42
+
43
+ with open(f"{out_root}/dataset_info.json", "r") as f:
44
+ dataset_info = json.load(f)
45
+
46
+ dataset_info[dataset_name] = {
47
+ "file_name": f"{dataset_name}.json",
48
+ "formatting": "sharegpt",
49
+ "columns": {
50
+ "messages": "conversations",
51
+ "images": "images",
52
+ "system": "system"
53
+ },
54
+ "tags": {
55
+ "role_tag": "role",
56
+ "content_tag": "content",
57
+ "user_tag": "user",
58
+ "assistant_tag": "assistant"
59
+ }
60
+ }
61
+
62
+ with open(f"{out_root}/dataset_info.json", "w") as f:
63
+ json.dump(dataset_info, f, indent=4, ensure_ascii=False)