A Random Matrix Analysis of In-context Memorization for Nonlinear Attention

Zhenyu Liao, Jiaqing Liu, TianQi Hou, Difan Zou, Zenan Ling
6/23/2025
stat.MLcs.LGmath.ST

No confident code implementation found for this paper.

Abstract

Attention mechanisms have revolutionized machine learning (ML) by enabling efficient modeling of global dependencies across inputs. Their inherently parallelizable structures allow for efficient scaling with the exponentially increasing size of both pretrained data and model parameters. Yet, despite their central role as the computational backbone of modern large language models (LLMs), the theoretical understanding of Attentions, especially in the nonlinear setting, remains limited. In this paper, we provide a precise characterization of the \emph{in-context memorization error} of \emph{nonlinear Attention}, in the high-dimensional proportional regime where the number of input tokens $n$ and their embedding dimension $p$ are both large and comparable. Leveraging recent advances in the theory of large kernel random matrices, we show that nonlinear Attention typically incurs higher memorization error than linear ridge regression on random inputs. However, this gap vanishes, and can even be reversed, when the input exhibits statistical structure, particularly when the Attention weights align with the input signal direction. Our results reveal how nonlinearity and input structure interact with each other to govern the memorization performance of nonlinear Attention. The theoretical insights are supported by numerical experiments.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{liao2025random,
  title  = {A Random Matrix Analysis of In-context Memorization for Nonlinear Attention},
  author = {Zhenyu Liao and Jiaqing Liu and TianQi Hou and Difan Zou and Zenan Ling},
  year   = {2025},
  eprint = {2506.18656},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2506.18656v1}
}

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

Discussion