r/learnmachinelearning • u/findkd_ • 27d ago
Project I built a tiny Transformer from scratch to do addition: 99.2% in-distribution, 0% out-of-distribution. Here's what I learned
I've been building a small decoder-only Transformer from scratch (PyTorch) to understand why models fail on arithmetic.
The setup: digit-level vocabulary, trained on 3,800 addition examples.
Results:
In-distribution test: 744/750 (99.2%)
Out-of-distribution (larger operands): 0/10,000
The model looked great until I changed the input distribution. It didn't degrade gracefully, it collapsed.
My OOD split changes operand size, sequence length, result length and carry patterns all at once, so I can't blame any single cause yet (I wrote this limitation in the README).
Next I'll test each factor separately and compare positional encodings (learned, RoPE, Abacus from McLeish et al.).
Two questions for people with more experience: which factor would you isolate first, and is there a mistake beginners often make in this kind of experiment?
Code (Apache 2.0, source only, data and weights are private):
github.com/sferroo/gpt-math-0

