arXiv:2410.20210cs.CLcs.LG2024-10ICML被引 13

Transformer按排名顺序逐步确定最高概率词元,揭示其内在决策机制。

Looking Beyond The Top-1: Transformers Determine Top Tokens In Order

  • 模型在输出前逐个锁定排名靠前的词元,顺序分明。
  • 即使未训练的Transformer也呈现此现象,说明是架构本质特性。
  • 可据此设计更高效的提前退出策略,兼顾准确与速度。

理解Transformer的内部运作对实现更准确高效的预测至关重要。本文分析了在最高概率词元确定后(即“饱和事件”)的后续计算过程,并将该概念扩展至top-k词元。我们发现,在语言、视觉和语音模型中,饱和事件按词元排名顺序依次发生:模型先确定第一高概率词元,再依次决定第二、第三等。这一现象似乎源于Transformer架构本身,出现在不同变体(仅解码器、仅编码器、完整Transformer)中,甚至在未训练模型中亦存在。我们提出任务切换机制作为解释:每个任务k对应预测第k个最可能词元,而饱和事件实质是任务间的离散切换。支持该观点的是,隐藏层嵌入可预测当前任务;通过干预方法,可促使模型跳转至下一任务。基于此,我们提出一种新型词元级早退出策略,在性能与效率间表现优于现有方法。

原文摘要 · Abstract (English)

Understanding the inner workings of Transformers is crucial for achieving more accurate and efficient predictions. In this work, we analyze the computation performed by Transformers in the layers after the top-1 prediction has become fixed, which has been previously referred to as the "saturation event". We expand the concept of saturation events for top-k tokens, demonstrating that similar saturation events occur across language, vision, and speech models. We find that these saturation events happen in order of the corresponding tokens' ranking, i.e., the model first decides on the top ranking token, then the second highest ranking token, and so on. This phenomenon seems intrinsic to the Transformer architecture, occurring across different architectural variants (decoder-only, encoder-only, and to a lesser extent full-Transformer), and even in untrained Transformers. We propose an underlying mechanism of task transition for this sequential saturation, where task k corresponds to predicting the k-th most probable token, and the saturation events are in fact discrete transitions between the tasks. In support of this we show that it is possible to predict the current task from hidden layer embedding. Furthermore, using an intervention method we demonstrate that we can cause the model to switch from one task to the next. Finally, leveraging our findings, we introduce a novel token-level early-exit strategy, which surpasses existing methods in balancing performance and efficiency.

Transformer注意力机制早退出模型解释

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。