File size: 1,588 Bytes
a329337
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()