atlas

Research map / Architectures and efficiency / Attention and transformers

Learning the greatest common divisor: explaining transformer predictions

ICLR 2024 · Architectures and efficiency › Attention and transformers · approach: Transformer expressivity and learnability · 0 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Trains small 4-layer transformers to compute GCD of integers, shows predictions are fully characterized by simple rules (sieve-like clustering by divisors of the base), and finds log-uniform operand and outcome distributions improve the number of correct GCD up to 91.

Problem

Whether small transformers can learn exact greatest common divisor computation, and how their predictions can be explained and improved by training distribution choices.

Approach

Model predictions can be fully characterized: the transformer clusters input pairs by GCD class and predicts the largest learned divisor (products of base divisors and later grokked small primes) dividing both inputs. Log-uniform training distributions of operands and outcomes accelerate learning and raise the number of correctly learned GCD.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use log-uniform operands instead of uniform operandsTransformer GCD training, base 10 · Stratified GCD ≤100correct GCD count: 13 -> 48Helped
Use log-uniform outcomes instead of natural outcomesTransformer GCD training, base 1000 · Stratified GCD ≤100correct GCD count: 71 -> 91Helped
Use uniform outcomes instead of unbalanced outcomesTransformer GCD training · GCD prediction explainabilitydeterministic predictionsHurt
Use inverse square root outcomes instead of natural inverse square outcomesTransformer GCD training with log-uniform operands · Stratified GCD ≤100correct GCD count: For 6 bases, 92 GCD under 100 are predicted correctly.Helped
Use log-uniform outcomes sampled up to 200 instead of up to 100Transformer GCD training with log-uniform operands · Stratified GCD ≤100correct GCD count: 90 -> 85Hurt
Add 5% uniformly sampled GCD to natural training outcomesTransformer GCD training, base 30 · Stratified GCD ≤100epochs to learn 27 GCD: 660 -> 175Helped
Use uniformly distributed GCD outcomes instead of unbalanced outcomesTransformer GCD training, base 10 · GCD prediction explainabilityprediction stability across epochsHurt
Reduce transformer size from the 4-layer baseline to 1 layer and 32 dimensions (ablation)Transformer GCD, base 30 · Natural test setaccuracy (%): 94.7 -> 93.3No clear effect
Scale from the 4-layer baseline to 24 layers and 1024 dimensions (ablation)Transformer GCD, base 30 · Natural test setaccuracy (%): 94.7 -> 93.4No clear effect
Use batch size 64 instead of 256 (ablation)Transformer GCD training with log-uniform operands, base 1000 · Stratified GCD ≤100correct GCD count: 71 -> 70No clear effect
Use base 420 instead of base 11Transformer GCD with uniform operands · Natural test setaccuracy (%): 61.8 -> 96.8Helped
Train on uniform rather than log-uniform operandsTransformer GCD, base 2401 · Stratified GCD ≤100correct GCD count: 14 -> 73Hurt

Surprising findings

Limitations

Experimental setup

Datasets: synthetic GCD pairs sampled uniformly from 1 to 10^6 log-uniform operand samples stratified GCD test set

Benchmarks: natural test set (uniform pairs 1 to 10^6) stratified test set (GCD 1 to 100)

Metrics: accuracy number of correct GCD under 100

Baselines: LSTM GRU natural GCD distribution training

Builds on: Adam grokking

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy