arXiv:2606.19317cs.LGcs.AI2026-06被引 1

用可执行代码解释Transformer注意力头行为,让黑箱变透明。

Explaining Attention with Program Synthesis

论文配图:Explaining Attention with Program Synthesis
图 1 · 摘自论文原文
  • 用程序合成方法生成能复现注意力模式的Python代码
  • 仅用不到1000个程序就实现75%以上注意力模式相似度
  • 替换25%注意力头后模型性能基本不变,适合想理解模型的开发者

可解释深度学习的核心目标之一是用人类可理解的符号化描述替代神经网络的黑箱计算。本文提出一种方法,通过可执行程序近似深度网络组件的行为。研究聚焦于Transformer语言模型中的注意力头。对于每个注意力头,首先在随机选取的训练样本上计算其注意力矩阵;接着,用这些矩阵的摘要提示预训练语言模型,要求其生成一组能仅凭输入文本重现相应注意力模式的Python程序;最后,根据程序在保留输入上的预测表现对它们进行重排序。实验表明,少于1000个生成程序即可在TinyStories数据集上复现GPT-2、TinyLlama-1.1B和Llama-3B中注意力头的注意力模式,平均交并比(IoU)超过75%。此外,用程序替代25%的注意力头后,模型平均困惑度仅上升16%,同时在多种下游问答任务上保持性能。该工作构建了一条可扩展的管线,实现基于人类可读代码的注意力头逆向工程,推动神经模型的符号化透明化。

原文摘要 · Abstract (English)

A longstanding goal of research on interpretable deep learning is to replace opaque neural computations with human-meaningful symbolic descriptions. In this paper, we propose an approach for approximating the behavior of components of deep networks with executable programs. We focus on attention heads in transformer language models. For a given head, we first compute its associated attention matrices on a collection of randomly selected training examples. Next, we prompt a pre-trained language model with a summary of these matrices, and instruct it to generate a set of Python programs that can reproduce the associated attention patterns given only text from the input sentence. Finally, we re-rank programs according to how well our final set of programs predict behavior on held-out inputs. We demonstrate that a set of fewer than 1,000 such generated programs can reproduce the attention patterns of heads in GPT-2, TinyLlama-1.1B, and Llama-3B, achieving an average Intersection-over-Union similarity above 75% on TinyStories. Moreover, the best-fit programs can replace neural attention heads without substantially affecting model behavior: replacing 25% of attention heads with programmatic surrogates across the three models incurs only a 16% average perplexity increase, while maintaining performance on a variety of downstream question answering benchmarks. This work contributes a scalable pipeline for reverse-engineering attention heads in transformer models using human-readable, executable code, advancing a path toward symbolic transparency in neural models.

注意力机制程序合成可解释性Transformer

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