Reproduce “Arithmetic with Language Models: from Memorization to Computation” on OpenResearch

Turn your favorite coding agents into research agents that review literature, develop hypotheses, and run experiments.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Davide Maltoni, Matteo Ferrara

This research investigates how language models perform arithmetic by proposing an "Encoding-Regression-Decoding" (ERD) hypothesis, where models map inputs to an internal value representation, compute in this space, and decode results. Using lightweight Transformers, the study demonstrates efficient learning of binary addition and multiplication, achieving 100% and 98.9% sequence accuracy respectively on token-space interpolation, while highlighting challenges in extrapolation within the numerical value space.

Key insights

  • Language models learn a computational strategy for arithmetic, rather than simply memorizing input-output pairs, with LSBs-first output order significantly improving training efficiency.
  • The 'Encoding-Regression-Decoding' (ERD) hypothesis is supported: input tokens are encoded into an internal value representation, a form of regression occurs in this value space, and results are then decoded back into output tokens.
  • Generalization performance is robust for token-space interpolation but significantly degrades for value-space extrapolation, indicating that coverage of the internal value representation by training data is critical for novel numerical ranges.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.