Skip to main content
QUICK REVIEW

[Paper Review] GN-Transformer: Fusing Sequence and Graph Representation for Improved Code Summarization

Junyan Cheng, Iordanis Fostiropoulos|arXiv (Cornell University)|Nov 17, 2021
Software Engineering ResearchComputer Science40 references6 citations
TL;DR

This paper proposes GN-Transformer, a novel model that fuses source code sequences and Abstract Syntax Tree (AST) representations into a Syntax-Code-Graph (SCG) for improved code summarization. By extending Graph Networks with self-attention mechanisms and training end-to-end on the fused modality, GN-Transformer achieves state-of-the-art performance across BLEU, METEOR, and ROUGE-L metrics on two code summarization datasets, with superior human-rated quality and accuracy in an expert-user study.

ABSTRACT

As opposed to natural languages, source code understanding is influenced by grammatical relationships between tokens regardless of their identifier name. Graph representations of source code such as Abstract Syntax Tree (AST) can capture relationships between tokens that are not obvious from the source code. We propose a novel method, GN-Transformer to learn end-to-end on a fused sequence and graph modality we call Syntax-Code-Graph (SCG). GN-Transformer expands on Graph Networks (GN) framework using a self-attention mechanism. SCG is the result of the early fusion between a source code snippet and the AST representation. We perform experiments on the structure of SCG, an ablation study on the model design, and the hyper-parameters to conclude that the performance advantage is from the fused representation. The proposed methods achieve state-of-the-art performance in two code summarization datasets and across three automatic code summarization metrics (BLEU, METEOR, ROUGE-L). We further evaluate the human perceived quality of our model and previous work with an expert-user study. Our model outperforms the state-of-the-art in human perceived quality and accuracy.

Motivation & Objective

  • To improve code summarization by fusing sequence and graph modalities early in the learning process.
  • To address the limitations of late fusion in existing models that process code and AST representations independently.
  • To develop a graph neural network architecture enhanced with self-attention for better cross-modal interaction in code understanding.
  • To evaluate model performance not only via automatic metrics but also through a large-scale expert-user study on human perceived quality and accuracy.
  • To investigate the impact of positional encoding in graph-structured representations for code summarization.

Proposed method

  • The model constructs a Syntax-Code-Graph (SCG) by early fusion of source code tokens and AST nodes into a single heterogeneous graph.
  • GN-Transformer employs a Graph Network (GN) framework enhanced with multi-head self-attention mechanisms to enable dynamic, learnable interactions between nodes.
  • The encoder processes the SCG through multiple GN-Transformer blocks, each applying residual connections and layer normalization to update node representations.
  • Only token-nodes are used as input to the decoder, while AST-nodes are discarded after feature extraction, preserving sequence-level generation.
  • The model uses learnable absolute and relative positional embeddings, adapted for graph structures, to provide inductive bias for node ordering.
  • The architecture supports end-to-end training on the fused SCG, enabling richer cross-modal representations than late fusion approaches.

Experimental results

Research questions

  • RQ1Can early fusion of code sequences and ASTs via a Syntax-Code-Graph improve code summarization performance compared to late fusion?
  • RQ2How does the integration of self-attention into Graph Networks enhance representation learning for code summarization?
  • RQ3What is the impact of different positional encoding strategies (absolute vs. relative) on graph-structured code representations?
  • RQ4Does the proposed model outperform state-of-the-art methods in both automatic metrics and human evaluation of summary quality and accuracy?
  • RQ5How do model hyperparameters and graph structure affect the performance of the fused representation?

Key findings

  • GN-Transformer achieves state-of-the-art performance on two code summarization datasets, outperforming prior models across BLEU, METEOR, and ROUGE-L metrics.
  • The ablation study confirms that the performance gain is due to the early fusion of sequence and graph modalities, not just improved architecture design.
  • Human evaluation via an expert-user study shows GN-Transformer outperforms previous models in perceived summary quality and accuracy.
  • Absolute positional embedding (APE) degrades performance on both datasets, especially when applied to AST-nodes, suggesting APE is ill-suited for graph-structured code representations.
  • Relative positional encoding (RPE) via PGNN shows mixed results—improving performance on the smaller Java dataset but degrading it on the larger Python dataset, likely due to insufficient anchor set adaptability in larger graphs.
  • The model demonstrates robustness to code length, with performance stability observed across varying snippet lengths in the test set.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.