大模型用少数注意力头实现通用列表过滤,可跨任务复用。
LLMs Process Lists With General Filter Heads
- 通过注意力头在特定标记中编码过滤条件的紧凑表示。
- 提取的过滤逻辑可跨数据集、格式、语言复用,保持准确率95%以上。
- 发现模型既可用抽象函数式策略,也可直接存储真假标志,灵活应对不同场景。
我们研究了大模型在一系列列表处理任务中的机制,发现其已学会对通用过滤操作进行紧凑且因果性的表征,与函数式编程中的'filter'函数高度相似。通过因果中介分析,我们发现少量被称为'filter heads'的注意力头,在特定标记的查询状态中编码了过滤谓词的紧凑表示。实验表明该谓词表示具有泛化性和可移植性:可被提取并应用于不同集合、格式、语言或任务中,依然保持高精度(平均95.3%)。然而我们也识别出一种替代策略:模型会提前判断元素是否满足条件,并将中间结果以标志形式直接存储在元素表征中。结果表明,变压器语言模型能够发展出人类可解释的抽象计算操作实现,其泛化方式令人意外地接近传统函数式编程模式。
原文摘要 · Abstract (English)
We investigate the mechanisms underlying a range of list-processing tasks in LLMs, and we find that LLMs have learned to encode a compact, causal representation of a general filtering operation that mirrors the generic "filter" function of functional programming. Using causal mediation analysis on a diverse set of list-processing tasks, we find that a small number of attention heads, which we dub filter heads, encode a compact representation of the filtering predicate in their query states at certain tokens. We demonstrate that this predicate representation is general and portable: it can be extracted and reapplied to execute the same filtering operation on different collections, presented in different formats, languages, or even in tasks. However, we also identify situations where transformer LMs can exploit a different strategy for filtering: eagerly evaluating if an item satisfies the predicate and storing this intermediate result as a flag directly in the item representations. Our results reveal that transformer LMs can develop human-interpretable implementations of abstract computational operations that generalize in ways that are surprisingly similar to strategies used in traditional functional programming patterns.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。