arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2404.05767cs.SEcs.AI
收藏

CSA-Trans:面向 AST 的代码结构感知 Transformer

CSA-Trans: Code Structure Aware Transformer for AST

KAIST(韩国科学技术院)

Saeyoon Oh, Shin Yoo

AI总结:

提出 CSA-Trans,通过 CSE 解耦注意力生成 AST 节点位置编码并结合 SBM 注意力,在 Python 和 Java 代码摘要任务上优于 14 个基线且更高效。

摘要:

将 Transformer 架构应用于源代码时,设计良好的自注意力机制至关重要,因为它会影响如何从源代码的抽象语法树(AST)中提取节点关系。我们提出了 Code Structure Aware Transformer(CSA-Trans,代码结构感知 Transformer),它使用 Code Structure Embedder(CSE,代码结构嵌入器)为 AST 中的每个节点生成特定的 PE。CSE 利用解耦注意力生成节点位置编码(PE)。为进一步扩展自注意力能力,我们采用了随机块模型(SBM)注意力。评估表明,与其他图相关 PE 技术相比,我们的 PE 能更好地捕捉 AST 节点之间的关系。我们还通过定量和定性分析表明,SBM 注意力能够生成更多节点特定的注意力系数。实验证明,在 Python 和 Java 的代码摘要任务上,CSA-Trans 优于 14 个基线;在 Java 数据集上,与 AST-Trans 和 SG-Trans 相比,其速度分别提升 41.92%,内存效率分别提高 25.31%。

英文摘要:

When applying the Transformer architecture to source code, designing a good self-attention mechanism is critical as it affects how node relationship is extracted from the Abstract Syntax Trees (ASTs) of the source code. We present Code Structure Aware Transformer (CSA-Trans), which uses Code Structure Embedder (CSE) to generate specific PE for each node in AST. CSE generates node Positional Encoding (PE) using disentangled attention. To further extend the self-attention capability, we adopt Stochastic Block Model (SBM) attention. Our evaluation shows that our PE captures the relationships between AST nodes better than other graph-related PE techniques. We also show through quantitative and qualitative analysis that SBM attention is able to generate more node specific attention coefficients. We demonstrate that CSA-Trans outperforms 14 baselines in code summarization tasks for both Python and Java, while being 41.92% faster and 25.31% memory efficient in Java dataset compared to AST-Trans and SG-Trans respectively.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑