Datasets:
Initial release
Browse files- README.md +84 -0
- code/short_arith.py +143 -0
- code/worked_arith.py +276 -0
- croguana-500.png +3 -0
- data/short-train.parquet +3 -0
- data/worked-test.parquet +3 -0
- data/worked-train.parquet +3 -0
README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- hr
|
| 4 |
+
- en
|
| 5 |
+
license: cc-by-4.0
|
| 6 |
+
pretty_name: Croatian arithmetic with worked steps
|
| 7 |
+
size_categories:
|
| 8 |
+
- 100K<n<1M
|
| 9 |
+
task_categories:
|
| 10 |
+
- text-generation
|
| 11 |
+
tags:
|
| 12 |
+
- croatian
|
| 13 |
+
- math
|
| 14 |
+
- arithmetic
|
| 15 |
+
- reasoning
|
| 16 |
+
- synthetic
|
| 17 |
+
configs:
|
| 18 |
+
- config_name: worked
|
| 19 |
+
data_files:
|
| 20 |
+
- split: train
|
| 21 |
+
path: data/worked-train.parquet
|
| 22 |
+
- split: test
|
| 23 |
+
path: data/worked-test.parquet
|
| 24 |
+
- config_name: short
|
| 25 |
+
data_files:
|
| 26 |
+
- split: train
|
| 27 |
+
path: data/short-train.parquet
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
<div align="center">
|
| 31 |
+
<img src="croguana-500.png" width="360">
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
# hr-arithmetic — hrvatska aritmetika s postupkom
|
| 35 |
+
|
| 36 |
+
Dio zbirke hrvatskih skupova podataka projekta CroGuana / part of the CroGuana Croatian data collection: [hr-arithmetic](https://huggingface.co/datasets/Shome/hr-arithmetic) · [hr-wiki-instruct](https://huggingface.co/datasets/Shome/hr-wiki-instruct) · [hr-bible](https://huggingface.co/datasets/Shome/hr-bible) · [hr-ner-chat](https://huggingface.co/datasets/Shome/hr-ner-chat) · [hy4-croatian-synthetic-v1](https://huggingface.co/datasets/Shome/hy4-croatian-synthetic-v1)
|
| 37 |
+
|
| 38 |
+
## Hrvatski
|
| 39 |
+
|
| 40 |
+
Generirani aritmetički zadaci na hrvatskom (i dijelom engleskom) u obliku razgovora. **Svaki rezultat izračunao je i
|
| 41 |
+
provjerio Python**, bez jezičnog modela. Skup je nastao jer naši raniji hrvatski modeli nisu znali pouzdano zbrajati
|
| 42 |
+
(npr. 33 + 7 = 39): tokenizator ionako dijeli brojeve na znamenke, pa modelu nedostaje *postupak*.
|
| 43 |
+
|
| 44 |
+
| Konfiguracija | Podjela | Redaka | Što |
|
| 45 |
+
|---|---|---:|---|
|
| 46 |
+
| `worked` | train | 40,000 | zbrajanje i oduzimanje po stupcima (prijenos, posudba), množenje, dijeljenje s ostatkom, redoslijed operacija, novac s decimalnim zarezom, postoci, tekstualni zadaci |
|
| 47 |
+
| `worked` | test | 600 | izdvojeni zadaci (drugo sjeme; nijedan par operanada iz testa nije u treningu) |
|
| 48 |
+
| `short` | train | 60,000 | kratki tekstualni zadaci (zbrajanje, oduzimanje, množenje, dijeljenje, ostatak, novac, vrijeme) |
|
| 49 |
+
|
| 50 |
+
**Oblik odgovora (`worked`):** 50 % `<think>` s koracima pa rezultat, 30 % koraci i provjera obrnutom operacijom
|
| 51 |
+
(„Provjera: 40 − 7 = 33”), 20 % samo rezultat. Primjer koraka: „3 + 7 = 10, pišem 0, prenosim 1”.
|
| 52 |
+
**`short`:** 40 % `<think>račun</think>` + broj, 40 % račun + rečenica, 20 % samo broj. Oko 70 % zadataka je na
|
| 53 |
+
hrvatskom, 30 % na engleskom (stupac `language`).
|
| 54 |
+
|
| 55 |
+
**Hrvatska gramatika:** tekstualni zadaci koriste ručno napisanu tablicu imenica sa sročnošću broja i padeža
|
| 56 |
+
(1 jabuka, 2 jabuke, 5 jabuka; „U 4 kutije ima 256 olovaka”) i smislene spremnike (nema stolica u vrećicama).
|
| 57 |
+
|
| 58 |
+
**Provjere:** konačni rezultati ponovno su izračunati; za sve zadatke zbrajanja, oduzimanja i množenja jednoznamenkastim
|
| 59 |
+
brojem znamenke iz koraka („pišem …”) složene su natrag i uspoređene s rezultatom (10 799 redaka, 0 pogrešaka).
|
| 60 |
+
Nijedan redak ne dijeli niz od 10 riječi s evaluacijskim skupovima koje koristimo (SuperGLUE-hr, SLE, GSM8K-hr, IFEval-hr, Hy4 dev/test).
|
| 61 |
+
|
| 62 |
+
**Kod:** `code/worked_arith.py` (konfiguracija `worked`) i `code/short_arith.py` (tablica imenica, konfiguracija
|
| 63 |
+
`short`) potpuno reproduciraju skup.
|
| 64 |
+
|
| 65 |
+
## English
|
| 66 |
+
|
| 67 |
+
Generated arithmetic problems in Croatian (about 30% English) as user/assistant chats. **Every result is computed and
|
| 68 |
+
checked by Python**, no language model involved. Built because our earlier Croatian models could not add reliably
|
| 69 |
+
(33 + 7 → 39): the tokenizer already splits digits, so what the model lacks is the procedure.
|
| 70 |
+
|
| 71 |
+
- `worked` (40,000 train / 600 held-out test): column addition with carries, subtraction
|
| 72 |
+
with borrows, multiplication by partial products, long division with remainder, order of operations, decimal-comma
|
| 73 |
+
money, percentages and word problems; answers as `<think>` steps + result (50%), steps + inverse-operation check (30%),
|
| 74 |
+
or the result only (20%). The test split uses a different seed and shares no operand pair with training.
|
| 75 |
+
- `short` (60,000 train): short word problems with three answer styles.
|
| 76 |
+
- Croatian word problems use a hand-written noun table for number/case agreement.
|
| 77 |
+
- Checks: results recomputed; for all +, − and single-digit × rows the digits written in the steps were reassembled and
|
| 78 |
+
compared with the result (10,799 rows, 0 errors). No row shares a 10-word window with the evaluation sets we use (SuperGLUE-hr, SLE, GSM8K-hr, IFEval-hr, Hy4 dev/test).
|
| 79 |
+
|
| 80 |
+
## Licenca / License
|
| 81 |
+
|
| 82 |
+
CC BY 4.0. Sve je naš rad (generator i podaci). / Entirely our own work (generator and data).
|
| 83 |
+
|
| 84 |
+
Zahtjeve za ispravak ili uklanjanje pošaljite kroz karticu **Community** ovog repozitorija. / Requests for corrections or removal: please use the **Community** tab of this repository.
|
code/short_arith.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Croatian/English arithmetic word problems (short answers) and the Croatian noun table with number
|
| 2 |
+
agreement used by both generators. Extracted from the MiniMind mid-training builder."""
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
NAMES = [('Ana', 'ž'), ('Marko', 'm'), ('Iva', 'ž'), ('Luka', 'm'), ('Petra', 'ž'), ('Ivan', 'm'), ('Maja', 'ž'), ('Josip', 'm'),
|
| 6 |
+
('Lucija', 'ž'), ('Filip', 'm'), ('Ema', 'ž'), ('Karlo', 'm'), ('Nika', 'ž'), ('Davor', 'm'), ('Tena', 'ž'), ('Ante', 'm')]
|
| 7 |
+
EN_NAMES = ['Anna', 'Mark', 'Eva', 'Luke', 'Sara', 'John', 'Mia', 'Paul', 'Lucy', 'Philip', 'Emma', 'Carl']
|
| 8 |
+
NOUN_TABLE = """
|
| 9 |
+
jabuka ž jabuka jabuke jabuku jabuci jabuke jabuka jabuke
|
| 10 |
+
knjiga ž knjiga knjige knjigu knjizi knjige knjiga knjige
|
| 11 |
+
olovka ž olovka olovke olovku olovci olovke olovaka olovke
|
| 12 |
+
bilježnica ž bilježnica bilježnice bilježnicu bilježnici bilježnice bilježnica bilježnice
|
| 13 |
+
kruška ž kruška kruške krušku kruški kruške krušaka kruške
|
| 14 |
+
naranča ž naranča naranče naranču naranči naranče naranča naranče
|
| 15 |
+
boca ž boca boce bocu boci boce boca boce
|
| 16 |
+
čaša ž čaša čaše čašu čaši čaše čaša čaše
|
| 17 |
+
žlica ž žlica žlice žlicu žlici žlice žlica žlice
|
| 18 |
+
karta ž karta karte kartu karti karte karata karte
|
| 19 |
+
lopta ž lopta lopte loptu lopti lopte lopti lopte
|
| 20 |
+
kocka ž kocka kocke kocku kocki kocke kocaka kocke
|
| 21 |
+
stolica ž stolica stolice stolicu stolici stolice stolica stolice
|
| 22 |
+
bombon m bombon bombona bombon bombonu bomboni bombona bombone
|
| 23 |
+
kolač m kolač kolača kolač kolaču kolači kolača kolače
|
| 24 |
+
cvijet m cvijet cvijeta cvijet cvijetu cvjetovi cvjetova cvjetove
|
| 25 |
+
tanjur m tanjur tanjura tanjur tanjuru tanjuri tanjura tanjure
|
| 26 |
+
ključ m ključ ključa ključ ključu ključevi ključeva ključeve
|
| 27 |
+
balon m balon balona balon balonu baloni balona balone
|
| 28 |
+
kamen m kamen kamena kamen kamenu kamenovi kamenova kamenove
|
| 29 |
+
sapun m sapun sapuna sapun sapunu sapuni sapuna sapune
|
| 30 |
+
jaje s jaje jajeta jaje jajetu jaja jaja jaja
|
| 31 |
+
pismo s pismo pisma pismo pismu pisma pisama pisma
|
| 32 |
+
kutija ž kutija kutije kutiju kutiji kutije kutija kutije
|
| 33 |
+
vrećica ž vrećica vrećice vrećicu vrećici vrećice vrećica vrećice
|
| 34 |
+
košara ž košara košare košaru košari košare košara košare
|
| 35 |
+
ladica ž ladica ladice ladicu ladici ladice ladica ladice
|
| 36 |
+
posuda ž posuda posude posudu posudi posude posuda posude
|
| 37 |
+
"""
|
| 38 |
+
NOUNS = {}
|
| 39 |
+
for _l in NOUN_TABLE.strip().splitlines():
|
| 40 |
+
_w, _rod, *_f = _l.split()
|
| 41 |
+
NOUNS[_w] = dict(zip(('N', 'G', 'A', 'L', 'Nmn', 'Gmn', 'Amn'), _f), rod=_rod)
|
| 42 |
+
CONT = ['kutija', 'vrećica', 'košara', 'ladica', 'posuda']
|
| 43 |
+
FITS = { # object -> sensible containers (no chairs in bags)
|
| 44 |
+
**{w: ['košara', 'kutija', 'vrećica', 'posuda'] for w in ('jabuka', 'kruška', 'naranča', 'kolač', 'bombon', 'jaje')},
|
| 45 |
+
**{w: ['kutija', 'ladica', 'vrećica'] for w in ('olovka', 'bilježnica', 'karta', 'kocka', 'ključ', 'sapun', 'pismo', 'žlica', 'balon')},
|
| 46 |
+
**{w: ['kutija', 'ladica'] for w in ('knjiga', 'čaša', 'tanjur', 'boca')},
|
| 47 |
+
}
|
| 48 |
+
OBJ = list(FITS)
|
| 49 |
+
PRICE = (1, 9)
|
| 50 |
+
EN_OBJ = ['apples', 'books', 'pencils', 'notebooks', 'pears', 'bottles', 'cups', 'cards', 'balls', 'chairs', 'candies', 'cakes',
|
| 51 |
+
'flowers', 'plates', 'keys', 'balloons', 'stones', 'eggs', 'letters']
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def agree(n, f, case='N'):
|
| 55 |
+
"""Form of a noun after the number n (digits). case 'N' subject, 'A' object."""
|
| 56 |
+
rod = f['rod']
|
| 57 |
+
if n % 10 == 1 and n % 100 != 11:
|
| 58 |
+
return f['A'] if case == 'A' else f['N']
|
| 59 |
+
if n % 10 in (2, 3, 4) and n % 100 not in (12, 13, 14):
|
| 60 |
+
return f['Nmn'] if rod == 'ž' else f['G']
|
| 61 |
+
return f['Gmn']
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def eur(n):
|
| 65 |
+
return 'euro' if n % 10 == 1 and n % 100 != 11 else 'eura'
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def verb(g, m, z):
|
| 69 |
+
return z if g == 'ž' else m
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def hr_problem(rng, nouns):
|
| 73 |
+
name, g = rng.choice(NAMES)
|
| 74 |
+
ow = rng.choice(OBJ)
|
| 75 |
+
o, c = nouns[ow], nouns[rng.choice(FITS[ow])]
|
| 76 |
+
t = rng.randrange(7)
|
| 77 |
+
if t == 0:
|
| 78 |
+
a, b = rng.randint(2, 60), rng.randint(2, 40)
|
| 79 |
+
q = f'{name} ima {a} {agree(a, o)}. {verb(g, "Dobio", "Dobila")} je još {b} {agree(b, o, "A")}. Koliko {o["Gmn"]} {name} sada ima?'
|
| 80 |
+
return q, f'{a} + {b} = {a + b}', a + b, f'{name} sada ima {a + b} {agree(a + b, o, "A")}.'
|
| 81 |
+
if t == 1:
|
| 82 |
+
a = rng.randint(10, 90); b = rng.randint(1, a - 1)
|
| 83 |
+
q = f'U {c["L"]} ima {a} {agree(a, o, "A")}. {name} je {verb(g, "uzeo", "uzela")} {b} {agree(b, o, "A")}. Koliko {o["Gmn"]} sada ima u {c["L"]}?'
|
| 84 |
+
return q, f'{a} - {b} = {a - b}', a - b, f'U {c["L"]} sada ima {a - b} {agree(a - b, o, "A")}.'
|
| 85 |
+
if t == 2:
|
| 86 |
+
a, b = rng.randint(2, 12), rng.randint(2, 12)
|
| 87 |
+
q = f'U svakoj {c["L"]} ima {a} {agree(a, o, "A")}. Koliko {o["Gmn"]} ima u {b} {agree(b, c)}?'
|
| 88 |
+
return q, f'{b} * {a} = {a * b}', a * b, f'U {b} {agree(b, c)} ima {a * b} {agree(a * b, o, "A")}.'
|
| 89 |
+
if t == 3:
|
| 90 |
+
k, b = rng.randint(2, 9), rng.randint(2, 12)
|
| 91 |
+
a = k * b
|
| 92 |
+
q = f'{name} ima {a} {agree(a, o)} i {verb(g, "želi", "želi")} ih jednako rasporediti u {b} {agree(b, c, "A")}. Koliko će {o["Gmn"]} biti u svakoj {c["L"]}?'
|
| 93 |
+
return q, f'{a} / {b} = {k}', k, f'U svakoj {c["L"]} bit će {k} {agree(k, o)}.'
|
| 94 |
+
if t == 4:
|
| 95 |
+
k = rng.randint(3, 8); a = rng.randint(k + 1, 70); full, rest = divmod(a, k)
|
| 96 |
+
q = f'{name} pakira {a} {agree(a, o, "A")} u {c["Amn"]}, po {k} u svaku. Koliko punih {c["Gmn"]} dobije i koliki je višak?'
|
| 97 |
+
return q, f'{a} = {full} * {k} + {rest}', f'{full}, višak {rest}', \
|
| 98 |
+
f'{name} napuni {full} {agree(full, c, "A")}, a višak je {rest}.' if rest else f'{name} napuni {full} {agree(full, c, "A")}, bez viška.'
|
| 99 |
+
if t == 5:
|
| 100 |
+
p = rng.randint(*PRICE); n = rng.randint(2, 9); pay = (p * n // 10 + 1) * 10
|
| 101 |
+
q = f'{o["N"].capitalize()} stoji {p} {eur(p)}. {name} kupuje {n} {agree(n, o, "A")} i daje {pay} {eur(pay)}. Koliko eura dobiva natrag?'
|
| 102 |
+
return q, f'{n} * {p} = {n * p}; {pay} - {n * p} = {pay - n * p}', pay - n * p, f'{name} dobiva natrag {pay - n * p} {eur(pay - n * p)}.'
|
| 103 |
+
h, mi = rng.randint(7, 18), rng.choice([0, 10, 15, 20, 30, 40, 45, 50]); d = rng.choice([25, 35, 40, 45, 50, 70, 75, 90, 105, 120])
|
| 104 |
+
e = h * 60 + mi + d
|
| 105 |
+
q = f'Sastanak počinje u {h}:{mi:02d} i traje {d} minuta. U koliko sati završava?'
|
| 106 |
+
return q, f'{h}:{mi:02d} + {d} min = {e // 60}:{e % 60:02d}', f'{e // 60}:{e % 60:02d}', f'Sastanak završava u {e // 60}:{e % 60:02d}.'
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def en_problem(rng):
|
| 110 |
+
n, o = rng.choice(EN_NAMES), rng.choice(EN_OBJ)
|
| 111 |
+
t = rng.randrange(5)
|
| 112 |
+
if t == 0:
|
| 113 |
+
a, b = rng.randint(2, 60), rng.randint(2, 40)
|
| 114 |
+
return f'{n} has {a} {o} and gets {b} more. How many {o} does {n} have now?', f'{a} + {b} = {a + b}', a + b, f'{n} now has {a + b} {o}.'
|
| 115 |
+
if t == 1:
|
| 116 |
+
a = rng.randint(10, 90); b = rng.randint(1, a - 1)
|
| 117 |
+
return f'There are {a} {o} in a box. {n} takes out {b}. How many are left?', f'{a} - {b} = {a - b}', a - b, f'{a - b} {o} are left.'
|
| 118 |
+
if t == 2:
|
| 119 |
+
a, b = rng.randint(2, 12), rng.randint(2, 12)
|
| 120 |
+
return f'Each bag holds {a} {o}. How many {o} are in {b} bags?', f'{b} * {a} = {a * b}', a * b, f'There are {a * b} {o} in {b} bags.'
|
| 121 |
+
if t == 3:
|
| 122 |
+
k = rng.randint(3, 8); a = rng.randint(k + 1, 70); full, rest = divmod(a, k)
|
| 123 |
+
return (f'{n} packs {a} {o} into boxes of {k}. How many full boxes are there, and how many {o} are left over?',
|
| 124 |
+
f'{a} = {full} * {k} + {rest}', f'{full}, remainder {rest}', f'There {"is" if full == 1 else "are"} {full} full box{"" if full == 1 else "es"} and {rest} left over.')
|
| 125 |
+
p = rng.randint(2, 30); m = rng.randint(2, 9); pay = (p * m // 10 + 1) * 10
|
| 126 |
+
return (f'One item costs {p} euros. {n} buys {m} and pays with {pay} euros. How much change does {n} get?',
|
| 127 |
+
f'{m} * {p} = {m * p}; {pay} - {m * p} = {pay - m * p}', pay - m * p, f'{n} gets {pay - m * p} euros back.')
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def arith(rng, entries, count):
|
| 131 |
+
nouns = NOUNS
|
| 132 |
+
rows = []
|
| 133 |
+
for i in range(count):
|
| 134 |
+
q, calc, ans, prose = en_problem(rng) if rng.random() < 0.3 else hr_problem(rng, nouns)
|
| 135 |
+
style = rng.random()
|
| 136 |
+
if style < 0.4:
|
| 137 |
+
a = f'<think>{calc}</think>\n{ans}'
|
| 138 |
+
elif style < 0.8:
|
| 139 |
+
a = f'{calc}. {prose}'
|
| 140 |
+
else:
|
| 141 |
+
a = str(ans)
|
| 142 |
+
rows.append(dict(id=f'arith:{i}', messages=[dict(role='user', content=q), dict(role='assistant', content=a)]))
|
| 143 |
+
return rows, sorted(nouns)
|
code/worked_arith.py
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Arithmetic data for YugoGPT Croatian v1: every answer computed and checked by Python.
|
| 2 |
+
|
| 3 |
+
Targets the 2024 CroGuana weakness (33 + 7 -> 39): the Mistral tokenizer already splits digits, so rows teach the
|
| 4 |
+
procedure. Column addition with carries, subtraction with borrows, multiplication by partial products, long division
|
| 5 |
+
with remainder, order of operations, percentages, decimal-comma money, time; word problems (Croatian with case agreement
|
| 6 |
+
from the MiniMind noun table, and English). Answer styles: <think> steps + answer, answer only, answer + inverse check.
|
| 7 |
+
|
| 8 |
+
python arith.py -> arith-train.jsonl (SFT), arith-probe.jsonl (held-out probes, separate seed, never in training)
|
| 9 |
+
"""
|
| 10 |
+
import json
|
| 11 |
+
import random
|
| 12 |
+
import sys
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
HERE = Path(__file__).resolve().parent
|
| 16 |
+
from short_arith import NAMES, NOUNS, FITS, OBJ, EN_NAMES, agree, eur, verb
|
| 17 |
+
|
| 18 |
+
DIG = {'hr': ('pišem', 'prenosim', 'posuđujem'), 'en': ('write', 'carry', 'borrow')}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def operands(rng, kind):
|
| 22 |
+
"""Operand pairs biased towards carries/borrows and edge cases."""
|
| 23 |
+
r = rng.random()
|
| 24 |
+
if r < 0.12: # edge cases
|
| 25 |
+
e = rng.choice([(10 ** rng.randint(1, 4) - 1, rng.randint(1, 9)), (10 ** rng.randint(2, 4), rng.randint(1, 9)),
|
| 26 |
+
(rng.randint(1, 9) * 10 + rng.randint(1, 9), 10 - rng.randint(1, 9))])
|
| 27 |
+
return e
|
| 28 |
+
da, db = rng.choice([(1, 1), (2, 1), (2, 1), (2, 2), (2, 2), (3, 2), (3, 3), (4, 3), (4, 4), (5, 4)])
|
| 29 |
+
a, b = rng.randint(10 ** (da - 1), 10 ** da - 1), rng.randint(10 ** (db - 1), 10 ** db - 1)
|
| 30 |
+
if r < 0.45 and kind in '+-': # force a units carry/borrow
|
| 31 |
+
if kind == '+':
|
| 32 |
+
b = b - b % 10 + max(b % 10, 10 - a % 10) if (a % 10 + b % 10) < 10 and a % 10 else b
|
| 33 |
+
elif a % 10 >= b % 10 and b % 10 < 9:
|
| 34 |
+
b = b - b % 10 + rng.randint(a % 10 + 1, 9) if a % 10 < 9 else b
|
| 35 |
+
return a, b
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def col_add(a, b, L):
|
| 39 |
+
w, c = DIG[L][0], DIG[L][1]
|
| 40 |
+
xs, ys, carry, out, steps = str(a)[::-1], str(b)[::-1], 0, [], []
|
| 41 |
+
for i in range(max(len(xs), len(ys))):
|
| 42 |
+
x, y = int(xs[i]) if i < len(xs) else 0, int(ys[i]) if i < len(ys) else 0
|
| 43 |
+
s = x + y + carry
|
| 44 |
+
expr = f'{x} + {y}' + (f' + {carry}' if carry else '')
|
| 45 |
+
out.append(s % 10)
|
| 46 |
+
steps.append(f'{expr} = {s}, {w} {s % 10}' + (f', {c} {s // 10}' if s >= 10 else ''))
|
| 47 |
+
carry = s // 10
|
| 48 |
+
if carry:
|
| 49 |
+
steps.append(f'{w} {carry}' if L == 'en' else f'{w} {carry} ispred')
|
| 50 |
+
return steps
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def col_sub(a, b, L):
|
| 54 |
+
w, br = DIG[L][0], DIG[L][2]
|
| 55 |
+
xs, ys, borrow, steps = str(a)[::-1], str(b)[::-1], 0, []
|
| 56 |
+
lent = 'posuđeno' if L == 'hr' else 'borrowed'
|
| 57 |
+
for i in range(len(xs)):
|
| 58 |
+
x0, y = int(xs[i]), int(ys[i]) if i < len(ys) else 0
|
| 59 |
+
x = x0 - borrow
|
| 60 |
+
pre = f'{x0} - 1 ({lent}) = {x}; ' if borrow else ''
|
| 61 |
+
if x < y:
|
| 62 |
+
steps.append(f'{pre}{x} < {y}, {br} 1: {x + 10} - {y} = {x + 10 - y}, {w} {x + 10 - y}')
|
| 63 |
+
borrow = 1
|
| 64 |
+
else:
|
| 65 |
+
steps.append(f'{pre}{x} - {y} = {x - y}, {w} {x - y}')
|
| 66 |
+
borrow = 0
|
| 67 |
+
return steps
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def col_mul(a, b, L):
|
| 71 |
+
w, c = DIG[L][0], DIG[L][1]
|
| 72 |
+
if b < 10:
|
| 73 |
+
steps, carry = [], 0
|
| 74 |
+
for d in str(a)[::-1]:
|
| 75 |
+
p = int(d) * b + carry
|
| 76 |
+
steps.append(f'{d} × {b}' + (f' + {carry}' if carry else '') + f' = {p}, {w} {p % 10}' + (f', {c} {p // 10}' if p >= 10 else ''))
|
| 77 |
+
carry = p // 10
|
| 78 |
+
if carry:
|
| 79 |
+
steps.append(f'{w} {carry}' if L == 'en' else f'{w} {carry} ispred')
|
| 80 |
+
return steps
|
| 81 |
+
parts = [(int(d) * 10 ** i) for i, d in enumerate(str(b)[::-1]) if d != '0']
|
| 82 |
+
lines = [f'{b} = ' + ' + '.join(map(str, parts[::-1]))] + [f'{a} × {p} = {a * p}' for p in parts[::-1]]
|
| 83 |
+
lines.append(' + '.join(str(a * p) for p in parts[::-1]) + f' = {a * b}')
|
| 84 |
+
return lines
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def long_div(a, b, L):
|
| 88 |
+
steps, rest = [], 0
|
| 89 |
+
for d in str(a):
|
| 90 |
+
cur = rest * 10 + int(d)
|
| 91 |
+
q, rest = divmod(cur, b)
|
| 92 |
+
if cur >= b or steps:
|
| 93 |
+
steps.append(f'{cur} : {b} = {q}' + (f', ostatak {rest}' if L == 'hr' else f', remainder {rest}'))
|
| 94 |
+
return steps or [f'{a} : {b} = 0, ' + ('ostatak' if L == 'hr' else 'remainder') + f' {a}']
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
Q = {
|
| 98 |
+
'hr': {'+': ['Koliko je {a} + {b}?', '{a} + {b} =', 'Izračunaj {a} + {b}.', 'Zbroji {a} i {b}.', 'Koliko je {a} plus {b}?'],
|
| 99 |
+
'-': ['Koliko je {a} - {b}?', '{a} - {b} =', 'Izračunaj {a} - {b}.', 'Oduzmi {b} od {a}.', 'Koliko je {a} minus {b}?'],
|
| 100 |
+
'*': ['Koliko je {a} × {b}?', '{a} * {b} =', 'Izračunaj {a} puta {b}.', 'Pomnoži {a} i {b}.'],
|
| 101 |
+
'/': ['Koliko je {a} : {b}?', 'Podijeli {a} s {b}.', 'Izračunaj {a} / {b} (s ostatkom ako ga ima).']},
|
| 102 |
+
'en': {'+': ['What is {a} + {b}?', '{a} + {b} =', 'Add {a} and {b}.', 'Calculate {a} plus {b}.'],
|
| 103 |
+
'-': ['What is {a} - {b}?', '{a} - {b} =', 'Subtract {b} from {a}.'],
|
| 104 |
+
'*': ['What is {a} × {b}?', '{a} * {b} =', 'Multiply {a} by {b}.'],
|
| 105 |
+
'/': ['What is {a} ÷ {b}?', 'Divide {a} by {b}.']},
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def bare(rng, L):
|
| 110 |
+
op = rng.choice('++--*/')
|
| 111 |
+
a, b = operands(rng, op)
|
| 112 |
+
if op == '-' and a < b:
|
| 113 |
+
a, b = b, a
|
| 114 |
+
if op == '*':
|
| 115 |
+
a, b = rng.randint(2, 999), rng.choice([rng.randint(2, 9), rng.randint(2, 9), rng.randint(11, 99)])
|
| 116 |
+
if op == '/':
|
| 117 |
+
b = rng.randint(2, 12) if rng.random() < 0.7 else rng.randint(13, 40)
|
| 118 |
+
a = b * rng.randint(2, 300) + (rng.randint(1, b - 1) if rng.random() < 0.35 else 0)
|
| 119 |
+
q = rng.choice(Q[L][op]).format(a=a, b=b)
|
| 120 |
+
if op == '+':
|
| 121 |
+
ans, steps, check = a + b, col_add(a, b, L), f'{a + b} - {b} = {a}'
|
| 122 |
+
elif op == '-':
|
| 123 |
+
ans, steps, check = a - b, col_sub(a, b, L), f'{a - b} + {b} = {a}'
|
| 124 |
+
elif op == '*':
|
| 125 |
+
ans, steps, check = a * b, col_mul(a, b, L), f'{a * b} : {b} = {a}'
|
| 126 |
+
else:
|
| 127 |
+
qq, r = divmod(a, b)
|
| 128 |
+
ans = (f'{qq}, ostatak {r}' if L == 'hr' else f'{qq}, remainder {r}') if r else qq
|
| 129 |
+
steps, check = long_div(a, b, L), f'{qq} × {b}' + (f' + {r}' if r else '') + f' = {a}'
|
| 130 |
+
sym = {'+': '+', '-': '-', '*': '×', '/': ':'}[op]
|
| 131 |
+
head = f'{a} {sym} {b}'
|
| 132 |
+
return q, head, steps, ans, check, (op, a, b)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def expr(rng, L):
|
| 136 |
+
"""Order of operations with brackets: a + b × c, (a + b) × c, a × b - c."""
|
| 137 |
+
a, b, c = rng.randint(2, 50), rng.randint(2, 20), rng.randint(2, 12)
|
| 138 |
+
t = rng.randrange(3)
|
| 139 |
+
if t == 0:
|
| 140 |
+
s, steps = f'{a} + {b} × {c}', [f'{b} × {c} = {b * c}', f'{a} + {b * c} = {a + b * c}']
|
| 141 |
+
ans = a + b * c
|
| 142 |
+
elif t == 1:
|
| 143 |
+
s, steps = f'({a} + {b}) × {c}', [f'{a} + {b} = {a + b}', f'{a + b} × {c} = {(a + b) * c}']
|
| 144 |
+
ans = (a + b) * c
|
| 145 |
+
else:
|
| 146 |
+
a = max(a, 2)
|
| 147 |
+
s, steps = f'{a} × {c} - {b}', [f'{a} × {c} = {a * c}', f'{a * c} - {b} = {a * c - b}']
|
| 148 |
+
ans = a * c - b
|
| 149 |
+
rule = 'Prvo množenje (i zagrade), zatim zbrajanje i oduzimanje.' if L == 'hr' else 'Brackets and multiplication first, then addition and subtraction.'
|
| 150 |
+
q = (f'Koliko je {s}?' if L == 'hr' else f'What is {s}?')
|
| 151 |
+
return q, s, [rule] + steps, ans, None, ('e', s, 0)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def money(rng, L):
|
| 155 |
+
p = rng.randint(105, 2999) / 100 # price with cents
|
| 156 |
+
n = rng.randint(2, 9)
|
| 157 |
+
tot = round(p * n, 2)
|
| 158 |
+
f = (lambda x: f'{x:.2f}'.replace('.', ',')) if L == 'hr' else (lambda x: f'{x:.2f}')
|
| 159 |
+
q = (f'Jedna bilježnica stoji {f(p)} €. Koliko stoji {n} bilježnica?' if L == 'hr' and n >= 5 else
|
| 160 |
+
f'Jedna bilježnica stoji {f(p)} €. Koliko stoje {n} bilježnice?' if L == 'hr' else
|
| 161 |
+
f'One notebook costs €{f(p)}. How much do {n} notebooks cost?')
|
| 162 |
+
cents = round(p * 100)
|
| 163 |
+
steps = [('Računam u centima: ' if L == 'hr' else 'Work in cents: ') + f'{f(p)} € = {cents} c',
|
| 164 |
+
*col_mul(cents, n, L), f'{cents * n} c = {f(tot)} €']
|
| 165 |
+
return q, f'{n} × {f(p)}', steps, f'{f(tot)} €', None, ('m', cents, n)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def percent(rng, L):
|
| 169 |
+
base = rng.choice([20, 40, 50, 60, 80, 120, 150, 200, 250, 300, 400, 480, 600, 750, 1200])
|
| 170 |
+
pc = rng.choice([5, 10, 15, 20, 25, 30, 40, 50, 75])
|
| 171 |
+
val = base * pc / 100
|
| 172 |
+
v = int(val) if val == int(val) else str(val).replace('.', ',' if L == 'hr' else '.')
|
| 173 |
+
q = f'Koliko je {pc} % od {base}?' if L == 'hr' else f'What is {pc}% of {base}?'
|
| 174 |
+
steps = [f'{pc} % = {pc}/100', f'{base} × {pc} = {base * pc}', f'{base * pc} : 100 = {v}']
|
| 175 |
+
return q, f'{pc} % od {base}' if L == 'hr' else f'{pc}% of {base}', steps, v, None, ('p', base, pc)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def word_hr(rng):
|
| 179 |
+
name, g = rng.choice(NAMES)
|
| 180 |
+
ow = rng.choice(OBJ)
|
| 181 |
+
o, c = NOUNS[ow], NOUNS[rng.choice(FITS[ow])]
|
| 182 |
+
t = rng.randrange(4)
|
| 183 |
+
if t == 0:
|
| 184 |
+
a, b = operands(rng, '+')
|
| 185 |
+
a, b = min(a, 999), min(b, 999)
|
| 186 |
+
q = f'{name} ima {a} {agree(a, o, "A")}. {verb(g, "Dobio", "Dobila")} je još {b} {agree(b, o, "A")}. Koliko {o["Gmn"]} {name} sada ima?'
|
| 187 |
+
return q, f'{a} + {b}', col_add(a, b, 'hr'), a + b, f'{a + b} - {b} = {a}', ('+', a, b), f'{name} sada ima {a + b} {agree(a + b, o, "A")}.'
|
| 188 |
+
if t == 1:
|
| 189 |
+
a, b = operands(rng, '-')
|
| 190 |
+
a, b = max(a, b), min(a, b)
|
| 191 |
+
q = f'U {c["L"]} ima {a} {agree(a, o, "A")}. {name} je {verb(g, "uzeo", "uzela")} {b} {agree(b, o, "A")}. Koliko {o["Gmn"]} je ostalo u {c["L"]}?'
|
| 192 |
+
return q, f'{a} - {b}', col_sub(a, b, 'hr'), a - b, f'{a - b} + {b} = {a}', ('-', a, b), f'U {c["L"]} je ostalo {a - b} {agree(a - b, o, "A")}.'
|
| 193 |
+
if t == 2:
|
| 194 |
+
a, b = rng.randint(2, 99), rng.randint(2, 12)
|
| 195 |
+
q = f'U svakoj {c["L"]} ima {a} {agree(a, o, "A")}. Koliko {o["Gmn"]} ima u {b} {agree(b, c)}?'
|
| 196 |
+
return q, f'{b} × {a}', col_mul(a, b, 'hr'), a * b, f'{a * b} : {b} = {a}', ('*', a, b), f'U {b} {agree(b, c)} ima {a * b} {agree(a * b, o, "A")}.'
|
| 197 |
+
b = rng.randint(2, 9)
|
| 198 |
+
k = rng.randint(2, 40)
|
| 199 |
+
a = b * k
|
| 200 |
+
q = f'{name} ima {a} {agree(a, o, "A")} i {verb(g, "želi", "želi")} ih jednako rasporediti u {b} {agree(b, c, "A")}. Koliko će {o["Gmn"]} biti u svakoj {c["L"]}?'
|
| 201 |
+
return q, f'{a} : {b}', long_div(a, b, 'hr'), k, f'{k} × {b} = {a}', ('/', a, b), f'U svakoj {c["L"]} bit će {k} {agree(k, o)}.'
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def word_en(rng):
|
| 205 |
+
n = rng.choice(EN_NAMES)
|
| 206 |
+
o = rng.choice(['apples', 'books', 'pencils', 'cards', 'stones', 'stickers', 'marbles'])
|
| 207 |
+
t = rng.randrange(3)
|
| 208 |
+
if t == 0:
|
| 209 |
+
a, b = operands(rng, '+')
|
| 210 |
+
return (f'{n} has {a} {o} and gets {b} more. How many {o} does {n} have now?', f'{a} + {b}', col_add(a, b, 'en'), a + b,
|
| 211 |
+
f'{a + b} - {b} = {a}', ('+', a, b), f'{n} now has {a + b} {o}.')
|
| 212 |
+
if t == 1:
|
| 213 |
+
a, b = operands(rng, '-')
|
| 214 |
+
a, b = max(a, b), min(a, b)
|
| 215 |
+
return (f'There are {a} {o} in a box. {n} takes out {b}. How many are left?', f'{a} - {b}', col_sub(a, b, 'en'), a - b,
|
| 216 |
+
f'{a - b} + {b} = {a}', ('-', a, b), f'{a - b} {o} are left.')
|
| 217 |
+
a, b = rng.randint(2, 99), rng.randint(2, 12)
|
| 218 |
+
return (f'Each bag holds {a} {o}. How many {o} are in {b} bags?', f'{b} × {a}', col_mul(a, b, 'en'), a * b,
|
| 219 |
+
f'{a * b} : {b} = {a}', ('*', a, b), f'There are {a * b} {o} in {b} bags.')
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def render(rng, L, item, style):
|
| 223 |
+
q, head, steps, ans, check, key, *prose = item
|
| 224 |
+
final = prose[0] if prose else (f'{head} = {ans}' if key[0] in '+-*/' else str(ans))
|
| 225 |
+
if style == 'short':
|
| 226 |
+
return q, (prose[0] if prose else str(ans)), key
|
| 227 |
+
think = '\n'.join(steps)
|
| 228 |
+
if check and style == 'check':
|
| 229 |
+
think += '\n' + ('Provjera: ' if L == 'hr' else 'Check: ') + check
|
| 230 |
+
if L == 'hr' and key[0] in '+-*/':
|
| 231 |
+
think = ('Računam po stupcima, od jedinica prema većim mjestima.\n' if key[0] in '+-' and key[1] >= 10 else '') + think
|
| 232 |
+
return q, f'<think>\n{think}\n</think>\n{final}', key
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def make(seed, n, exclude=frozenset()):
|
| 236 |
+
rng = random.Random(seed)
|
| 237 |
+
rows, keys = [], set()
|
| 238 |
+
gens = [(bare, 0.42), (word_hr, 0.2), (word_en, 0.08), (expr, 0.12), (money, 0.08), (percent, 0.10)]
|
| 239 |
+
while len(rows) < n:
|
| 240 |
+
g = rng.choices([x for x, _ in gens], [w for _, w in gens])[0]
|
| 241 |
+
L = 'en' if g is word_en else ('hr' if g is word_hr else ('en' if rng.random() < 0.3 else 'hr'))
|
| 242 |
+
item = g(rng) if g in (word_hr, word_en) else g(rng, L)
|
| 243 |
+
q, a, key = render(rng, L, item, rng.choices(['think', 'check', 'short'], [0.5, 0.3, 0.2])[0])
|
| 244 |
+
if key in exclude:
|
| 245 |
+
continue
|
| 246 |
+
keys.add(key)
|
| 247 |
+
rows.append(dict(id=f'yg-arith:{seed}:{len(rows)}', lang=L, messages=[dict(role='user', content=q), dict(role='assistant', content=a)]))
|
| 248 |
+
return rows, keys
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def selfcheck(rows):
|
| 252 |
+
"""Re-verify every stated final number for bare + - × rows by evaluating the head expression."""
|
| 253 |
+
bad = 0
|
| 254 |
+
for r in rows:
|
| 255 |
+
a = r['messages'][1]['content'].split('\n')[-1]
|
| 256 |
+
if ' = ' in a and a.count('=') == 1:
|
| 257 |
+
lhs, rhs = a.split(' = ')
|
| 258 |
+
lhs = lhs.replace('×', '*')
|
| 259 |
+
if all(ch in '0123456789+-* ' for ch in lhs) and rhs.strip().isdigit():
|
| 260 |
+
bad += eval(lhs) != int(rhs)
|
| 261 |
+
return bad
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def main():
|
| 265 |
+
probe, pkeys = make(990001, 600)
|
| 266 |
+
train, _ = make(251125, 40000, exclude=frozenset(pkeys))
|
| 267 |
+
assert selfcheck(train) == 0 and selfcheck(probe) == 0
|
| 268 |
+
for name, rows in (('arith-train.jsonl', train), ('arith-probe.jsonl', probe)):
|
| 269 |
+
with open(HERE / name, 'w') as f:
|
| 270 |
+
for r in rows:
|
| 271 |
+
f.write(json.dumps(r, ensure_ascii=False) + '\n')
|
| 272 |
+
print('train', len(train), 'probe', len(probe), 'probe keys excluded from train')
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
if __name__ == '__main__':
|
| 276 |
+
main()
|
croguana-500.png
ADDED
|
Git LFS Details
|
data/short-train.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aacd8187da48a6571b3f5476248b0d3d096b51d94796f016ff17bedc523e068b
|
| 3 |
+
size 2962449
|
data/worked-test.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fefa76234b9b5dbd7f8d8b0ff38d2c4a95663f2dac730cfc3231331ce857984e
|
| 3 |
+
size 44681
|
data/worked-train.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2d46274f0cb6cf0e9409e67e4a711d0169b9dd118d04d36dc78dc4d843ef8f85
|
| 3 |
+
size 2713132
|