|
|
import json |
|
|
from tqdm import tqdm |
|
|
import random |
|
|
import os |
|
|
|
|
|
|
|
|
import json |
|
|
import os |
|
|
import random |
|
|
from tqdm import tqdm |
|
|
|
|
|
|
|
|
random.seed(0) |
|
|
|
|
|
def save_to_json(data, filename): |
|
|
"""保存数据到 JSON 文件""" |
|
|
with open(filename, 'w', encoding='utf-8') as f: |
|
|
json.dump(data, f, ensure_ascii=False, indent=4) |
|
|
print(f"Saved to {filename}, data length: {len(data)}") |
|
|
|
|
|
def load_json(file_path): |
|
|
"""从 JSON 文件加载数据""" |
|
|
with open(file_path, "r", encoding="utf-8") as f: |
|
|
data = json.load(f) |
|
|
print(f"Loaded from {file_path}, data length: {len(data)}") |
|
|
return data |
|
|
|
|
|
def save_questions_to_txt(data, output_txt_file): |
|
|
"""将数据中的 Question 字段保存到 TXT 文件""" |
|
|
with open(output_txt_file, 'w', encoding='utf-8') as f: |
|
|
for item in data: |
|
|
question = item.get("Question", "") |
|
|
if question: |
|
|
f.write(f"idx: {item['idx']}\n") |
|
|
f.write(f"question: {item['Question']}\n\n") |
|
|
print(f"Questions saved to {output_txt_file}") |
|
|
|
|
|
|
|
|
input_file = "/opt/aps/workdir/sunshuang/deep_search/math_data/math_qwq_4524.json" |
|
|
|
|
|
|
|
|
|
|
|
data = load_json(input_file) |
|
|
|
|
|
selected_data = random.sample(data, 871) |
|
|
|
|
|
save_to_json(selected_data, "/opt/aps/workdir/sunshuang/deep_search/math_data/math_qwq_4524_selected_871.json") |
|
|
|
|
|
|
|
|
|