Abstract
Source code summarization aims to automatically generate natural language summaries for code snippets, aiding developers in understanding and maintaining software. Existing methods are typically either extractive (retrieving key statements) or abstractive (generating text via neural models). While extractive methods preserve facts but lack naturalness, abstractive methods produce human-like text but often miss critical technical details. We propose EACS, a novel extractive-and-abstractive framework that combines these strengths. EACS uses an extractive module to identify important statements and an abstractive module with parallel encoders to generate succinct, human-like summaries. Evaluated on three datasets across six programming languages, EACS significantly outperforms state-of-the-art techniques in BLEU, METEOR, and ROUGE-L metrics.
What Problem Does This Paper Address?
High-quality code comments are vital for software maintenance but are frequently neglected due to the manual effort required. Automated summarization attempts to fill this gap, but current approaches face a trade-off:
- Extractive Methods: These identify and pull key keywords or statements directly from the source. While factually grounded, they often produce disjointed and ungrammatical summaries.
- Abstractive Methods: These utilize encoder-decoder architectures to generate summaries from scratch. While they achieve better naturalness, they are prone to "hallucinations" or omitting specific variable names and edge cases because the model's attention is spread thin across the entire code block.
The EACS framework bridges this gap by ensuring the model focuses on the most informative code segments without sacrificing linguistic quality.
Methods
The EACS framework is structured into two distinct phases: training and deployment.
Phase 1: The Extractor
The Extractor acts as a "highlighter." It is a classifier trained to identify the most "important" lines of code. Ground-truth labels are generated using the ROUGE-L metric to find code statements with the highest overlap with human-written comments. Once trained, this module predicts "Important Statements" (IStates) for any input code.
Phase 2: The Abstracter
The Abstracter is the core generative component. Unlike standard single-encoder models, it employs two parallel encoders:
- AbEncoder: Processes the entire code snippet to capture global context.
- ExEncoder: Focuses exclusively on the IStates identified by the Extractor to capture factual details.
The outputs from both encoders are integrated by a Fusioner and passed to a Decoder to generate the final summary. This dual-focus approach allows the model to balance overall program flow with specific technical facts.
Experimental Evaluation
The researchers evaluated EACS on three major benchmarks: JCSD (Java), PCSD (Python), and CodeXGLUE (covering Go, Java, JavaScript, PHP, Python, and Ruby).
Key Results
- Performance Gains: On the JCSD dataset, EACS improved BLEU scores by 3.56% and METEOR scores by 8.81% over the state-of-the-art CodeT5 model.
- Multilingual Robustness: EACS consistently achieved higher scores across all six languages in CodeXGLUE, demonstrating its generalizability.
- Human Evaluation: In a blind study, developers rated EACS summaries significantly higher for informativeness and relevance, noting its superior ability to capture the "intent" of the code.
Insights and Future Work
A key finding was that parallel processing of global and extractive information prevents technical details from being lost in the "noise" of full source code. Case studies revealed that the Extractor effectively filters out non-functional code, such as logging statements, while prioritizing logic like return-value checks.
However, challenges remain. The model still struggles with high-level abstractions that lack direct textual links to the code (e.g., summarizing complex math as "calculating the remainder"). Additionally, standard tokenizers can sometimes disrupt technical syntax. Future work will explore integrating larger language models (LLMs) to enhance the framework's abstractive capabilities.
Summary updated