Memorization Capacity of Multi-Head Attention in Transformers

Sadegh Mahdavi, Renjie Liao, Christos Thrampoulidis
6/3/2023
cs.LG

No official code found. Best implementation: smahdavi4/attention-memorization (3 stars, last commit 2024-02-27).

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 $H$ heads, dimension $d$, and context size $n < d$, featuring $Θ(Hd^2)$ parameters, can memorize $Ω(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.

View on arXivView PDF

Code Implementations(1)

31Shell, PythonJun 2, 20232 years ago

Similar Papers

Cite this paper

@article{mahdavi2023memorization,
  title  = {Memorization Capacity of Multi-Head Attention in Transformers},
  author = {Sadegh Mahdavi and Renjie Liao and Christos Thrampoulidis},
  year   = {2023},
  eprint = {2306.02010},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2306.02010v3},
  journal = {ICLR 2023 2023}
}

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/2306.02010.svg)](https://codeofpaper.com/paper/2306.02010)

Discussion