[Paper Review] Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer
This paper provides a mathematically rigorous analysis of SGD training dynamics in a 1-layer Transformer for next token prediction, revealing that self-attention acts as a discriminative scanning mechanism: it progressively focuses on distinct, frequently co-occurring tokens while reducing attention to common ones. The key finding is a phase transition in training dynamics that prevents collapse to winner-takes-all, resulting in stable, sparse attention patterns controllable by learning rate ratios.
Transformer architecture has shown impressive performance in multiple research domains and has become the backbone of many neural network models. However, there is limited understanding on how it works. In particular, with a simple predictive loss, how the representation emerges from the gradient \emph{training dynamics} remains a mystery. In this paper, for 1-layer transformer with one self-attention layer plus one decoder layer, we analyze its SGD training dynamics for the task of next token prediction in a mathematically rigorous manner. We open the black box of the dynamic process of how the self-attention layer combines input tokens, and reveal the nature of underlying inductive bias. More specifically, with the assumption (a) no positional encoding, (b) long input sequence, and (c) the decoder layer learns faster than the self-attention layer, we prove that self-attention acts as a \emph{discriminative scanning algorithm}: starting from uniform attention, it gradually attends more to distinct key tokens for a specific next token to be predicted, and pays less attention to common key tokens that occur across different next tokens. Among distinct tokens, it progressively drops attention weights, following the order of low to high co-occurrence between the key and the query token in the training set. Interestingly, this procedure does not lead to winner-takes-all, but decelerates due to a \emph{phase transition} that is controllable by the learning rates of the two layers, leaving (almost) fixed token combination. We verify this extbf{\emph{scan and snap}} dynamics on synthetic and real-world data (WikiText).
Motivation & Objective
- To understand the implicit inductive bias of self-attention in Transformers during training with simple next-token prediction.
- To formalize the dynamic evolution of attention weights under SGD, particularly in the absence of positional encoding.
- To explain why self-attention does not collapse to winner-takes-all despite increasing sparsity.
- To characterize how learning rate ratios between decoder and self-attention layers control the onset of phase transition and attention pattern density.
- To verify theoretical predictions on synthetic and real-world data (WikiText).
Proposed method
- Analyzes a 1-layer Transformer with self-attention followed by a decoder layer for next-token prediction under SGD optimization.
- Introduces a continuous-time approximation of SGD dynamics using nonlinear ODEs to model parameter evolution.
- Employs a reparameterization of attention weights via matrices $Y$ and $Z$ to decouple self-attention and decoder dynamics.
- Derives analytical solutions for attention logits and softmax outputs under long-sequence and slow-attention assumptions.
- Uses Hoeffding's inequality to bound empirical frequency estimates of token co-occurrence in long sequences.
- Validates findings via experiments on synthetic data and WikiText, measuring attention entropy and recall-threshold curves.

Experimental results
Research questions
- RQ1How does self-attention dynamically evolve during training in a 1-layer Transformer without positional encoding?
- RQ2What inductive bias does self-attention learn, and how does it relate to token co-occurrence frequency and distinctiveness?
- RQ3Why does self-attention avoid collapsing into a winner-takes-all pattern despite increasing sparsity?
- RQ4How do learning rate ratios between the decoder and self-attention layers affect the sparsity and stability of attention patterns?
- RQ5Can the theoretical dynamics of 'scan and snap' be empirically verified on real-world sequences?
Key findings
- Self-attention exhibits a discriminative scanning behavior: it progressively focuses on key tokens that are distinct and frequently co-occurring with the query token.
- The attention mechanism shows a frequency bias, favoring tokens with high co-occurrence frequency with the query in the training data.
- Despite increasing sparsity, attention does not collapse to one-hot due to a phase transition in training dynamics, leading to a logarithmic decay in gradient magnitude.
- Larger learning rates for the decoder layer accelerate the phase transition, resulting in denser attention patterns, while larger self-attention learning rates lead to sparser patterns.
- Empirical results on WikiText confirm that higher learning rates reduce attention map entropy and slow the recall-threshold descent, indicating sparser attention.
- Theoretical predictions on attention sparsity and co-occurrence dependence are validated via recall-threshold curves across varying learning rate ratios.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.