CSA-Trans: Code Structure Aware Transformer for AST

Saeyoon Oh, Shin Yoo
4/7/2024
cs.SEcs.AI

No official code found. Best implementation: saeyoon17/Code-Structure-Aware-Transformer (6 stars, last commit 2023-10-30).

Abstract

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.

View on arXivView PDF

Code Implementations(1)

Replication package for CSA-Trans

60Python, Jupyter NotebookFeb 3, 20232 years ago

Similar Papers

Cite this paper

@article{oh2024csatrans,
  title  = {CSA-Trans: Code Structure Aware Transformer for AST},
  author = {Saeyoon Oh and Shin Yoo},
  year   = {2024},
  eprint = {2404.05767},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.05767v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2404.05767.svg)](https://codeofpaper.com/paper/2404.05767)

Discussion