Transformer通过分层专业化实现组合推理,揭示其内部可解释机制。
Layer Specialization Underlying Compositional Reasoning in Transformers
- 用递归语法生成序列,研究模型在不同任务下的泛化能力。
- 层数越多、上下文样本越多,模型在分布外任务表现越好,需更多样例。
- 模型分层发展出层次化表示,各层专注不同推理层级,支持组合推理。
Transformers 在训练中未见的序列上表现出组合推理能力,常归因于上下文学习(ICL)和技能组合。本文采用随机层级模型(RHM),一种基于概率上下文无关语法的生成模型,通过递归规则生成序列。模型在子集序列上训练,并在四种泛化条件下评估:记忆、分布内泛化、分布外泛化(相同规则)、跨层迁移。行为上,性能随任务复杂度和上下文示例数量系统性提升,分布外任务需远多于分布内任务的示例。机制上,训练过程中逐步出现层专业化现象,与泛化性能相关。主成分分析和注意力模式聚类显示,Transformers 在专用层中发展出结构化、分层组织的表征。结果表明,Transformers 建立了模块化、可解释的机制以支持组合推理,将内部算法结构与行为能力关联。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。