Training Dynamics of Transformers to Recognize Word Co-occurrence via Gradient Flow Analysis
Not on the map. Why?
Abstract (arXiv)
Understanding the training dynamics of transformers is important to explain the impressive capabilities behind large language models. In this work, we study the dynamics of training a shallow transformer on a task of recognizing co-occurrence of two designated words. In the literature of studying training dynamics of transformers, several simplifications are commonly adopted such as weight reparameterization, attention linearization, special initialization, and lazy regime. In contrast, we analyze the gradient flow dynamics of simultaneously training three attention matrices and a linear MLP layer from random initialization, and provide a framework of analyzing such dynamics via a coupled dynamical system. We establish near minimum loss and characterize the attention model after training. We discover that gradient flow serves as an inherent mechanism that naturally divide the training process into two phases. In Phase 1, the linear MLP quickly aligns with the two target signals for correct classification, whereas the softmax attention remains almost unchanged. In Phase 2, the attention matrices and the MLP evolve jointly to enlarge the classification margin and reduce the loss to a near minimum value. Technically, we prove a novel property of the gradient flow, termed textitautomatic balancing of gradients, which enables the loss values of different samples to decrease almost at the same rate and further facilitates the proof of near minimum training loss. We also conduct experiments to verify our theoretical results.
Key facts. Cited by 9 papers in the map (data through 14 Oct 2026). Builds on 35 of its 42 references that are in the map. First posted on arXiv 12 Oct 2024.
Builds on
35 of 42 references.
References · 35
- 2017Attention Is All You Needcited by 60,361
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,399
- 2020An Image is Worth 16x16 Words: Transformers for Image Recognition at Scalecited by 30,186
- 2023GPT-4 Technical Reportcited by 18,396
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 14,132
- 2023Sparks of Artificial General Intelligence: Early experiments with GPT-4cited by 2,592
- 2023PaLM 2 Technical Reportcited by 1,162
- 2023Gemini: A Family of Highly Capable Multimodal Modelscited by 872
- 2022Transformers learn in-context by gradient descentcited by 732
- 2019Are Transformers universal approximators of sequence-to-sequence functions?cited by 406
- 2023Trained Transformers Learn Linear Models In-Contextcited by 337
- 2023Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selectioncited by 298
23 more
- 2023Transformers learn to implement preconditioned gradient descent for in-context learningcited by 279
- 2022Transformers Learn Shortcuts to Automatacited by 268
- 2021Inductive Biases and Variable Creation in Self-Attention Mechanismscited by 144
- 2023Representational Strengths and Limitations of Transformerscited by 133
- 2023What and How does In-Context Learning Learn? Bayesian Model Averaging, Parameterization, and Generalizationcited by 118
- 2024How Transformers Learn Causal Structure with Gradient Descentcited by 118
- 2023In-Context Convergence of Transformerscited by 115
- 2021Statistically Meaningful Approximation: a Case Study on Approximating Turing Machines with Transformerscited by 102
- 2023Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformercited by 102
- 2022Vision Transformers provably learn spatial structurecited by 93
- 2023How Do Transformers Learn Topic Structure: Towards a Mechanistic Understandingcited by 86
- 2021Why Do Pretrained Language Models Help in Downstream Tasks? An Analysis of Head and Prompt Tuningcited by 82
- 2023A Theoretical Understanding of Shallow Vision Transformers: Learning, Generalization, and Sample Complexitycited by 77
- 2024Training Dynamics of Multi-Head Softmax Attention for In-Context Learning: Emergence, Convergence, and Optimalitycited by 74
- 2023Max-Margin Token Selection in Attention Mechanismcited by 58
- 2023JoMA: Demystifying Multilayer Transformers via JOint Dynamics of MLP and Attentioncited by 52
- 2023Do Transformers Parse while Predicting the Masked Word?cited by 48
- 2024How Do Nonlinear Transformers Learn and Generalize in In-Context Learning?cited by 35
- 2024Implicit Bias and Fast Convergence Rates for Self-attentioncited by 31
- 2024Provably learning a multi-head attention layercited by 21
- 2024Implicit Optimization Bias of Next-Token Prediction in Linear Modelscited by 14
- 2023On the Convergence of Encoder-only Shallow Transformerscited by 13
- 2024A Theoretical Analysis of Self-Supervised Learning for Vision Transformerscited by 6
Built on by
Citing papers per year: 2025: 5; 2026: 4.
9 papers.
- 2025How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Biascited by 11
- 2025Bayes optimal learning of attention-indexed modelscited by 3
- 2026How Do Transformers Learn to Associate Tokens: Gradient Leading Terms Bring Mechanistic Interpretabilitycited by 3
- 2025How Can Mamba Learn In Context with Outliers and Generalize Provably?cited by 2
- 2026Incremental Learning of Sparse Attention Patterns in Transformerscited by 2
- 2025Attention with Trained Embeddings Provably Selects Important Tokenscited by 1
- 2026On the global convergence of gradient flow for wide shallow models beyond homogeneous nonlinearitiescited by 1
- 2025Mixture-of-Transformers Learn Faster: A Theoretical Study on Classification Problemscited by 0
- 2026Training Dynamics of Transformers on Unbounded Inputs: Attention Learning Can Lag Output Layer Learningcited by 0
- 2026Training Dynamics of Transformers on Unbounded Inputs: Attention Learning Can Lag Output Layer Learning14 Oct 2026
- 2026On the global convergence of gradient flow for wide shallow models beyond homogeneous nonlinearities11 May 2026
- 2026Incremental Learning of Sparse Attention Patterns in Transformers22 Feb 2026
- 2026How Do Transformers Learn to Associate Tokens: Gradient Leading Terms Bring Mechanistic Interpretability27 Jan 2026
- 2025Mixture-of-Transformers Learn Faster: A Theoretical Study on Classification Problems30 Oct 2025
- 2025How Can Mamba Learn In Context with Outliers and Generalize Provably?1 Oct 2025
- 2025Bayes optimal learning of attention-indexed models2 Jun 2025
- 2025Attention with Trained Embeddings Provably Selects Important Tokens22 May 2025
- 2025How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Bias2 May 2025