atlas

Research map / Architectures and efficiency / Attention and transformers

Transformers Can Do Arithmetic with the Right Embeddings

NeurIPS 2024 · Architectures and efficiency › Attention and transformers · approach: Transformer expressivity and learnability · 6 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.

Adds Abacus Embeddings (per-digit positional embeddings shared across same-significance digits, with random offsets) to small transformers trained from scratch on arithmetic, combined with input injection and looped transformers, achieving length generalization to 100+ digit addition.

Problem

Transformers struggle to learn multi-digit arithmetic and to extrapolate to longer operands because they lose track of each digit's exact position within a number.

Approach

Learned positional embeddings assigned per digit according to its significance relative to the number start (with a random starting offset during training), so digits of equal significance share an embedding; combined with input injection and looped (recurrent) transformer blocks.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Add Abacus Embeddings and input injection with a looped transformerAddition model trained on operands up to 20 digits · Addition, OODaccuracy: 92.9% to 99.1%Helped
Add Abacus EmbeddingsStandard transformer · Addition, OOD length generalizationexact match accuracyHelped
Use Abacus Embeddings instead of FIRE or NoPEAddition transformer · Additionexact match accuracyHelped
Combine Abacus Embeddings with FIRE8-layer standard transformer · Sorting, all OOD (30×30)exact match accuracy: 3.73; 2.65; 4.48Helped
Combine Abacus Embeddings with FIRE8-layer standard transformer · Sorting, OOD (number length - 30)exact match accuracy: 55.32; 68.63; 67.28Helped
Combine Abacus Embeddings with FIRE8-layer standard transformer · Sorting, OOD (array length - 30)exact match accuracy: 21.35; 9.67; 21.11Mixed
Use a looped transformer instead of a standard transformerSorting model · All OOD, minimum element onlyaccuracy: 49.73; 60.09; 68.51Helped
Use a looped transformer instead of a standard transformerSorting model · All OOD, exact string matchaccuracy: 4.48; 3.84; 2.60Hurt
Use an 8-layer recurrent block with 2 recurrences instead of a non-recurrent 16-layer model (ablation)Addition model with Abacus Embeddings · Addition, OODerror rate: half the errorHelped
Remove loss masking before the equals sign (ablation)Addition model · AdditionaccuracyHurt
Remove input injection within recurrent-block layers, retaining it only at the first recurrent layer (ablation)Addition looped transformer · AdditionperformanceNo clear effect
Divide recurrent-block gradients by the number of recurrences (ablation)Addition looped transformer · AdditionperformanceNo clear effect

Surprising findings

Limitations

Experimental setup

Datasets: synthetic addition data (up to 20-digit operands) synthetic multiplication data (up to 15 digits) synthetic array sorting data synthetic bitwise OR data

Benchmarks: addition exact match accuracy (in-distribution, OOD up to 100 digits, 100+ digit OOD up to 160) multiplication up to 15 digits array sorting OOD (30-digit numbers, 30-element arrays)

Metrics: exact match accuracy

Baselines: FIRE NoPE RoPE Index hints (Zhou et al.) Standard transformer with input injection

Builds on: FIRE positional embeddings NoPE randomized positional embeddings progressive loss index hints

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