Abstract
This study investigates the approximation capabilities, training dynamics, and generalization of one-layer transformers on in-context recall tasks. We demonstrate that while standard transformers can represent optimal solutions, they often fail to generalize to out-of-distribution (OOD) samples when trained via gradient descent. By introducing a specific structural reparameterization, we prove that transformers with linear, ReLU, or softmax attention can achieve Bayes-optimality with linear convergence rates. Our findings reveal that proper parameterization is crucial for models to move beyond memorization and learn the underlying logic of in-context reasoning.
Introduction
In-context learning is a hallmark of Large Language Models (LLMs), yet the mechanisms by which they acquire these skills during training remain partially understood. This paper focuses on "in-context recall"—the ability of a model to identify a trigger token within a prompt and retrieve its associated output. While previous research has explored the existence of attention-based solutions for such tasks, this work delves into the training dynamics and generalization properties of these models under gradient descent.
Problem Formulation: The In-Context Recall Task
The authors define a synthetic data model to isolate the recall mechanism. In this setup, a sequence contains a trigger-output pair $(q, y)$. Later in the sequence, the trigger $q$ reappears, and the model must predict $y$.
- Noiseless Setting: The trigger $q$ is always followed by $y$.
- Noisy Setting: The trigger $q$ may be followed by $y$ or a generic noise token $\tau$.
- OOD Generalization: The primary challenge is whether a model trained on a subset of $(q, y)$ pairs can correctly perform recall for a $y$ it has never seen in that specific context before.
Methodology: Reparameterization and Training
The study employs a 1-layer decoder-only transformer. To overcome the "lazy" convergence of standard models, the authors introduce a reparameterization scheme. This scheme structures the weight matrices (Unembedding, Value, Query-Key, and Feed-forward) to facilitate associative memory.
Training is analyzed using Normalized Gradient Descent (NGD). The authors provide a finite-sample analysis, tracking the evolution of the loss function and proving that the expected loss converges at a linear rate to the Bayes risk.
Key Insights
- Expressivity vs. Generalization: High expressive power does not guarantee generalization. Standard "Origin" models often minimize training loss by memorizing specific pairs but fail when encountering unseen output tokens.
- The Role of Parameterization: Structural reparameterization acts as a regularizer, guiding gradient descent toward a generalizable "recall rule" rather than simple memorization.
- Functional Specialization: In noisy environments, the model naturally decomposes the task: the attention layer handles context-specific recall, while the feed-forward layer manages global statistics (like predicting the noise token).
Key Results and Empirical Validation
The theoretical predictions were tested against empirical benchmarks. As shown in Figure 1, standard models ("Origin") consistently failed the "Unseen $y$" test, indicating a lack of OOD generalization.
The results demonstrate that:
- Linear Convergence: All reparameterized models achieved linear convergence to optimal loss.
- OOD Success: Fully reparameterized models (shaded in the table) successfully generalized to unseen tokens in both noiseless and noisy environments.
- Linear Attention Optimality: Contrary to common belief, linear attention can be Bayes-optimal for recall tasks when properly parameterized.
Conclusion
This work provides a rigorous theoretical foundation for understanding how transformers learn in-context tasks. It highlights a critical gap between a model's capacity to represent a solution and its ability to learn that solution via gradient descent. The success of the reparameterization scheme suggests that architectural or training-time inductive biases are essential for achieving human-like generalization in LLMs. Future work will explore how these biases might emerge naturally in more complex, multi-layer architectures.
Summary updated