跳到正文
arXiv:cs.LG· Amiri Hayes, Belinda Z Li, Jacob Andreas·· 7 小时前AI 评分51

用程序合成解释 Transformer 注意力头

Explaining Attention with Program Synthesis

AI 导读

MIT 研究者(Amiri Hayes、Belinda Z Li、Jacob Andreas)提出用程序合成近似 Transformer 语言模型注意力头行为的方法:先在随机训练样本上计算注意力矩阵,再提示预训练语言模型生成可复现这些注意力模式的 Python 程序,并按在留出输入上的预测效果重排序。

正文

View PDF HTML (experimental)

Abstract: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.
Subjects: Machine Learning (cs.LG); Artificial Intelligence (cs.AI)
Cite as: arXiv:2606.19317 [cs.LG]
  (or arXiv:2606.19317v3 [cs.LG] for this version)
  https://doi.org/10.48550/arXiv.2606.19317

arXiv-issued DOI via DataCite

Submission history

From: Amiri Hayes [view email]
[v1] Wed, 17 Jun 2026 17:40:55 UTC (644 KB)
[v2] Mon, 29 Jun 2026 15:31:17 UTC (644 KB)
[v3] Tue, 6 Oct 2026 05:46:25 UTC (790 KB)

来源:arXiv:cs.LG · arxiv.org