通过代码数据挖掘注意力模式,实现大模型可扩展的可解释性分析。
Automated Attention Pattern Discovery at Scale in Large Language Models
- 利用代码结构化特性挖掘大模型中的重复注意力模式。
- AP-MAE模型能高精度重建注意力图,跨模型泛化且预测生成正确性。
- 结果可用于精准干预提升性能,适合大规模可解释性研究者使用。
大语言模型虽因规模扩展取得成功,但其可解释性方法仍难以规模化。当前机制可解释性多聚焦于特定行为的精确解释,缺乏泛化性或资源消耗过大。本文通过挖掘Java代码数据集中的生成场景,利用代码结构特性,收集注意力头生成的注意力模式,证明其可作为模型组件全局可解释性的可扩展信号。引入基于视觉变换器的注意力模式掩码自编码器(AP-MAE),高效重建被遮蔽的注意力模式。在StarCoder2上的实验表明:(i) AP-MAE能高精度重建注意力模式;(ii) 跨未见模型泛化性能下降小;(iii) 揭示推理中反复出现的模式;(iv) 无需真实标签即可预测生成正确性,准确率55%至70%不等;(v) 选择性应用可使准确率提升13.6%,但过度应用会导致模型崩溃。这些结果确立注意力模式为可扩展的可解释信号,并证明AP-MAE为分析与干预提供可迁移基础。此外,该模型还可用于引导细粒度机制研究。代码与模型已开源,支持未来大规模可解释性研究。
原文摘要 · Abstract (English)
Large language models have found success by scaling up capabilities to work in general settings. The same can unfortunately not be said for interpretability methods. The current trend in mechanistic interpretability is to provide precise explanations of specific behaviors in controlled settings. These often do not generalize, or are too resource intensive for larger studies. In this work we propose to study repeated behaviors in large language models by mining completion scenarios in Java code datasets, through exploiting the structured nature of code. We collect the attention patterns generated in the attention heads to demonstrate that they are scalable signals for global interpretability of model components. We show that vision models offer a promising direction for analyzing attention patterns at scale. To demonstrate this, we introduce the Attention Pattern - Masked Autoencoder(AP-MAE), a vision transformer-based model that efficiently reconstructs masked attention patterns. Experiments on StarCoder2 show that AP-MAE (i) reconstructs masked attention patterns with high accuracy, (ii) generalizes across unseen models with minimal degradation, (iii) reveals recurring patterns across inferences, (iv) predicts whether a generation will be correct without access to ground truth, with accuracies ranging from 55% to 70% depending on the task, and (v) enables targeted interventions that increase accuracy by 13.6% when applied selectively, but cause collapse when applied excessively. These results establish attention patterns as a scalable signal for interpretability and demonstrate that AP-MAE provides a transferable foundation for both analysis and intervention in large language models. Beyond its standalone value, AP-MAE also serves as a selection procedure to guide fine-grained mechanistic approaches. We release code and models to support future work in large-scale interpretability.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。