On the Optimal Memorization Capacity of Transformers
Tokio Kajitsuka, Issei Sato
TL;DR
The paper analyzes the memorization capacity of Transformer architectures under two settings: next-token prediction and sequence-to-sequence prediction. It shows that memorization can be achieved with \\tilde{O}(\\sqrt{N}) parameters in the next-token setting (nearly independent of input length $n$) and with \\tilde{O}(\\sqrt{nN}) parameters in the seq-to-seq setting under hardmax, with matching lower bounds up to logarithmic factors. The core technique uses a contextual mapping to assign unique sequence IDs and demonstrates that a single self-attention layer can effectively identify input sequences, while the feed-forward network becomes the bottleneck for assigning labels in the seq-to-seq case. These results illuminate the parameter-efficiency of self-attention reusing information across tokens and suggest that the practical advantages of Transformers may stem from optimization and generalization properties rather than raw memorization capacity. The work also discusses bit-complexity considerations and open problems for softmax memorization bounds and extensions to other equivariant architectures.
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 $\tilde{O}(\sqrt{N})$ parameters in a next-token prediction setting for $N$ input sequences of length $n$, 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 $n$ owing to the benefit of parameter sharing. We also analyze the memorization capacity in the sequence-to-sequence setting, and find that $\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.
