该研究利用 Random Hierarchy Model 分析 Transformer 的组合推理,揭示层特化随训练逐步形成,并与不同泛化条件下的性能相关。
摘要:
Transformer 会在训练期间未观察过的序列上表现出组合推理能力,这种能力通常被归因于上下文学习(ICL)和技能组合。我们使用 Random Hierarchy Model(RHM)研究这一现象,该模型是一种通过递归规则应用生成序列的概率上下文无关文法。模型在序列子集上进行训练,并在四种泛化条件下评估:记忆、分布内泛化、使用相同规则的分布外泛化,以及跨层迁移。在行为层面,性能随任务复杂性和上下文示例数量系统性提升,而分布外任务比分布内场景需要显著更多的示例。在机制层面,我们发现训练过程中层特化会逐步出现,并且与泛化性能相关。主成分分析和注意力模式聚类表明,Transformer 会在特化层中形成结构化、按层级组织的表示。这些结果证明,Transformer 发展出了支持组合推理的模块化、可解释机制,将内部算法结构与观察到的行为能力联系起来。
英文摘要:
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.
School of Computer Science and Applied Mathematics, University of the Witwatersrand(金山大学计算机科学与应用数学学院);Gatsby Computational Neuroscience Unit(盖茨比计算神经科学单元);Sainsbury Wellcome Centre, UCL(伦敦大学学院桑斯伯里惠康中心);CIFAR(加拿大高级研究院)
Faith and Fate: Limits of Transformers on Compositionality
Allen Institute for Artificial Intelligence(艾伦人工智能研究所);University of Washington(华盛顿大学);University of Southern California(南加州大学);University of Chicago(芝加哥大学)
Shattered Compositionality: Counterintuitive Learning Dynamics of Transformers for Arithmetic
University of Wisconsin–Madison(威斯康星大学麦迪逊分校);Department of Computer Sciences, University of Wisconsin–Madison(威斯康星大学麦迪逊分校计算机科学系);Department of Statistics, University of Wisconsin–Madison(威斯康星大学麦迪逊分校统计学系)
Compositional Reasoning with Transformers, RNNs, and Chain of Thought
Courant Institute of Mathematical Sciences(Courant数学科学研究所);New York University(纽约大学);Center for Data Science(数据科学中心);Center for Computational Mathematics(计算数学中心);Flatiron Institute(Flatiron研究所)
Complexity Control Facilitates Reasoning-Based Compositional Generalization in Transformers
School of Artificial Intelligence, Shanghai Jiao Tong University(上海交通大学人工智能学院);Institute for Advanced Algorithms Research, Shanghai Seres Information Technology Co., Ltd(上海赛尔斯信息技术有限公司高级算法研究院)
Mixture-of-Transformers Learn Faster: A Theoretical Study on Classification Problems
Department of ECE The Ohio State University(电子工程系,俄亥俄州立大学);Department of CSE The Ohio State University(计算机科学与工程系,俄亥俄州立大学);Department of Computer Science University of Houston(计算机科学系,休斯顿大学);Department of ECE Department of CSE The Ohio State University(电子工程系、计算机科学与工程系,俄亥俄州立大学)
Initialization is Critical to Whether Transformers Fit Composite Functions by Reasoning or Memorizing
School of Mathematical Sciences, Shanghai Jiao Tong University(上海交通大学数学科学学院);Shanghai Seres Information Technology Co., Ltd(上海赛尔斯信息技术有限公司);Center for LLM, Institute for Advanced Algorithms Research(高级算法研究院大语言模型中心)
Rule Extrapolation in Language Models: A Study of Compositional Generalization on OOD Prompts
University of Cambridge(剑桥大学);AI Center, UCL(伦敦大学学院人工智能中心);Max Planck Institute for Intelligent Systems(马克斯·普朗克智能系统研究所);ELLIS Institute Tübingen(蒂宾根ELLIS研究所);Tübingen AI Center(蒂宾根人工智能中心)
Compositional Generalization with Tree Stack Memory Units
Carnegie Mellon University(卡内基梅隆大学);Johns Hopkins University(约翰斯·霍普金斯大学);University of Washington(华盛顿大学);University of California Irvine(加州大学欧文分校);California Institute of Technology(加州理工学院)