English

On the Optimal Memorization Capacity of Transformers

Machine Learning 2025-02-28 v2

Abstract

Recent research in the field of machine learning has increasingly focused on the memorization capacity of Transformers, but how efficient they are is not yet well understood. We demonstrate that Transformers can memorize labels with O~(N)\tilde{O}(\sqrt{N}) parameters in a next-token prediction setting for NN input sequences of length nn, which is proved to be optimal up to logarithmic factors. This indicates that Transformers can efficiently perform memorization with little influence from the input length nn owing to the benefit of parameter sharing. We also analyze the memorization capacity in the sequence-to-sequence setting, and find that O~(nN)\tilde{O}(\sqrt{nN}) parameters are not only sufficient, but also necessary at least for Transformers with hardmax. These results suggest that while self-attention mechanisms can efficiently identify input sequences, the feed-forward network becomes a bottleneck when associating a label to each token.

Keywords

Cite

@article{arxiv.2409.17677,
  title  = {On the Optimal Memorization Capacity of Transformers},
  author = {Tokio Kajitsuka and Issei Sato},
  journal= {arXiv preprint arXiv:2409.17677},
  year   = {2025}
}

Comments

Published at ICLR 2025

R2 v1 2026-06-28T18:57:53.067Z