arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2505.05145cs.LGcs.AIcs.CL
收藏

通过激活子空间理解上下文学习中的加法运算

Understanding In-context Learning of Addition via Activation Subspaces

UC Berkeley(伯克利大学);INRIA(法国国家信息与自动化研究所)

Xinyan Hu, Kayo Yin, Michael I. Jordan, Jacob Steinhardt, Lijie Chen

AI总结:

本文通过激活子空间分析,将Llama-3-8B-instruct的少样本加法能力简化为三个注意力头的六维子空间,并揭示其信息聚合与自我纠正机制。

摘要:

为了进行少样本学习,语言模型从少量输入-标签对中提取信号,将这些信号聚合为学到的预测规则,并将该规则应用于新输入。这在现代Transformer模型的前向传播中是如何实现的?为了探索这一问题,我们研究了一类结构化的少样本学习任务,其中真实的预测规则是将整数$k$加到输入上。我们提出了一种新颖的优化方法,将模型的少样本能力定位到仅少数几个注意力头上。随后,我们通过降维和分解对单个注意力头进行了深入分析。例如,在Llama-3-8B-instruct上,我们将任务中的机制简化为仅三个注意力头,具有六维子空间,其中四个维度通过周期为$2$、$5$和$10$的三角函数跟踪个位数字,两个维度通过低频分量跟踪数量级。为了加深对机制的理解,我们还推导了一个数学恒等式,将注意力头的“聚合”和“提取”子空间联系起来,使我们能够追踪从单个示例到最终聚合概念的信息流。利用这一点,我们识别出一种自我纠正机制,其中早期演示中学到的错误会被后续演示抑制。我们的结果表明,在前向传播中跟踪局部化头的低维子空间可以提供对语言模型中细粒度计算结构的洞察。

英文摘要:

To perform few-shot learning, language models extract signals from a few input-label pairs, aggregate them into a learned prediction rule, and apply this rule to new inputs. How is this implemented in the forward pass of modern transformer models? To explore this question, we study a structured family of few-shot learning tasks for which the true prediction rule is to add an integer $k$ to the input. We introduce a novel method that localizes the model's few-shot learning ability to only a few attention heads. This method and the findings generalize to four additional task families spanning arithmetic and semantic tasks. We then perform an in-depth analysis of individual heads via dimensionality reduction and decomposition of the heads' output spaces. For example, in Llama-3-8B-Instruct, we reduce the mechanism underlying these tasks to just three attention heads with six-dimensional subspaces, in which four dimensions track the units digit using trigonometric functions with periods $2$, $5$, and $10$, while two dimensions track magnitude using low-frequency components. To deepen our understanding of this mechanism, we also derive a mathematical identity relating the ''aggregator'' and ''extractor'' subspaces of attention heads, allowing us to track the flow of information from individual examples to a final aggregated concept. Our results demonstrate how tracking low-dimensional subspaces of localized heads throughout a forward pass can provide insight into fine-grained computational structures in language models. Our code is available at https://github.com/xyVickyHu/addition-subspaces.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑