AI
Transformers Learn Patterns in Prime Factorization Tree Sequences Far Beyond Training Data
A GPT-2 model trained on a trillion elements of a mathematically-structured tree sequence generalizes accurately to numbers a million times larger, capturing deep regularities absent from simple frequency analysis.
Researchers have trained a transformer network to predict sequences of rooted trees derived from prime factorization patterns, demonstrating that the model learns meaningful mathematical structure rather than merely memorizing token frequencies.
The Task#
The study focuses on a deterministic sequence generated by applying iterated prime factorization to natural numbers. Each integer is converted into a rooted planar tree, creating an arithmetic text with measurable statistical properties. A GPT-2 architecture was trained on the first 10^11 elements (100 billion) of this sequence to perform next-token and masked-token prediction tasks.
Key Results#
The trained transformer achieved roughly 40% word accuracy—substantially outperforming a Hidden Markov Model baseline—while maintaining consistent performance on test data extracted from 10^13 to 10^15 (hundreds of trillions), far beyond its training range. This sustained accuracy on distant held-out blocks suggests genuine pattern capture rather than overfitting.
To verify the model was learning genuine regularities, researchers tested it against two control sequences:
- Randomized controls: synthetic token streams preserving individual token frequencies but destroying sequential order
- Forbidden configurations: sequences containing more than three consecutive square-free integers, which the arithmetic text naturally avoids
The model's likelihood scores successfully separated the true arithmetic sequence from both controls, with the gap widening as context window increased—evidence that the transformer internalized contextual dependencies specific to the mathematical structure.
Scaling and Generalization#
A comprehensive scaling analysis across context window size, dataset size, vocabulary size, and model capacity revealed systematic improvements. The model's ability to extrapolate so far beyond training suggests it learned compressed representations of deep mathematical principles underlying the prime factorization sequence.
Implications#
The results indicate that transformers can capture abstract structural regularities that transcend simple frequency profiles, opening questions about what kinds of mathematical and logical patterns neural networks can discover through sequence prediction alone.

