A more complex script generated by gpt4-turbo

#2
LOLO.png DELETED

Git LFS Details

  • SHA256: 0b519bc0a8725a044d9e5b13c4c5a18d77a3148250e531265eccdb769b3c1fad
  • Pointer size: 132 Bytes
  • Size of remote file: 1.73 MB
README.md CHANGED
@@ -1,37 +1,19 @@
1
  ---
2
  dataset_info:
3
  features:
4
- - name: output
5
- dtype: string
6
  - name: instruction
7
  dtype: string
 
 
8
  splits:
9
- - name: arithmetic.float2_train
10
- num_bytes: 645500.3
11
- num_examples: 19000
12
- - name: arithmetic.float2_valid
13
- num_bytes: 33973.7
14
- num_examples: 1000
15
- - name: arithmetic.float3_train
16
- num_bytes: 1890863.85
17
- num_examples: 47500
18
- - name: arithmetic.float3_valid
19
- num_bytes: 99519.15
20
- num_examples: 2500
21
- - name: arithmetic.float34_train
22
- num_bytes: 9321513.05
23
- num_examples: 218500
24
- - name: arithmetic.float34_valid
25
- num_bytes: 490605.95
26
- num_examples: 11500
27
- - name: arithmetic.float4_train
28
- num_bytes: 21671996.6
29
- num_examples: 475000
30
- - name: arithmetic.float4_valid
31
- num_bytes: 1140631.4
32
- num_examples: 25000
33
- download_size: 27928049
34
- dataset_size: 35294604
35
  configs:
36
  - config_name: default
37
  data_files:
@@ -39,104 +21,49 @@ configs:
39
  path: data/train-*
40
  - split: test
41
  path: data/test-*
42
- tags:
43
- - math
44
- - finance
45
- license: cc-by-nc-nd-4.0
46
- task_categories:
47
- - text-generation
48
- - question-answering
49
- pretty_name: Simple Math
50
- size_categories:
51
- - 100K<n<1M
52
  ---
53
 
54
- # Simple Math: 2+2=4 -1=3 (LoLo: Learning Only Logical Operations)
55
 
56
  Just like my teacher gave me homework, i thought maybe we can also add some of these basics on the trainings of our models.
57
 
58
- It was created with very simple code that is in the repo, if you add more complex operations and so.. **please share the code** :D thank you
59
-
60
- Current Code Version: 20240127.fblgit (A modification over @win10 for progressive and DPO operation)
61
- ![LoLo: Learning Only Logical Operations](https://huggingface.co/datasets/fblgit/simple-math/resolve/main/LOLO.png)
62
- ## Does it Works?
63
- ### 34BEAGLES Evaluation:
64
- ```
65
- hf (pretrained=/data/models/UNA-34Beagles-v1-final,dtype=bfloat16,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: auto (8)
66
- | Tasks |Version|Filter|n-shot| Metric |Value | |Stderr|
67
- |--------------|-------|------|-----:|--------|-----:|---|-----:|
68
- |arc_challenge |Yaml |none | 25|acc |0.7039|± |0.0133|
69
- | | |none | 25|acc_norm|0.7321|± |0.0129|
70
- |truthfulqa_mc2|Yaml |none | 0|acc |0.7387|± |0.0141|
71
-
72
- hf (pretrained=/data/models/UNA-34Beagles-v1-final,dtype=bfloat16,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: auto
73
- |Tasks|Version| Filter |n-shot| Metric |Value | |Stderr|
74
- |-----|-------|----------|-----:|-----------|-----:|---|-----:|
75
- |gsm8k|Yaml |get-answer| 5|exact_match|0.6399|± |0.0132|
76
-
77
- | Groups |Version|Filter|n-shot|Metric|Value | |Stderr|
78
- |------------------|-------|------|-----:|------|-----:|---|-----:|
79
- |mmlu |N/A |none | 0|acc |0.7477|± |0.1079|
80
- | - humanities |N/A |none | 0|acc |0.7188|± |0.0855|
81
- | - other |N/A |none | 0|acc |0.7950|± |0.1057|
82
- | - social_sciences|N/A |none | 0|acc |0.8297|± |0.0664|
83
- | - stem |N/A |none | 0|acc |0.6641|± |0.1291|
84
- ```
85
-
86
- ### 34BEAGLES-MATH Evaluation
 
 
 
 
 
 
 
87
  ```
88
- hf (pretrained=/data/models/34BeaglesMath-v1,dtype=bfloat16,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: auto
89
- |Tasks|Version| Filter |n-shot| Metric |Value | |Stderr|
90
- |-----|-------|----------|-----:|-----------|-----:|---|-----:|
91
- |gsm8k|Yaml |get-answer| 5|exact_match|0.6505|± |0.0131|
92
-
93
- hf (pretrained=/data/models/34BeaglesMath-v1,dtype=bfloat16,trust_remote_code=True), gen_kwargs: (None), limit: None, num_fewshot: None, batch_size: auto (8)
94
- | Tasks |Version|Filter|n-shot| Metric |Value | |Stderr|
95
- |--------------|-------|------|-----:|--------|-----:|---|-----:|
96
- |arc_challenge |Yaml |none | 25|acc |0.7090|± |0.0133|
97
- | | |none | 25|acc_norm|0.7329|± |0.0129|
98
- |truthfulqa_mc2|Yaml |none | 0|acc |0.7378|± |0.0141|
99
 
100
- | Groups |Version|Filter|n-shot|Metric|Value | |Stderr|
101
- |------------------|-------|------|-----:|------|-----:|---|-----:|
102
- |mmlu |N/A |none | 0|acc |0.7524|± |0.1045|
103
- | - humanities |N/A |none | 0|acc |0.7307|± |0.0846|
104
- | - other |N/A |none | 0|acc |0.7937|± |0.1029|
105
- | - social_sciences|N/A |none | 0|acc |0.8274|± |0.0667|
106
- | - stem |N/A |none | 0|acc |0.6708|± |0.1236|
107
- ```
108
-
109
- But it gets better, because when increasing length and complexity, the marks are even superior:
110
- ```
111
- |Tasks|Version| Filter |n-shot| Metric |Value | |Stderr|
112
- |-----|-------|----------|-----:|-----------|-----:|---|-----:|
113
- |gsm8k|Yaml |get-answer| 5|exact_match|0.6611|± | 0.013|
114
- ```
115
- On a 3.20% GSM Improvement compared to its base model.
116
-
117
- ## Note to contributors:
118
- **thank you to those contributing on the experiment with beautiful commits and good spirit**
119
-
120
- * Feel free to contribute on the readme Evaluation tests.
121
- * Lets aim to build an ablation & paper together. All contributors will be cited.
122
-
123
- ## Versions
124
- ```
125
- 27.01.24 Added new code to generate the dataset, seed 42 and now also generates DPO.
126
- 24.01.24 Added gradual complexity on a separate script
127
- 20-23.01.24 Multiple contributions with operations and increased complexity on the main generator script.
128
- ```
129
-
130
- ## Citations
131
  If you use Simple Math o train your model, please cite on the modelcard or the paper.
132
-
133
- ```
134
- @misc{simplemath,
135
- title={Simple-Math: 2+2=4 4-1=3},
136
- author={Xavier Murias},
137
- year={2024},
138
- publisher = {Juanako.AI},
139
- journal = {HuggingFace repository},
140
- howpublished = {\url{https://huggingface.co/datasets/fblgit/simple-math}},
141
- }
142
- ```
 
1
  ---
2
  dataset_info:
3
  features:
 
 
4
  - name: instruction
5
  dtype: string
6
+ - name: output
7
+ dtype: string
8
  splits:
9
+ - name: train
10
+ num_bytes: 15268888.05
11
+ num_examples: 487500
12
+ - name: test
13
+ num_bytes: 391509.95
14
+ num_examples: 12500
15
+ download_size: 12160789
16
+ dataset_size: 15660398.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  configs:
18
  - config_name: default
19
  data_files:
 
21
  path: data/train-*
22
  - split: test
23
  path: data/test-*
 
 
 
 
 
 
 
 
 
 
24
  ---
25
 
26
+ # Simple Math
27
 
28
  Just like my teacher gave me homework, i thought maybe we can also add some of these basics on the trainings of our models.
29
 
30
+ It was created with this code, if you add more complex operations and so.. please share the code :D thank you
31
+ ```py
32
+ import random
33
+ # Define the number of samples you want to generate
34
+ num_samples = 500000
35
+ # Define the range for the random numbers
36
+ min_value = -99.99
37
+ max_value = 99.99
38
+ # Define the arithmetic operations
39
+ operations = ['+', '-', '*', '/']
40
+ # Generate data
41
+ data = []
42
+ for _ in range(num_samples):
43
+ num1 = float("%.3f" % random.uniform(min_value, max_value))
44
+ num2 = float("%.3f" % random.uniform(min_value, max_value))
45
+ while num2 == 0.0:
46
+ num2 = float("%.3f" % random.uniform(min_value, max_value))
47
+ while num1 == 0.0:
48
+ num1 = float("%.3f" % random.uniform(min_value, max_value))
49
+ operation = random.choice(operations)
50
+ if operation == '/':
51
+ result = num1 / num2
52
+ elif operation == '-':
53
+ result = num1 - num2
54
+ elif operation == '*':
55
+ result = num1 * num2
56
+ elif operation == '+':
57
+ result = num1 + num2
58
+ output = "%.4f" % result
59
+ instruction = f"{num1} {operation} {num2}"
60
+ data.append({'instruction': instruction, 'output': output})
61
+ # Create the dataset
62
+ import json
63
+ out_file = 'arithmetic-float4a.json'
64
+ with open(out_file, 'w') as f:
65
+ json.dump(data, f)
66
  ```
 
 
 
 
 
 
 
 
 
 
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  If you use Simple Math o train your model, please cite on the modelcard or the paper.
69
+ Thank you
 
 
 
 
 
 
 
 
 
 
data/arithmetic.float2_train-00000-of-00001-76d20691102f37a0.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ac883ac351f437ca03f3a0dbbc1c1f3f2d659354f2a06248ff87cdbc29c9843a
3
- size 436655
 
 
 
 
data/arithmetic.float2_valid-00000-of-00001-4da290d9dd516e56.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:e0cb741de82b162d98f9fd6b013aae7e31421dd416ea4060db3eebf51b2d7e24
3
- size 23926
 
 
 
 
data/arithmetic.float34_train-00000-of-00001-675d1a6d12dd2773.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:47f74ed658777edd68f302c8ac0ba4eabe16b9522b37d934ff897491a4c0788a
3
- size 7229970
 
 
 
 
data/arithmetic.float34_valid-00000-of-00001-6361402bfe44060c.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:e21f7c213473e4988429f826bfbd8c546d7acaf28c6f494e808bdc5f46676bbf
3
- size 381872
 
 
 
 
data/arithmetic.float3_train-00000-of-00001-e20ff809970b0270.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:055dfc6aa0896895e5b644b338e9a32757c8e1dc4bbcbd54cff5800057520f5c
3
- size 1383635
 
 
 
 
data/arithmetic.float3_valid-00000-of-00001-69ca851e549f4b06.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:b285631b13c0ac2d921c1eceda32538e4210b5c25b47c0a87e86a706f109800e
3
- size 74022
 
 
 
 
data/arithmetic.float4_train-00000-of-00001-e6ab9284e13e1f0c.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:d7157baa3a95e306ca4b192f366ad7d47430f5c5638fbaaf8feeada2f4859650
3
- size 17476607
 
 
 
 
data/arithmetic.float4_valid-00000-of-00001-badf2cf4b2557733.parquet DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:0361ad345ba73a9dfbc40eceb4f0626ce3ef59fc65bb23442a11f62e2214e482
3
- size 921362
 
 
 
 
mathrandom-progressive.py DELETED
@@ -1,157 +0,0 @@
1
- import random
2
- import json
3
- import operator
4
- import math
5
-
6
- num_samples = [20000, 50000, 230000, 500000]
7
- min_values = [-9.99, -19.99, -99.99, -99.99]
8
- max_values = [9.99, 19.99, 99.99, 99.99]
9
- vals_floats = ["%.2f", "%.3f", "%.3f", "%.4f"]
10
- result_floats = ["%.2f", "%.3f", "%.4f", "%.4f"]
11
- seed = 42
12
-
13
- random.seed(seed)
14
-
15
- # Binary operations
16
- binary_operations = {
17
- '+': operator.add,
18
- '-': operator.sub,
19
- '*': operator.mul,
20
- '/': operator.truediv,
21
- #'**': operator.pow, # it makes tons of troubles, but if u wanna contribute with a functional fix (L)
22
- '%': operator.mod
23
- }
24
-
25
- # Safe division to avoid division by zero
26
- def safe_division(numerator, denominator):
27
- return numerator if denominator == 0 else numerator / denominator
28
-
29
- # Unary operations
30
- def safe_sqrt(x):
31
- return math.sqrt(x) if x >= 0 else 0
32
-
33
- def safe_log(x):
34
- return math.log(x) if x > 0 else 0
35
-
36
- unary_operations = {
37
- 'sqrt': safe_sqrt,
38
- 'sin': math.sin,
39
- 'cos': math.cos,
40
- 'log': safe_log
41
- }
42
-
43
- def format_result(result, format_spec):
44
- if isinstance(result, complex):
45
- real_part = format_spec % result.real
46
- imag_part = format_spec % result.imag
47
- return f"{real_part} + {imag_part}j"
48
- else:
49
- return format_spec % result
50
-
51
- def safe_modulo(numerator, denominator):
52
- return 0 if denominator == 0 else numerator % denominator
53
-
54
- def safe_power(base, exponent):
55
- if base == 0 and exponent < 0:
56
- return 0 # or some other value that signifies an undefined operation
57
- else:
58
- return base ** exponent
59
-
60
- def generate_sub_expression(min_value, max_value, val_float):
61
- num1 = float(val_float % random.uniform(min_value, max_value))
62
- num2 = float(val_float % random.uniform(min_value, max_value))
63
- operation = random.choice(list(binary_operations.keys()))
64
-
65
- if operation == '/':
66
- result = safe_division(num1, num2)
67
- elif operation == '%':
68
- result = safe_modulo(num1, num2)
69
- else:
70
- result = binary_operations[operation](num1, num2)
71
-
72
- expression = f"({num1} {operation} {num2})"
73
- return expression, result
74
-
75
- def generate_expression(num_samples, min_value, max_value, val_float, result_float):
76
- data = []
77
- for _ in range(num_samples):
78
- sub_ops_count = random.randint(0, 2) # Number of sub-operations (0, 1, or 2), the code is not tailored for more cases, but feel free to improve it.
79
- sub_expressions = [generate_sub_expression(min_value, max_value, val_float) for _ in range(sub_ops_count)]
80
-
81
- # Main operation
82
- main_num1 = float(val_float % random.uniform(min_value, max_value))
83
- main_num2 = float(val_float % random.uniform(min_value, max_value))
84
- main_operation = random.choice(list(binary_operations.keys()))
85
-
86
- # Embed sub-expressions into main expression
87
- if sub_expressions:
88
- if len(sub_expressions) == 1:
89
- sub_expr, sub_result = sub_expressions[0]
90
- if random.choice([True, False]):
91
- main_expression = f"{sub_expr} {main_operation} {main_num2}"
92
- if main_operation == '/':
93
- main_result = safe_division(sub_result, main_num2)
94
- elif main_operation == '%':
95
- main_result = safe_modulo(sub_result, main_num2)
96
- else:
97
- main_result = binary_operations[main_operation](sub_result, main_num2)
98
- else:
99
- main_expression = f"{main_num1} {main_operation} {sub_expr}"
100
- if main_operation == '/':
101
- main_result = safe_division(main_num1, sub_result)
102
- elif main_operation == '%':
103
- main_result = safe_modulo(main_num1, sub_result)
104
- else:
105
- main_result = binary_operations[main_operation](main_num1, sub_result)
106
- else:
107
- sub_expr1, sub_result1 = sub_expressions[0]
108
- sub_expr2, sub_result2 = sub_expressions[1]
109
- main_expression = f"{sub_expr1} {main_operation} {sub_expr2}"
110
- if main_operation == '/':
111
- main_result = safe_division(sub_result1, sub_result2)
112
- elif main_operation == '%':
113
- main_result = safe_modulo(sub_result1, sub_result2)
114
- else:
115
- main_result = binary_operations[main_operation](sub_result1, sub_result2)
116
- else:
117
- main_expression = f"{main_num1} {main_operation} {main_num2}"
118
- if main_operation == '/':
119
- main_result = safe_division(main_num1, main_num2)
120
- elif main_operation == '%':
121
- main_result = safe_modulo(main_num1, main_num2)
122
- else:
123
- main_result = binary_operations[main_operation](main_num1, main_num2)
124
-
125
- output = format_result(main_result, result_float)
126
- data.append({'instruction': main_expression, 'output': output})
127
-
128
- return data
129
-
130
-
131
- # DPO (Follows Ultrabinarized Format)
132
- def make_prompt(expression, output):
133
- prompt = {
134
- 'prompt': 'What is the result of the following expression?',
135
- 'chosen': [],
136
- 'rejected': [],
137
- 'messages': []
138
- }
139
- prompt['chosen'].append({'content': prompt['prompt'] + '\n' + expression, 'role': 'user'})
140
- prompt['chosen'].append({'content': output, 'role': 'assistant'})
141
- prompt['rejected'].append({'content': prompt['prompt'] + '\n' + expression, 'role': 'user'})
142
- prompt['rejected'].append({'content': output[0:2], 'role': 'assistant'})
143
- prompt['messages'].append({'content': prompt['prompt'] + '\n' + expression, 'role': 'user'})
144
- prompt['messages'].append({'content': output, 'role': 'assistant'})
145
- return prompt
146
-
147
-
148
- # Generate and write data for each set of parameters
149
- for idx, sample_count in enumerate(num_samples):
150
- data = generate_expression(sample_count, min_values[idx], max_values[idx], vals_floats[idx], result_floats[idx])
151
- dpo_data = [make_prompt(elem['instruction'], elem['output']) for elem in data]
152
- out_file = f'arithmetic-float-complex_{idx}.json'
153
- with open(out_file, 'w') as f:
154
- json.dump(data, f)
155
- out_file = f'arithmetic-float-complex_DPO_{idx}.json'
156
- with open(out_file, 'w') as f:
157
- json.dump(dpo_data, f)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
mathrandom2.py DELETED
@@ -1,70 +0,0 @@
1
- import random
2
- import json
3
- import operator
4
-
5
- # Define the number of samples you want to generate
6
- num_samples = 500000
7
- # Define the range for the random numbers
8
- min_value = -99.99
9
- max_value = 99.99
10
- # Define the arithmetic operations and their corresponding functions
11
- operations = {
12
- '+': operator.add,
13
- '-': operator.sub,
14
- '*': operator.mul,
15
- '/': operator.truediv
16
- }
17
-
18
- def generate_random_number():
19
- return float("%.3f" % random.uniform(min_value, max_value))
20
-
21
- def safe_division(numerator, denominator):
22
- return numerator if denominator == 0 else numerator / denominator
23
-
24
- # Generate complex data
25
- data = []
26
- for _ in range(num_samples):
27
- num1 = generate_random_number()
28
- num2 = generate_random_number()
29
- num3 = generate_random_number()
30
- # Ensure num2 and num3 are not zero if they will be used as divisors
31
- if num2 == 0.0:
32
- num2 = generate_random_number()
33
- if num3 == 0.0:
34
- num3 = generate_random_number()
35
-
36
- # Randomly choose two operations
37
- operation1 = random.choice(list(operations.keys()))
38
- operation2 = random.choice(list(operations.keys()))
39
-
40
- # Create a more complex expression
41
- if random.choice([True, False]):
42
- # With parentheses
43
- expression = f"({num1} {operation1} {num2}) {operation2} {num3}"
44
- if operation1 == '/':
45
- intermediate_result = safe_division(num1, num2)
46
- else:
47
- intermediate_result = operations[operation1](num1, num2)
48
- if operation2 == '/' and intermediate_result != 0:
49
- result = safe_division(intermediate_result, num3)
50
- else:
51
- result = operations[operation2](intermediate_result, num3)
52
- else:
53
- # Without parentheses
54
- expression = f"{num1} {operation1} {num2} {operation2} {num3}"
55
- if operation1 == '/':
56
- intermediate_result = safe_division(num1, num2)
57
- else:
58
- intermediate_result = operations[operation1](num1, num2)
59
- if operation2 == '/':
60
- result = safe_division(intermediate_result, num3)
61
- else:
62
- result = operations[operation2](intermediate_result, num3)
63
-
64
- output = "%.4f" % result
65
- data.append({'instruction': expression, 'output': output})
66
-
67
- # Create the dataset
68
- out_file = 'arithmetic-float-complex.json'
69
- with open(out_file, 'w') as f:
70
- json.dump(data, f)