How Transformers Learn Regular Language Recognition: A Theoretical Study on Training Dynamics and Implicit Bias
Ruiquan Huang, Yingbin Liang, Jing Yang
Abstract
Language recognition tasks are fundamental in natural language processing (NLP) and have been widely used to benchmark the performance of large language models (LLMs). These tasks also play a crucial role in explaining the working mechanisms of transformers. In this work, we focus on two representative tasks in the category of regular language recognition, known as 'even pairs' and 'parity check', the aim of which is to determine whether the occurrences of certain subsequences in a given sequence are even. Our goal is to explore how a one-layer transformer, consisting of an attention layer followed by a linear layer, learns to solve these tasks by theoretically analyzing its training dynamics under gradient descent. While even pairs can be solved directly by a one-layer transformer, parity check need to be solved by integrating Chain-of-Thought (CoT), either into the inference stage of a transformer well-trained for the even pairs task, or into the training of a one-layer transformer. For both problems, our analysis shows that the joint training of attention and linear layers exhibits two distinct phases. In the first phase, the attention layer grows rapidly, mapping data sequences into separable vectors. In the second phase, the attention layer becomes stable, while the linear layer grows logarithmically and approaches in direction to a max-margin hyperplane that correctly separates the attention layer outputs into positive and negative samples, and the loss decreases at a rate of O(1/t). Our experiments validate those theoretical results.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
3 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Transformers learn to implement preconditioned gradient descent for in-context learning cites One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attention
- One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attention cites Transformers learn to implement preconditioned gradient descent for in-context learning
- The Expressive Power of Transformers with Chain of Thought cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Unlabeled Data Can Provably Enhance In-Context Learning of Transformers cites Transformers learn to implement preconditioned gradient descent for in-context learning
- Unlabeled Data Can Provably Enhance In-Context Learning of Transformers cites One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-Attention
- Unlabeled Data Can Provably Enhance In-Context Learning of Transformers cites Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer Transformer
- Transformers with RL or SFT Provably Learn Sparse Boolean Functions, But Differently cites The Expressive Power of Transformers with Chain of Thought
- Transformers with RL or SFT Provably Learn Sparse Boolean Functions, But Differently cites Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
- Context-free Recognition with Transformers cites The Expressive Power of Transformers with Chain of Thought
Cited by top-tier papers3
- Unlabeled Data Can Provably Enhance In-Context Learning of TransformersRenpu Liu, Jing YangNeurIPS 2025 · 3 citations
- Context-free Recognition with TransformersSelim Jerad, Anej Svete, Sophie Hao, Ryan Cotterell et al.ICML 2026 · 3 citations
- Transformers with RL or SFT Provably Learn Sparse Boolean Functions, But DifferentlyBochen Lyu, Yiyang Jia, Xiaohao Cai, Zhanxing ZhuICML 2026
Builds on29
- Chain-of-Thought Prompting Elicits Reasoning in Large Language ModelsJason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma et al.NeurIPS 2022 · 22,562 citations
- Transformers learn to implement preconditioned gradient descent for in-context learningKwangjun Ahn, Xiang Cheng, Hadi Daneshmand, Suvrit SraNeurIPS 2023 · 324 citations
- The Expressive Power of Transformers with Chain of ThoughtWilliam Merrill, Ashish SabharwalICLR 2024 · 243 citations
- One Step of Gradient Descent is Provably the Optimal In-Context Learner with One Layer of Linear Self-AttentionArvind V. Mahankali, Tatsunori Hashimoto, Tengyu MaICLR 2024 · 160 citations
- Scan and Snap: Understanding Training Dynamics and Token Composition in 1-layer TransformerYuandong Tian, Yiping Wang, Beidi Chen, Simon S. DuNeurIPS 2023 · 125 citations
Related papers
- Transformers Provably Solve Parity Efficiently with Chain of ThoughtJuno Kim, Taiji SuzukiICLR 2025
- Overcoming a Theoretical Limitation of Self-AttentionDavid Chiang, Peter CholakACL 2022
- Task Generalization with Autoregressive Compositional Structure: Can Learning from D Tasks Generalize to DT Tasks?Amirhesam Abedsoltan, Huaqing Zhang, Kaiyue Wen, Hongzhou Lin et al.ICML 2025
- Training Dynamics of Transformers to Recognize Word Co-occurrence via Gradient Flow AnalysisHongru Yang, Bhavya Kailkhura, Zhangyang Wang, Yingbin LiangNeurIPS 2024 · 14 citations
- Transformers Learn to Implement Multi-step Gradient Descent with Chain of ThoughtJianhao Huang, Zixuan Wang, Jason D. LeeICLR 2025
