|
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: |
|
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() |
|
|