How Transformers Learn Causal Structure with Gradient Descent
Eshaan Nichani, Alex Damian, Jason D. Lee
摘要
The incredible success of transformers on sequence modeling tasks can be largely attributed to the self-attention mechanism, which allows information to be transferred between different parts of a sequence. Self-attention allows transformers to encode causal structure which makes them particularly suitable for sequence modeling. However, the process by which transformers learn such causal structure via gradient-based training algorithms remains poorly understood. To better understand this process, we introduce an in-context learning task that requires learning latent causal structure. We prove that gradient descent on a simplified two-layer transformer learns to solve this task by encoding the latent causal graph in the first attention layer. The key insight of our proof is that the gradient of the attention matrix encodes the mutual information between tokens. As a consequence of the data processing inequality, the largest entries of this gradient correspond to edges in the latent causal graph. As a special case, when the sequences are generated from in-context Markov chains, we prove that transformers learn an induction head (Olsson et al., 2022). We confirm our theoretical findings by showing that transformers trained on our in-context learning task are able to recover a wide variety of causal structures.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 86 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers 引用了 An Explanation of In-context Learning as Implicit Bayesian Inference
- Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers 引用了 Language Models are Few-Shot Learners
- Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers 引用了 Iteration Head: A Mechanistic Study of Chain-of-Thought
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale 引用了 Language Models are Few-Shot Learners
- An Explanation of In-context Learning as Implicit Bayesian Inference 引用了 Language Models are Few-Shot Learners
- Decision Transformer: Reinforcement Learning via Sequence Modeling 引用了 An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Decision Transformer: Reinforcement Learning via Sequence Modeling 引用了 Language Models are Few-Shot Learners
- The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains 引用了 An Explanation of In-context Learning as Implicit Bayesian Inference
- The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains 引用了 Language Models are Few-Shot Learners
- The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains 引用了 What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- In-Context Learning with Representations: Contextual Generalization of Trained Transformers 引用了 An Explanation of In-context Learning as Implicit Bayesian Inference
- In-Context Learning with Representations: Contextual Generalization of Trained Transformers 引用了 The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains
- In-Context Learning with Representations: Contextual Generalization of Trained Transformers 引用了 Language Models are Few-Shot Learners
- In-Context Learning with Representations: Contextual Generalization of Trained Transformers 引用了 What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Iteration Head: A Mechanistic Study of Chain-of-Thought 引用了 An Explanation of In-context Learning as Implicit Bayesian Inference
- Iteration Head: A Mechanistic Study of Chain-of-Thought 引用了 The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains
- Iteration Head: A Mechanistic Study of Chain-of-Thought 引用了 Language Models are Few-Shot Learners
- Iteration Head: A Mechanistic Study of Chain-of-Thought 引用了 What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- What Can Transformers Learn In-Context? A Case Study of Simple Function Classes 引用了 An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- What Can Transformers Learn In-Context? A Case Study of Simple Function Classes 引用了 An Explanation of In-context Learning as Implicit Bayesian Inference
- What Can Transformers Learn In-Context? A Case Study of Simple Function Classes 引用了 Language Models are Few-Shot Learners
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks 引用了 Language Models are Few-Shot Learners
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks 引用了 What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
引用它的顶会 Paper86
- The Evolution of Statistical Induction Heads: In-Context Learning Markov ChainsEzra Edelman, Nikolaos Tsilivis, Benjamin L. Edelman, Eran Malach 等NeurIPS 2024 · 140 次引用
- Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasksTianyu He, Darshil Doshi, Aritra Das, Andrey GromovNeurIPS 2024 · 52 次引用
- Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in TransformersSiyu Chen, Heejune Sheen, Tianhao Wang, Zhuoran YangNeurIPS 2024 · 48 次引用
- In-Context Learning with Representations: Contextual Generalization of Trained TransformersTong Yang, Yu Huang, Yingbin Liang, Yuejie ChiNeurIPS 2024 · 45 次引用
- Iteration Head: A Mechanistic Study of Chain-of-ThoughtVivien Cabannes, Charles Arnal, Wassim Bouaziz, Xingyu Yang 等NeurIPS 2024 · 44 次引用
它引用的 Paper21
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah 等NeurIPS 2020 · 64,255 次引用
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn 等ICLR 2021 · 21,477 次引用
- Decision Transformer: Reinforcement Learning via Sequence ModelingLili Chen, Kevin Lu, Aravind Rajeswaran, Kimin Lee 等NeurIPS 2021 · 2,557 次引用
- An Explanation of In-context Learning as Implicit Bayesian InferenceSang Michael Xie, Aditi Raghunathan, Percy Liang, Tengyu MaICLR 2022 · 1,030 次引用
- What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 次引用
相关 Paper
- Selective induction Heads: How Transformers Select Causal Structures in ContextFrancesco D'Angelo, Francesco Croce, Nicolas FlammarionICLR 2025
- Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento 等ICML 2023 · 729 次引用
- What One Cannot, Two Can: Two-Layer Transformers Provably Represent Induction Heads on Any-Order Markov ChainsChanakya Ekbote, Ashok Vardhan Makkuva, Marco Bondaschi, Nived Rajaraman 等NeurIPS 2025 · 4 次引用
- How Transformers Learn Causal Structures In-Context: Explainable Mechanism Meets Theoretical GuaranteeJianzhe Wei, Siyu Chen, Jianliang He, Zhuoran YangICLR 2026
- Transformers Learn Latent Mixture Models In-Context via Mirror DescentFrancesco D'Angelo, Nicolas FlammarionICLR 2026 · 2 次引用
