RAGEN / scripts /nothink_dataset.py
Harryis's picture
Add files using upload-large-folder tool
70a7f67 verified
Raw
History Blame Contribute Delete
2.81 kB
import json
# with open("/mnt/general/wanghy/RAGEN/runs/Game2048NoisyDQN__noisy_dqn_2048_refined__1__1765041200/sft/step_300000_sft_singleturn_slidewindows5_7000score.json") as f:
# dataset1 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/BanditDQN__dqn_bandit_nochangeenv__1__1764233298/sft/step_50000_sft.json") as f:
dataset2 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/RubiksCube2x2__ppo_rubikscube1_1218/sft/step_999424_sft_singleturn.json") as f:
dataset3 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/RubiksCube2x2__ppo_rubikscube2_1219_turn5/sft/step_999424_sft_singleturn.json") as f:
dataset4 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/RubiksCube2x2__ppo_rubikscube3_1219_turn5_6000/sft/step_999424_sft_singleturn.json") as f:
dataset5 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/FrozenLake__ppo_frozenlake_nochangeenv__p0.9_slippery/sft/step_1986560_sft_slippery_singleturn.json") as f:
dataset6 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/SokobanNoisyDQN__noisy_dqn_sokoban__1__1764155447/sft/step_1000000_sft_singleturn.json") as f:
dataset7 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/SokobanNoisyDQN__noisy_dqn_sokoban__1__1764155464/sft/step_1000000_sft_singleturn.json") as f:
dataset8 = json.load(f)
with open("/mnt/general/wanghy/RAGEN/runs/Sudoku__ppo_sudoku_actionmask__4x4/sft/step_999424_sft_singleturn_nohint.json") as f:
dataset9 = json.load(f)
data = dataset2 +dataset3 +dataset4 +dataset5 +dataset6 +dataset7 +dataset8 +dataset9
target_user_str = " <think> [Your thoughts] </think>"
target_assistant_str1 = "<think></think>"
target_assistant_str2 = "<think> </think>"
# 2. 遍历数据并进行替换
# 假设 data 是一个列表,列表里每个元素都有 "messages" 字段
if isinstance(data, list):
for entry in data:
if "messages" in entry:
for msg in entry["messages"]:
role = msg.get("role")
content = msg.get("content", "")
# 处理 User
if role == "user":
if target_user_str in content:
msg["content"] = content.replace(target_user_str, "")
# 处理 Assistant
elif role == "assistant":
if (target_assistant_str1 in content) or (target_assistant_str2 in content):
msg["content"] = content.replace(target_assistant_str1, "").replace(target_assistant_str2, "")
import pdb;pdb.set_trace()
# 3. 将修改后的数据保存为新文件
with open("/mnt/general/wanghy/RAGEN/runs/multitask_nothink/sft_no2048.json", 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)