English

Learning the greatest common divisor: explaining transformer predictions

Machine Learning 2024-03-18 v2 Artificial Intelligence

Abstract

The predictions of small transformers, trained to calculate the greatest common divisor (GCD) of two positive integers, can be fully characterized by looking at model inputs and outputs. As training proceeds, the model learns a list D\mathcal D of integers, products of divisors of the base used to represent integers and small primes, and predicts the largest element of D\mathcal D that divides both inputs. Training distributions impact performance. Models trained from uniform operands only learn a handful of GCD (up to 3838 GCD 100\leq100). Log-uniform operands boost performance to 7373 GCD 100\leq 100, and a log-uniform distribution of outcomes (i.e. GCD) to 9191. However, training from uniform (balanced) GCD breaks explainability.

Cite

@article{arxiv.2308.15594,
  title  = {Learning the greatest common divisor: explaining transformer predictions},
  author = {François Charton},
  journal= {arXiv preprint arXiv:2308.15594},
  year   = {2024}
}
R2 v1 2026-06-28T12:07:47.477Z