Abstract
This study benchmarks the performance of various Large Language Models (LLMs) on the task of code explanation—the generation of natural language summaries for code snippets. By evaluating both generic and code-specialized models across different prompting strategies, the research identifies that domain-specific pre-training is more critical than model scale. Furthermore, the findings reveal a "few-shot trap" where mismatched example distributions can degrade performance, making zero-shot prompting a more robust baseline for specialized documentation tasks.
Introduction
Software documentation is a critical but often neglected aspect of software engineering, with studies suggesting that only a small fraction of open-source projects are adequately documented. This lack of clarity complicates the maintenance of legacy systems. While LLMs have demonstrated significant capability in code generation, their ability to accurately explain existing code—capturing the underlying intent rather than just the syntax—remains a subject of active research. This paper investigates how different model architectures and prompting strategies handle the nuances of code summarization.
Methods and Experimental Setup
The researchers evaluated five distinct LLMs categorized into two groups:
- Generic LLM: Llama-2-70B-Chat, representing a high-capacity general-purpose model.
- Code-Specific LLMs: Llama-2-Coder-7B, CodeLlama-13B-Instruct, CodeUp-13B-Chat, and StarCoder (15.5B).
Three primary evaluation strategies were employed:
- Zero-shot: Direct prompting with a task description and the target code.
- Few-shot: Providing 10 (code, explanation) pairs as context before the target task.
- Instruction Fine-tuning: Utilizing QLoRA and PEFT to fine-tune the CodeUp-13B-Chat model on specialized datasets.
Performance was quantified using BLEU scores for lexical overlap and CodeBERT-based cosine similarity to assess semantic alignment between generated summaries and ground truth.
Datasets and Distribution Mismatch
The study utilized two primary datasets with significantly different characteristics:
- IRSE (Information Retrieval in Software Engineering): The target benchmark, featuring long, detailed explanations (average 84.28 words).
- conala-train: Used for few-shot examples and fine-tuning, featuring much shorter summaries (average 14.68 words).
Key Results
The experimental results demonstrate a clear advantage for code-specialized models. In the zero-shot setting, CodeLlama-13B-Instruct and Llama-2-Coder-7B emerged as the top performers. Notably, CodeLlama-13B-Instruct achieved a BLEU-1 score of 0.189 and a CodeBERT semantic score of 0.498, vastly outperforming the much larger Llama-2-70B-Chat, which scored only 0.019 and 0.338 respectively.
Discussion and Insights
Domain Expertise vs. Scale
The data suggests that for technical domains like programming, specialized training data is a more significant factor than raw parameter count. The 13B and 7B code-specific models consistently outperformed the 70B generic model, indicating that the latter lacks the specific linguistic patterns required for high-quality code explanation.
The "Few-Shot Trap"
A surprising finding was that few-shot prompting often yielded worse results than zero-shot prompting. This was attributed to a distribution mismatch: because the few-shot examples from the Conala dataset were significantly shorter than the target IRSE explanations, the models "learned" to produce truncated summaries, sacrificing the detail required for the IRSE benchmark.
Fine-tuning Limitations
While instruction fine-tuning improved the base performance of the CodeUp model, it still struggled to match the zero-shot performance of the leading Code LLMs when tested on out-of-distribution data. This underscores the importance of zero-shot resilience in scenarios where high-quality, task-specific training data is unavailable.
Conclusion
This research highlights that zero-shot prompting with specialized Code LLMs is currently the most effective approach for generating detailed code explanations, especially when target documentation styles vary. Future work should focus on methods to align models with varying explanation lengths and complexities without requiring extensive, perfectly matched few-shot examples.
Summary updated