OzoneAsai commited on
Commit
a329337
1 Parent(s): 5941c73

Upload gen.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. gen.py +39 -0
gen.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ def calculate_and_generate_dataset():
4
+ file_path = "generated_dataset.json"
5
+
6
+ with open(file_path, "w", encoding="utf-8") as json_file:
7
+ for n in range(-10001, 10001):
8
+ for m in range(-10001, 10001):
9
+ if m == 0: # 0での除算を防止
10
+ continue
11
+
12
+ # 掛け算
13
+ instruction_multiply = f"{n} * {m}"
14
+ output_multiply = n * m
15
+ json.dump({"instruction": instruction_multiply, "output": output_multiply}, json_file, ensure_ascii=False)
16
+ json_file.write("\n")
17
+
18
+ # 足し算
19
+ instruction_add = f"{n} + {m}"
20
+ output_add = n + m
21
+ json.dump({"instruction": instruction_add, "output": output_add}, json_file, ensure_ascii=False)
22
+ json_file.write("\n")
23
+
24
+ # 引き算
25
+ instruction_subtract = f"{n} - {m}"
26
+ output_subtract = n - m
27
+ json.dump({"instruction": instruction_subtract, "output": output_subtract}, json_file, ensure_ascii=False)
28
+ json_file.write("\n")
29
+
30
+ # 割り算
31
+ instruction_divide = f"{n} / {m}"
32
+ output_divide = n / m
33
+ json.dump({"instruction": instruction_divide, "output": output_divide}, json_file, ensure_ascii=False)
34
+ json_file.write("\n")
35
+
36
+ print("データセットがファイルに保存されました。ファイルパス:", file_path)
37
+
38
+ # データセットを生成
39
+ calculate_and_generate_dataset()