Learning Modular Exponentiation with Transformers

Fuente: arXiv
Salvato in:
Dettagli Bibliografici
Autori principali: Africa, David Demitri, Kapoor, Sara M., Sorg, Theo Simon, Mishra, Challenger
Natura: Preprint
Pubblicazione: 2025
Soggetti:
Accesso online:
Tags: Aggiungi Tag
Nessun Tag, puoi essere il primo ad aggiungerne!!
_version_ 1866908607317016576
author Africa, David Demitri
Kapoor, Sara M.
Sorg, Theo Simon
Mishra, Challenger
author_facet Africa, David Demitri
Kapoor, Sara M.
Sorg, Theo Simon
Mishra, Challenger
contents Modular exponentiation is crucial to number theory and cryptography, yet remains largely unexplored from a mechanistic interpretability standpoint. We train a 4-layer encoder-decoder Transformer model to perform this operation and investigate the emergence of numerical reasoning during training. Utilizing principled sampling strategies, PCA-based embedding analysis, and activation patching, we examine how number-theoretic properties are encoded within the model. We find that reciprocal operand training leads to strong performance gains, with sudden generalization across related moduli. These synchronized accuracy surges reflect grokking-like dynamics, suggesting the model internalizes shared arithmetic structure. We also find a subgraph consisting entirely of attention heads in the final layer sufficient to achieve full performance on the task of regular exponentiation. These results suggest that transformer models learn modular arithmetic through specialized computational circuits, paving the way for more interpretable and efficient neural approaches to modular exponentiation.
format Preprint
id arxiv_https___arxiv_org_abs_2506_23679
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Learning Modular Exponentiation with Transformers
Africa, David Demitri
Kapoor, Sara M.
Sorg, Theo Simon
Mishra, Challenger
Machine Learning
Artificial Intelligence
Cryptography and Security
Modular exponentiation is crucial to number theory and cryptography, yet remains largely unexplored from a mechanistic interpretability standpoint. We train a 4-layer encoder-decoder Transformer model to perform this operation and investigate the emergence of numerical reasoning during training. Utilizing principled sampling strategies, PCA-based embedding analysis, and activation patching, we examine how number-theoretic properties are encoded within the model. We find that reciprocal operand training leads to strong performance gains, with sudden generalization across related moduli. These synchronized accuracy surges reflect grokking-like dynamics, suggesting the model internalizes shared arithmetic structure. We also find a subgraph consisting entirely of attention heads in the final layer sufficient to achieve full performance on the task of regular exponentiation. These results suggest that transformer models learn modular arithmetic through specialized computational circuits, paving the way for more interpretable and efficient neural approaches to modular exponentiation.
title Learning Modular Exponentiation with Transformers
topic Machine Learning
Artificial Intelligence
Cryptography and Security
url https://arxiv.org/abs/2506.23679