Layer Specialization Underlying Compositional Reasoning in Transformers
Not on the map. Why?
Abstract (arXiv)
Transformers exhibit compositional reasoning on sequences not observed during training, a capability often attributed to in-context learning (ICL) and skill composition. We investigate this phenomenon using the Random Hierarchy Model (RHM), a probabilistic context-free grammar that generates sequences through recursive rule application. Models are trained on subsets of sequences and evaluated across four generalization conditions: memorization, in-distribution generalization, out-of-distribution generalization with the same rules, and cross-layer transfer. Behaviorally, performance improves systematically with task complexity and the number of in-context examples, with out-of-distribution tasks requiring substantially more examples than in-distribution scenarios. Mechanistically, we identify a progressive emergence of layer specialization during training that correlates with generalization performance. Principal component analysis and attention pattern clustering reveal that transformers develop structured, hierarchically organized representations in specialized layers. These results demonstrate that transformers develop modular, interpretable mechanisms supporting compositional reasoning, linking internal algorithmic structure to observed behavioral capabilities.
Key facts. No citing papers in the map yet (data through 7 Oct 2026). Builds on 14 of its 20 references that are in the map. First posted on arXiv 20 Oct 2025.
Builds on
14 of 20 references.
References · 14
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2020Transformer Feed-Forward Layers Are Key-Value Memoriescited by 1,307
- 2022Toy Models of Superpositioncited by 928
- 2021An Explanation of In-context Learning as Implicit Bayesian Inferencecited by 915
- 2022Transformers learn in-context by gradient descentcited by 714
- 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 700
- 2022What learning algorithm is in-context learning? Investigations with linear modelscited by 671
- 2022Transformer Feed-Forward Layers Build Predictions by Promoting Concepts in the Vocabulary Spacecited by 522
- 2019Measuring Compositional Generalization: A Comprehensive Method on Realistic Datacited by 280
- 2023Physics of Language Models: Part 3.1, Knowledge Storage and Extractioncited by 264
- 2022Omnigrok: Grokking Beyond Algorithmic Datacited by 142
- 2023A Tale of Two Circuits: Grokking as Competition of Sparse and Dense Subnetworkscited by 78
2 more
Built on by
Not cited yet.