[论文解读] How Do Transformers Learn Topic Structure: Towards a Mechanistic Understanding
该论文通过使用来自潜在狄利克雷分配(LDA)模型的合成数据,提供了对单层变换器如何在嵌入和自注意力机制中学习并编码主题结构的机制性理解。它在标准训练动态下,从数学上证明了词嵌入和注意力权重自然地捕捉到主题共现模式——即同一主题内的词具有更高的相似性和注意力,即使仅训练其中一个组件(嵌入或注意力)也能实现。
While the successes of transformers across many domains are indisputable, accurate understanding of the learning mechanics is still largely lacking. Their capabilities have been probed on benchmarks which include a variety of structured and reasoning tasks -- but mathematical understanding is lagging substantially behind. Recent lines of work have begun studying representational aspects of this question: that is, the size/depth/complexity of attention-based networks to perform certain tasks. However, there is no guarantee the learning dynamics will converge to the constructions proposed. In our paper, we provide fine-grained mechanistic understanding of how transformers learn "semantic structure", understood as capturing co-occurrence structure of words. Precisely, we show, through a combination of mathematical analysis and experiments on Wikipedia data and synthetic data modeled by Latent Dirichlet Allocation (LDA), that the embedding layer and the self-attention layer encode the topical structure. In the former case, this manifests as higher average inner product of embeddings between same-topic words. In the latter, it manifests as higher average pairwise attention between same-topic words. The mathematical results involve several assumptions to make the analysis tractable, which we verify on data, and might be of independent interest as well.
研究动机与目标
- 理解变换器从训练数据中学习语义主题结构的机制基础。
- 研究嵌入层和自注意力机制是否以及如何独立地编码主题共现模式。
- 在简化且可分析的设置(单层变换器在LDA生成的数据上)中分析训练动态,以隔离学习机制。
- 验证主题结构在真实世界数据(如维基百科)中是否稳健学习,而不仅限于合成分布。
- 证明当一个组件(嵌入层或注意力机制)被冻结时,另一个仍能补偿并学习主题结构,表明其在表征能力上存在结构冗余。
提出的方法
- 使用来自潜在狄利克雷分配(LDA)模型生成的合成数据,创建具有已知主题-词关系的受控、结构化分布。
- 使用掩码语言建模范式训练单层变换器,通过改变哪些组件(嵌入或注意力矩阵)可训练来实现。
- 形式化并证明两个关键定理:其一表明最优嵌入通过提高同主题词对的内积来编码主题结构;其二表明当嵌入固定时,注意力矩阵也能学习到类似结构。
- 通过按句子长度缩放注意力权重,对注意力权重进行去偏归一化,以隔离由长度引起的偏差。
- 通过主题似然和模糊度阈值筛选词语,聚焦于核心主题相关标记,提升可解释性并减少噪声。
- 在真实维基百科数据上使用预训练的BERT、RoBERTa、ELECTRA等模型验证发现,比较同主题与不同主题的嵌入相似性及注意力权重。
实验结果
研究问题
- RQ1在LDA生成数据上训练的单层变换器中,其嵌入权重如何学习反映主题结构?
- RQ2当词嵌入被固定为独热向量时,自注意力机制能否独立学习主题结构?
- RQ3训练动态在主题结构出现过程中起什么作用?该过程是否在不同优化器和超参数下遵循两阶段模式(先嵌入,后注意力)?
- RQ4在真实世界预训练模型(如BERT和RoBERTa)中,嵌入和注意力中的主题结构在多大程度上得以保留?
- RQ5句子长度偏差在多大程度上影响注意力权重比较?如何校正这些偏差以隔离基于主题的注意力模式?
主要发现
- 在LDA生成数据上训练的单层变换器中,其嵌入层通过定理1证明,会为同主题词对分配更高的内积。
- 当嵌入被固定为独热向量时,自注意力机制(特别是值矩阵)通过定理3的形式化证明,会为同主题词对分配更高的注意力权重。
- 在合成LDA数据上,嵌入相似性和注意力权重均表现出明显的分块模式,对应于主题结构,同主题词对始终优于不同主题词对。
- 在真实维基百科数据上,如BERT和RoBERTa等预训练模型显示,经长度去偏后,同主题词对之间的平均注意力权重比不同主题词对高出1.12至1.70倍。
- 去偏后,随机初始化的BERT模型在同主题与不同主题词对之间的平均注意力无显著差异,确认主题结构仅在训练后才出现。
- 即使一个组件(嵌入或注意力)被冻结,另一个仍能学习并保持主题结构,表明模型表征能力中存在一种机制冗余。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。