Memorization Capacity of Multi-Head Attention in Transformers

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 $\Theta(Hd^2)$ parameters, can memorize $\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.

Cite

Text

Mahdavi et al. "Memorization Capacity of Multi-Head Attention in Transformers." International Conference on Learning Representations, 2024.

Markdown

[Mahdavi et al. "Memorization Capacity of Multi-Head Attention in Transformers." International Conference on Learning Representations, 2024.](https://mlanthology.org/iclr/2024/mahdavi2024iclr-memorization/)

BibTeX

@inproceedings{mahdavi2024iclr-memorization,
  title     = {{Memorization Capacity of Multi-Head Attention in Transformers}},
  author    = {Mahdavi, Sadegh and Liao, Renjie and Thrampoulidis, Christos},
  booktitle = {International Conference on Learning Representations},
  year      = {2024},
  url       = {https://mlanthology.org/iclr/2024/mahdavi2024iclr-memorization/}
}