Lune

ICLR2024Top-tier venue

Memorization Capacity of Multi-Head Attention in Transformers

Sadegh Mahdavi, Renjie Liao, Christos Thrampoulidis

Abstract

Transformers have become the go-to architecture for language and vision tasks, yet their theoretical properties, especially memorization capacity, remain elusive. This paper investigates the memorization abilities of multi-head attention mechanisms, examining how many example sequences they can memorize, as a function of the number of heads and sequence length. Motivated by experimental findings on vision transformers, we introduce novel assumptions about the linear independence of input data, distinct from the commonly used general-position assumption. Under these assumptions, we demonstrate that an attention layer with HH heads, dimension dd, and context size n<dn<d, featuring Θ(Hd2)\Theta(Hd^2) parameters, can memorize Ω(Hn)\Omega(Hn) examples. Our analysis sheds light on how different attention heads handle various example sequences, aided by the softmax operator's saturation property. We validate our findings through experiments on synthetic data.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

26 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators? cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators? cites Language Models are Few-Shot Learners
  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale cites Language Models are Few-Shot Learners
  • What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Tasks cites Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators?
  • What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Tasks cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Tasks cites Language Models are Few-Shot Learners
  • What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Tasks cites Transformers Learn In-Context by Gradient Descent
  • What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Tasks cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • How Transformers Utilize Multi-Head Attention in In-Context Learning? A Case Study on Sparse Linear Regression cites Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators?
  • How Transformers Utilize Multi-Head Attention in In-Context Learning? A Case Study on Sparse Linear Regression cites What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning Tasks
  • How Transformers Utilize Multi-Head Attention in In-Context Learning? A Case Study on Sparse Linear Regression cites Transformers Learn In-Context by Gradient Descent
  • How Transformers Utilize Multi-Head Attention in In-Context Learning? A Case Study on Sparse Linear Regression cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Scaling Vision Transformers to 22 Billion Parameters cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • How Far Can Transformers Reason? The Globality Barrier and Inductive Scratchpad cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • On Statistical Rates and Provably Efficient Criteria of Latent Diffusion Transformers (DiTs) cites Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators?
  • On Statistical Rates and Provably Efficient Criteria of Latent Diffusion Transformers (DiTs) cites Language Models are Few-Shot Learners
  • Transformers Learn In-Context by Gradient Descent cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Transformers Learn In-Context by Gradient Descent cites Language Models are Few-Shot Learners
  • Transformers Learn In-Context by Gradient Descent cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers26

  1. How Far Can Transformers Reason? The Globality Barrier and Inductive ScratchpadEmmanuel Abbe, Samy Bengio, Aryo Lotfi, Colin Sandon et al.NeurIPS 2024 · 52 citations
  2. On Statistical Rates and Provably Efficient Criteria of Latent Diffusion Transformers (DiTs)Jerry Yao-Chieh Hu, Weimin Wu, Zhuoru Li, Sophia Pi et al.NeurIPS 2024 · 49 citations
  3. Are Transformers with One Layer Self-Attention Using Low-Rank Weight Matrices Universal Approximators?Tokio Kajitsuka, Issei SatoICLR 2024 · 31 citations
  4. What Can Transformer Learn with Varying Depth? Case Studies on Sequence Learning TasksXingwu Chen, Difan ZouICML 2024 · 22 citations
  5. How Transformers Utilize Multi-Head Attention in In-Context Learning? A Case Study on Sparse Linear RegressionXingwu Chen, Lei Zhao, Difan ZouNeurIPS 2024 · 19 citations

Builds on21

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
  3. What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
  4. Scaling Vision Transformers to 22 Billion ParametersMostafa Dehghani, Josip Djolonga, Basil Mustafa, Piotr Padlewski et al.ICML 2023 · 848 citations
  5. Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations

Related papers

  1. Provable Memorization Capacity of TransformersJunghwan Kim, Michelle Kim, Barzan MozafariICLR 2023
  2. The Effect of Attention Head Count on Transformer ApproximationPenghao Yu, Haotian Jiang, Zeyu Bao, Ruoxi Yu et al.ICLR 2026 · 5 citations
  3. On the Optimal Memorization Capacity of TransformersTokio Kajitsuka, Issei SatoICLR 2025
  4. Understanding the Expressive Power and Mechanisms of Transformer for Sequence ModelingMingze Wang, Weinan ENeurIPS 2024 · 32 citations
  5. Quality over Quantity in Attention Layers: When Adding More Heads HurtsNoah Amsel, Gilad Yehudai, Joan BrunaICLR 2025
Dusk over the sea between two cliffs drawn in fine vertical lines