Graph Conditioned Sparse-Attention for Improved Source Code Understanding

Junyan Cheng, Iordanis Fostiropoulos, Barry Boehm
12/1/2021
3 citations
cs.LGcs.PL
transformer-attention

Official code: chengjunyan1/Graph-Sparse-Transformer (7 stars, Python, Apache-2.0, last commit 2025-05-25).

Abstract

Transformer architectures have been successfully used in learning source code representations. The fusion between a graph representation like Abstract Syntax Tree (AST) and a source code sequence makes the use of current approaches computationally intractable for large input sequence lengths.

Show full abstract

Source code can have long-range dependencies that require larger sequence lengths to model effectively. Current approaches have a quadratic growth in computational and memory costs with respect to the sequence length. Using such models in practical scenarios is difficult. In this work, we propose the conditioning of a source code snippet with its graph modality by using the graph adjacency matrix as an attention mask for a sparse self-attention mechanism and the use of a graph diffusion mechanism to model longer-range token dependencies. Our model reaches state-of-the-art results in BLEU, METEOR, and ROUGE-L metrics for the code summarization task and near state-of-the-art accuracy in the variable misuse task. The memory use and inference time of our model have linear growth with respect to the input sequence length as compared to the quadratic growth of previous works.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

The official repository for the paper "Graph Conditioned Sparse-Attention for Improved Source Code Understanding".

70Python, ShellDec 1, 20211 years agoApache-2.0

Similar Papers

Cite this paper

@article{cheng2021graph,
  title  = {Graph Conditioned Sparse-Attention for Improved Source Code Understanding},
  author = {Junyan Cheng and Iordanis Fostiropoulos and Barry Boehm},
  year   = {2021},
  eprint = {2112.00663},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2112.00663}
}

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/2112.00663.svg)](https://codeofpaper.com/paper/2112.00663)

Discussion