Understanding Addition and Subtraction in Transformers

Philip Quirke, Clement Neo, Fazl Barez
2/4/2024
cs.LGcs.CL
transformer-attention

No confident code implementation found for this paper.

Abstract

Transformers are widely deployed in large language models (LLMs), yet most models still fail on basic arithmetic tasks such as multidigit addition. In contrast, we show that small transformers trained from scratch can solve n-digit addition and subtraction with 99.999% accuracy.

Show full abstract

Building directly on prior work that uncovered addition circuits, we extend the analysis to subtraction and present a unified mechanistic account based on cascading carry and borrow circuits. Using a suite of 49 trained models, we apply systematic ablations and node-level constraints to validate the learned mechanisms and release a reproducible interpretability toolkit for studying arithmetic circuits. Finally, surveying 180 publicly available LLMs, we find that only 7% can reliably perform addition, underscoring the gap between specialized small models and general-purpose LLMs. Our results show that arithmetic can be implemented exactly by tiny transformers, offering a tractable case study for mechanistic interpretability and a cautionary contrast with the persistent arithmetic failures of much larger models.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{quirke2024understanding,
  title  = {Understanding Addition and Subtraction in Transformers},
  author = {Philip Quirke and Clement Neo and Fazl Barez},
  year   = {2024},
  eprint = {2402.02619},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2402.02619v10}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2402.02619.svg)](https://codeofpaper.com/paper/2402.02619)

Discussion