OpenTransformer commited on
Commit
6d600ca
·
verified ·
1 Parent(s): 3e05e1a

Add synthetic numeracy pretraining corpus

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. README.md +16 -0
  3. generate_math_numeracy.py +121 -0
  4. metadata.json +29 -0
  5. train.jsonl +3 -0
.gitattributes CHANGED
@@ -58,3 +58,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ train.jsonl filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - synthetic
5
+ - math
6
+ - numeracy
7
+ - pretraining
8
+ ---
9
+
10
+ # AGILLM Math Numeracy Synthetic
11
+
12
+ Synthetic plain-text numeracy corpus for AGILLM pretraining. Each JSONL row has `text` and `kind`.
13
+
14
+ Coverage includes addition/subtraction/multiplication/division facts, multi-digit arithmetic, comparisons, order/parity, place value, missing-number equations, simple word problems, fractions, money, and two-step arithmetic.
15
+
16
+ Generated deterministically with `generate_math_numeracy.py`.
generate_math_numeracy.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import json, random, hashlib, time
3
+ from pathlib import Path
4
+ OUT = Path('/workspace/agillm_math_numeracy_synth/train.jsonl')
5
+ META = Path('/workspace/agillm_math_numeracy_synth/metadata.json')
6
+ README = Path('/workspace/agillm_math_numeracy_synth/README.md')
7
+ N = 2_000_000
8
+ SEED = 731095
9
+ rng = random.Random(SEED)
10
+ objects = ['apples','coins','books','marbles','pencils','blocks','tokens','stickers']
11
+ names = ['Ada','Ben','Cara','Dion','Eli','Fay','Gus','Hana']
12
+ counts = {}
13
+
14
+ def jwrite(f, text, kind):
15
+ counts[kind] = counts.get(kind, 0) + 1
16
+ f.write(json.dumps({'text': text.strip() + '\n', 'kind': kind}, ensure_ascii=True, separators=(',', ':')) + '\n')
17
+
18
+ def choose(xs): return xs[rng.randrange(len(xs))]
19
+
20
+ def gen_add(big=False):
21
+ m = 9999 if big else 100
22
+ a,b = rng.randint(0,m), rng.randint(0,m); c=a+b
23
+ return choose([f'{a} + {b} = {c}.', f'{a}+{b}={c}', f'Compute {a} + {b}. Answer: {c}.', f'What is {a} plus {b}? {c}.', f'The sum of {a} and {b} is {c}.']), 'multi_digit_addition' if big else 'addition'
24
+
25
+ def gen_sub():
26
+ b,c = rng.randint(0,1000), rng.randint(0,1000); a=b+c
27
+ return choose([f'{a} - {b} = {c}.', f'{a}-{b}={c}', f'Compute {a} minus {b}. Answer: {c}.', f'What is {a} - {b}? {c}.']), 'subtraction'
28
+
29
+ def gen_mul():
30
+ a,b = (rng.randint(0,20), rng.randint(0,20)) if rng.random()<0.75 else (rng.randint(0,99), rng.randint(0,12))
31
+ c=a*b
32
+ return choose([f'{a} * {b} = {c}.', f'{a} times {b} equals {c}.', f'Compute {a} x {b}. Answer: {c}.', f'The product of {a} and {b} is {c}.']), 'multiplication'
33
+
34
+ def gen_div():
35
+ b,c = rng.randint(1,20), rng.randint(0,100); a=b*c
36
+ return choose([f'{a} / {b} = {c}.', f'{a} divided by {b} equals {c}.', f'Compute {a} / {b}. Answer: {c}.']), 'exact_division'
37
+
38
+ def gen_compare():
39
+ a,b = rng.randint(-200,200), rng.randint(-200,200)
40
+ sym = '>' if a>b else '<' if a<b else '='
41
+ word = 'greater than' if a>b else 'less than' if a<b else 'equal to'
42
+ return choose([f'{a} {sym} {b}.', f'{a} is {word} {b}.', f'Compare {a} and {b}: {a} {sym} {b}.']), 'comparison'
43
+
44
+ def gen_order_parity():
45
+ n = rng.randint(-1000,1000)
46
+ if rng.random()<0.5:
47
+ return choose([f'The number after {n} is {n+1}.', f'The number before {n} is {n-1}.', f'{n-1}, {n}, {n+1}.']), 'number_order'
48
+ par = 'even' if n % 2 == 0 else 'odd'
49
+ return f'{n} is {par}.', 'parity'
50
+
51
+ def gen_place():
52
+ n = rng.randint(0,9999); ones=n%10; tens=(n//10)%10; hundreds=(n//100)%10; thousands=(n//1000)%10
53
+ return choose([f'In {n}, the ones digit is {ones}.', f'In {n}, the tens digit is {tens}.', f'In {n}, the hundreds digit is {hundreds}.', f'In {n}, the thousands digit is {thousands}.', f'{n} = {thousands} thousands + {hundreds} hundreds + {tens} tens + {ones} ones.']), 'place_value'
54
+
55
+ def gen_missing():
56
+ a = rng.randint(0,100); x = rng.randint(0,100); b = a+x
57
+ if rng.random()<0.5:
58
+ return f'Solve x + {a} = {b}. x = {x}. Check: {x} + {a} = {b}.', 'missing_number'
59
+ return f'Solve {b} - x = {a}. x = {x}. Check: {b} - {x} = {a}.', 'missing_number'
60
+
61
+ def gen_word():
62
+ name=choose(names); obj=choose(objects); a=rng.randint(0,30); b=rng.randint(0,30)
63
+ if rng.random()<0.55:
64
+ return f'{name} has {a} {obj} and gets {b} more {obj}. {name} has {a+b} {obj}.', 'word_addition'
65
+ if b>a: a,b=b,a
66
+ return f'{name} has {a} {obj} and gives away {b}. {name} has {a-b} {obj} left.', 'word_subtraction'
67
+
68
+ def gen_multistep():
69
+ a,b,c = rng.randint(0,50), rng.randint(0,50), rng.randint(0,50)
70
+ if rng.random()<0.5:
71
+ r=a+b-c
72
+ return f'{a} + {b} - {c} = {r}. First {a} + {b} = {a+b}; then {a+b} - {c} = {r}.', 'two_step'
73
+ r=a*b+c
74
+ return f'{a} * {b} + {c} = {r}. First {a} * {b} = {a*b}; then {a*b} + {c} = {r}.', 'two_step'
75
+
76
+ def gen_fraction():
77
+ d=rng.randint(2,12); n=rng.randint(1,d-1); k=rng.randint(2,10)
78
+ return f'{n}/{d} = {n*k}/{d*k}. Multiplying numerator and denominator by {k} makes an equivalent fraction.', 'fractions'
79
+
80
+ def gen_money():
81
+ cents=rng.randint(0,9999); dollars=cents//100; rem=cents%100
82
+ return f'{cents} cents = {dollars} dollars and {rem} cents.', 'money'
83
+
84
+ gens = [gen_add, lambda: gen_add(True), gen_sub, gen_mul, gen_div, gen_compare, gen_order_parity, gen_place, gen_missing, gen_word, gen_multistep, gen_fraction, gen_money]
85
+ weights = [0.18,0.07,0.14,0.14,0.08,0.08,0.08,0.06,0.07,0.07,0.05,0.04,0.04]
86
+
87
+ def weighted_gen():
88
+ total = sum(weights)
89
+ r=rng.random() * total; acc=0.0
90
+ for g,w in zip(gens,weights):
91
+ acc += w
92
+ if r <= acc: return g()
93
+ return gens[-1]()
94
+
95
+ start=time.time(); sha=hashlib.sha256(); rows=0
96
+ with OUT.open('w', encoding='utf-8') as f:
97
+ # Exhaustive core facts first, repeated in clean forms.
98
+ for a in range(0,101):
99
+ for b in range(0,101):
100
+ jwrite(f, f'{a} + {b} = {a+b}.', 'addition_table'); rows+=1
101
+ if a >= b:
102
+ jwrite(f, f'{a} - {b} = {a-b}.', 'subtraction_table'); rows+=1
103
+ for a in range(0,21):
104
+ for b in range(0,21):
105
+ jwrite(f, f'{a} * {b} = {a*b}.', 'multiplication_table'); rows+=1
106
+ if b != 0:
107
+ jwrite(f, f'{a*b} / {b} = {a}.', 'division_table'); rows+=1
108
+ while rows < N:
109
+ text, kind = weighted_gen()
110
+ jwrite(f, text, kind); rows += 1
111
+ if rows % 250000 == 0:
112
+ print(f'generated {rows:,}', flush=True)
113
+ # Hash after close.
114
+ with OUT.open('rb') as f:
115
+ for chunk in iter(lambda: f.read(1<<20), b''):
116
+ sha.update(chunk)
117
+ meta = {'name':'agillm-math-numeracy-synthetic','rows':rows,'seed':SEED,'sha256':sha.hexdigest(),'counts':counts,'created_unix':int(time.time()),'description':'Synthetic numeracy pretraining JSONL with exact arithmetic facts, comparisons, place value, word problems, and simple step-by-step arithmetic.'}
118
+ META.write_text(json.dumps(meta, indent=2, sort_keys=True) + '\n')
119
+ README.write_text('''---\nlicense: apache-2.0\ntags:\n- synthetic\n- math\n- numeracy\n- pretraining\n---\n\n# AGILLM Math Numeracy Synthetic\n\nSynthetic plain-text numeracy corpus for AGILLM pretraining. Each JSONL row has `text` and `kind`.\n\nCoverage includes addition/subtraction/multiplication/division facts, multi-digit arithmetic, comparisons, order/parity, place value, missing-number equations, simple word problems, fractions, money, and two-step arithmetic.\n\nGenerated deterministically with `generate_math_numeracy.py`.\n''')
120
+ print(json.dumps(meta, indent=2, sort_keys=True))
121
+ print(f'elapsed_sec={time.time()-start:.1f}')
metadata.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "counts": {
3
+ "addition": 324553,
4
+ "addition_table": 10201,
5
+ "comparison": 144775,
6
+ "division_table": 420,
7
+ "exact_division": 144311,
8
+ "fractions": 72327,
9
+ "missing_number": 126466,
10
+ "money": 71675,
11
+ "multi_digit_addition": 125494,
12
+ "multiplication": 253019,
13
+ "multiplication_table": 441,
14
+ "number_order": 72122,
15
+ "parity": 71839,
16
+ "place_value": 108699,
17
+ "subtraction": 251795,
18
+ "subtraction_table": 5151,
19
+ "two_step": 90161,
20
+ "word_addition": 69737,
21
+ "word_subtraction": 56814
22
+ },
23
+ "created_unix": 1780047216,
24
+ "description": "Synthetic numeracy pretraining JSONL with exact arithmetic facts, comparisons, place value, word problems, and simple step-by-step arithmetic.",
25
+ "name": "agillm-math-numeracy-synthetic",
26
+ "rows": 2000000,
27
+ "seed": 731095,
28
+ "sha256": "11e893285638c733c7068510f07011273ac856586f2aa1239a7d526533a24280"
29
+ }
train.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:11e893285638c733c7068510f07011273ac856586f2aa1239a7d526533a24280
3
+ size 132737866