import json def calculate_and_generate_dataset(): file_path = "generated_dataset.json" with open(file_path, "w", encoding="utf-8") as json_file: for n in range(-10001, 10001): for m in range(-10001, 10001): if m == 0: # 0での除算を防止 continue # 掛け算 instruction_multiply = f"{n} * {m}" output_multiply = n * m json.dump({"instruction": instruction_multiply, "output": output_multiply}, json_file, ensure_ascii=False) json_file.write("\n") # 足し算 instruction_add = f"{n} + {m}" output_add = n + m json.dump({"instruction": instruction_add, "output": output_add}, json_file, ensure_ascii=False) json_file.write("\n") # 引き算 instruction_subtract = f"{n} - {m}" output_subtract = n - m json.dump({"instruction": instruction_subtract, "output": output_subtract}, json_file, ensure_ascii=False) json_file.write("\n") # 割り算 instruction_divide = f"{n} / {m}" output_divide = n / m json.dump({"instruction": instruction_divide, "output": output_divide}, json_file, ensure_ascii=False) json_file.write("\n") print("データセットがファイルに保存されました。ファイルパス:", file_path) # データセットを生成 calculate_and_generate_dataset()