Lune

ICML2024Top-tier venue

How Transformers Learn Causal Structure with Gradient Descent

Eshaan Nichani, Alex Damian, Jason D. Lee

Abstract

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.

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.

86 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites An Explanation of In-context Learning as Implicit Bayesian Inference
  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites Language Models are Few-Shot Learners
  • Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers cites Iteration Head: A Mechanistic Study of Chain-of-Thought
  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale cites Language Models are Few-Shot Learners
  • An Explanation of In-context Learning as Implicit Bayesian Inference cites Language Models are Few-Shot Learners
  • Decision Transformer: Reinforcement Learning via Sequence Modeling cites An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • Decision Transformer: Reinforcement Learning via Sequence Modeling cites Language Models are Few-Shot Learners
  • The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains cites An Explanation of In-context Learning as Implicit Bayesian Inference
  • The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains cites Language Models are Few-Shot Learners
  • The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • In-Context Learning with Representations: Contextual Generalization of Trained Transformers cites An Explanation of In-context Learning as Implicit Bayesian Inference
  • In-Context Learning with Representations: Contextual Generalization of Trained Transformers cites The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains
  • In-Context Learning with Representations: Contextual Generalization of Trained Transformers cites Language Models are Few-Shot Learners
  • In-Context Learning with Representations: Contextual Generalization of Trained Transformers cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
  • Iteration Head: A Mechanistic Study of Chain-of-Thought cites An Explanation of In-context Learning as Implicit Bayesian Inference
  • Iteration Head: A Mechanistic Study of Chain-of-Thought cites The Evolution of Statistical Induction Heads: In-Context Learning Markov Chains
  • Iteration Head: A Mechanistic Study of Chain-of-Thought cites Language Models are Few-Shot Learners
  • Iteration Head: A Mechanistic Study of Chain-of-Thought cites 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 cites 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 cites An Explanation of In-context Learning as Implicit Bayesian Inference
  • What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Language Models are Few-Shot Learners
  • Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks cites Language Models are Few-Shot Learners
  • Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers86

  1. The Evolution of Statistical Induction Heads: In-Context Learning Markov ChainsEzra Edelman, Nikolaos Tsilivis, Benjamin L. Edelman, Eran Malach et al.NeurIPS 2024 · 140 citations
  2. Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasksTianyu He, Darshil Doshi, Aritra Das, Andrey GromovNeurIPS 2024 · 52 citations
  3. Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in TransformersSiyu Chen, Heejune Sheen, Tianhao Wang, Zhuoran YangNeurIPS 2024 · 48 citations
  4. In-Context Learning with Representations: Contextual Generalization of Trained TransformersTong Yang, Yu Huang, Yingbin Liang, Yuejie ChiNeurIPS 2024 · 45 citations
  5. Iteration Head: A Mechanistic Study of Chain-of-ThoughtVivien Cabannes, Charles Arnal, Wassim Bouaziz, Xingyu Yang et al.NeurIPS 2024 · 44 citations

Builds on21

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn et al.ICLR 2021 · 21,477 citations
  3. Decision Transformer: Reinforcement Learning via Sequence ModelingLili Chen, Kevin Lu, Aravind Rajeswaran, Kimin Lee et al.NeurIPS 2021 · 2,557 citations
  4. An Explanation of In-context Learning as Implicit Bayesian InferenceSang Michael Xie, Aditi Raghunathan, Percy Liang, Tengyu MaICLR 2022 · 1,030 citations
  5. What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations

Related papers

  1. Selective induction Heads: How Transformers Select Causal Structures in ContextFrancesco D'Angelo, Francesco Croce, Nicolas FlammarionICLR 2025
  2. Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations
  3. 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 et al.NeurIPS 2025 · 4 citations
  4. How Transformers Learn Causal Structures In-Context: Explainable Mechanism Meets Theoretical GuaranteeJianzhe Wei, Siyu Chen, Jianliang He, Zhuoran YangICLR 2026
  5. Transformers Learn Latent Mixture Models In-Context via Mirror DescentFrancesco D'Angelo, Nicolas FlammarionICLR 2026 · 2 citations
Dusk over the sea between two cliffs drawn in fine vertical lines