File size: 4,351 Bytes
d1ff550 238def2 d1ff550 238def2 d1ff550 d2de66b 00a0d8e d2de66b 2ad076a 984e202 2ad076a d2de66b 238def2 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
---
dataset_info:
features:
- name: instruction
dtype: string
- name: output
dtype: string
splits:
- name: train
num_bytes: 15268888.05
num_examples: 487500
- name: test
num_bytes: 391509.95
num_examples: 12500
download_size: 12160789
dataset_size: 15660398
configs:
- config_name: default
data_files:
- split: train
path: data/train-*
- split: test
path: data/test-*
tags:
- math
---
# Simple Math
Just like my teacher gave me homework, i thought maybe we can also add some of these basics on the trainings of our models.
It was created with this code, if you add more complex operations and so.. please share the code :D thank you
```py
import random
# Define the number of samples you want to generate
num_samples = 500000
# Define the range for the random numbers
min_value = -99.99
max_value = 99.99
# Define the arithmetic operations
operations = ['+', '-', '*', '/']
# Generate data
data = []
for _ in range(num_samples):
num1 = float("%.3f" % random.uniform(min_value, max_value))
num2 = float("%.3f" % random.uniform(min_value, max_value))
while num2 == 0.0:
num2 = float("%.3f" % random.uniform(min_value, max_value))
while num1 == 0.0:
num1 = float("%.3f" % random.uniform(min_value, max_value))
operation = random.choice(operations)
if operation == '/':
result = num1 / num2
elif operation == '-':
result = num1 - num2
elif operation == '*':
result = num1 * num2
elif operation == '+':
result = num1 + num2
output = "%.4f" % result
instruction = f"{num1} {operation} {num2}"
data.append({'instruction': instruction, 'output': output})
# Create the dataset
import json
out_file = 'arithmetic-float4a.json'
with open(out_file, 'w') as f:
json.dump(data, f)
```
We have also a new community submission for a more complex dataset of 3 elements:
```py
import random
import json
import operator
# Define the number of samples you want to generate
num_samples = 500000
# Define the range for the random numbers
min_value = -99.99
max_value = 99.99
# Define the arithmetic operations and their corresponding functions
operations = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv
}
def generate_random_number():
return float("%.3f" % random.uniform(min_value, max_value))
def safe_division(numerator, denominator):
return numerator if denominator == 0 else numerator / denominator
# Generate complex data
data = []
for _ in range(num_samples):
num1 = generate_random_number()
num2 = generate_random_number()
num3 = generate_random_number()
# Ensure num2 and num3 are not zero if they will be used as divisors
if num2 == 0.0:
num2 = generate_random_number()
if num3 == 0.0:
num3 = generate_random_number()
# Randomly choose two operations
operation1 = random.choice(list(operations.keys()))
operation2 = random.choice(list(operations.keys()))
# Create a more complex expression
if random.choice([True, False]):
# With parentheses
expression = f"({num1} {operation1} {num2}) {operation2} {num3}"
if operation1 == '/':
intermediate_result = safe_division(num1, num2)
else:
intermediate_result = operations[operation1](num1, num2)
if operation2 == '/' and intermediate_result != 0:
result = safe_division(intermediate_result, num3)
else:
result = operations[operation2](intermediate_result, num3)
else:
# Without parentheses
expression = f"{num1} {operation1} {num2} {operation2} {num3}"
if operation1 == '/':
intermediate_result = safe_division(num1, num2)
else:
intermediate_result = operations[operation1](num1, num2)
if operation2 == '/':
result = safe_division(intermediate_result, num3)
else:
result = operations[operation2](intermediate_result, num3)
output = "%.4f" % result
data.append({'instruction': expression, 'output': output})
# Create the dataset
out_file = 'arithmetic-float-complex.json'
with open(out_file, 'w') as f:
json.dump(data, f)
```
If you use Simple Math o train your model, please cite on the modelcard or the paper.
Thank you |