paperbot · PL 论文追踪

全部论文 待读 收藏

P2 AST-trans

AST-Trans:面向代码摘要的树结构注意力编码
ICSE Proceedings of the 44th International Conference on Software Engineering2022匹配度 2/10 · 该论文属于深度学习驱动的代码摘要任务,核心是改进 AST 的树结构注意力编码,既不做静态分析、也不涉及 LLM/Agent,更与浮点程序分析、贝叶斯程序分析无关;仅在“AST 作为程序结构表示”这一点上与研究方向有非常间接的交集。引用 60 inbox
Ze Tang, Xiaoyu Shen, Chuanyi Li, Jidong Ge, Liguo Huang, Zhelin Zhu, Bin Luo
crossref: 2026-09-12

AI 速览

一句话:提出 AST-Trans,利用祖先-后代与兄弟关系施加树结构注意力编码 AST,实现更准更快的代码摘要。

代码摘要旨在为源代码生成简短的自然语言描述,当前主流方法采用基于 Transformer 的编码器-解码器架构,并借助抽象语法树(AST)编码结构信息。然而 AST 比对应源码长得多,已有工作忽略其长度约束,直接将整棵线性化 AST 送入编码器。作者认为这种做法既难以从过长序列中提取真正有用的依赖关系,也因每个节点都要与所有其他节点做自注意力而带来显著计算开销。为此本文提出 AST-Trans,利用 AST 中两类节点关系——祖先-后代关系与兄弟关系——施加树结构注意力,据此动态为相关节点分配权重并排除无关节点,同时给出支持快速并行计算的高效实现。在两个代码摘要数据集上,AST-Trans 显著优于现有最优方法,且效率为标准 Transformer 的数倍。

问题
现有代码摘要方法将整棵线性化 AST 直接输入 Transformer 编码器,忽略其长度约束,导致难以提取有效依赖关系且自注意力计算开销巨大。
方法
利用 AST 中祖先-后代与兄弟两类关系设计树结构注意力,动态为相关节点分配权重、屏蔽无关节点,并提出支持快速并行计算的高效实现。
评估
在两个代码摘要数据集上与现有最优方法对比,结果显示 AST-Trans 在摘要质量上显著领先,且效率比标准 Transformer 高数倍。
原文摘要(Abstract)

Code summarization aims to generate brief natural language descriptions for source codes. The state-of-the-art approaches follow a transformer-based encoder-decoder architecture. As the source code is highly structured and follows strict grammars, its Abstract Syntax Tree (AST) is widely used for encoding structural information. However, ASTs are much longer than the corresponding source code. Existing approaches ignore the size constraint and simply feed the whole linearized AST into the encoders. We argue that such a simple process makes it difficult to extract the truly useful dependency relations from the overlong input sequence. It also incurs significant computational overhead since each node needs to apply self-attention to all other nodes in the AST. To encode the AST more effectively and efficiently, we propose AST-Trans in this paper which exploits two types of node relationships in the AST: ancestor-descendant and sibling relationships. It applies the tree-structured attention to dynamically allocate weights for relevant nodes and exclude irrelevant nodes based on these two relationships. We further propose an efficient implementation to support fast parallel computation for tree-structure attention. On the two code summarization datasets, experimental results show that AST-Trans significantly outperforms the state-of-the-arts while being times more efficient than standard transformers1.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot6917,
  title = {AST-trans},
  author = {Ze Tang and Xiaoyu Shen and Chuanyi Li and Jidong Ge and Liguo Huang and Zhelin Zhu and Bin Luo},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510224}
}