Source Code Summarization with Structural Relative Position Guided Transformer

02/14/2022
by   Zi Gong, et al.
0

Source code summarization aims at generating concise and clear natural language descriptions for programming languages. Well-written code summaries are beneficial for programmers to participate in the software development and maintenance process. To learn the semantic representations of source code, recent efforts focus on incorporating the syntax structure of code into neural networks such as Transformer. Such Transformer-based approaches can better capture the long-range dependencies than other neural networks including Recurrent Neural Networks (RNNs), however, most of them do not consider the structural relative correlations between tokens, e.g., relative positions in Abstract Syntax Trees (ASTs), which is beneficial for code semantics learning. To model the structural dependency, we propose a Structural Relative Position guided Transformer, named SCRIPT. SCRIPT first obtains the structural relative positions between tokens via parsing the ASTs of source code, and then passes them into two types of Transformer encoders. One Transformer directly adjusts the input according to the structural relative distance; and the other Transformer encodes the structural relative positions during computing the self-attention scores. Finally, we stack these two types of Transformer encoders to learn representations of source code. Experimental results show that the proposed SCRIPT outperforms the state-of-the-art methods by at least 1.6 datasets, respectively. We further show that how the proposed SCRIPT captures the structural relative dependencies.

READ FULL TEXT

page 1

page 3

research
05/01/2020

A Transformer-based Approach for Source Code Summarization

Generating a readable summary that describes the functionality of a prog...
research
04/19/2021

Code Structure Guided Transformer for Source Code Summarization

Source code summarization aims at generating concise descriptions of giv...
research
11/17/2021

GN-Transformer: Fusing Sequence and Graph Representation for Improved Code Summarization

As opposed to natural languages, source code understanding is influenced...
research
12/29/2020

SIT3: Code Summarization with Structure-Induced Transformer

Code summarization (CS) is becoming a promising area in recent natural l...
research
12/01/2021

Graph Conditioned Sparse-Attention for Improved Source Code Understanding

Transformer architectures have been successfully used in learning source...
research
04/19/2019

Learning Programmatic Idioms for Scalable Semantic Parsing

Programmers typically organize executable source code using high-level c...
research
05/11/2022

CV4Code: Sourcecode Understanding via Visual Code Representations

We present CV4Code, a compact and effective computer vision method for s...

Please sign up or login with your details

Forgot password? Click here to reset