TL;DR
Automatically predicting clean, descriptive method names is a notoriously difficult task for large language models (LLMs) when they attempt to map raw code directly to an identifier. This paper demonstrates that mimicking the human "understand-before-naming" process via intermediate code summarization significantly improves name quality. By introducing SMNP, a framework combining task-oriented summarization with Chain-of-Thought (CoT) refinement, the authors achieve highly accurate, human-aligned method names across multiple state-of-the-art LLMs.
What Problem Does This Paper Address?
Clear method names are the bedrock of readable and maintainable software, yet developers—especially novices—frequently struggle to distill complex logic into a few concise words. While Method Name Prediction (MNP) tools aim to automate this process, current LLM-based approaches face two major roadblocks:
- Flawed Evaluation Metrics: Traditional benchmarks rely on surface-level token overlap metrics (like F1-score or Exact Match). These metrics penalize perfectly valid synonyms and fail to capture true semantic equivalence.
- The "Single-Leap" Generation Gap: Most MNP models map raw code directly to a method name in a single probabilistic step. This ignores how humans actually write code: we first comprehend what a function does globally before deciding how to name it.
This paper investigates whether introducing an explicit code-summarization step bridges this gap, and how to evaluate the resulting names accurately without relying on rigid token matching.
Methods
The authors first establish that LLMs (particularly DeepSeek) can act as reliable, reference-free semantic evaluators that align closely with human experts.
Building on this, they analyze a naive "summarize-then-name" approach and identify key failure modes, such as semantic object/verb misalignments (e.g., using a generic verb like process instead of a constructive verb like create). To fix these issues, they propose SMNP (Summary-enhanced Method Name Prediction), which introduces two core innovations:
- MNP-Oriented Summarization: Instead of standard code commenting, SMNP uses a zero-shot prompt that forces the LLM to generate a single-sentence functional summary. This summary must explicitly state the main action, the primary object of operation, and the key result, while strictly banning lazy, generic verbs like "do" or "execute".
- CoT-Enhanced Refinement: A 6-step Chain-of-Thought prompting strategy guides the model to systematically unpack the summary before generating the final identifier. The model must explicitly document its reasoning across three semantic pillars: understanding the core purpose, identifying the key action verb, and determining the target entity.
The workflow contrast between direct generation and the summary-based approach is illustrated below:
Datasets
The framework was evaluated using the clean version of the CodeSearchNet (CSN) corpus, a massive dataset containing millions of functions. The authors specifically extracted samples from CSN-java and CSN-python to test the model's robustness across two distinct, mainstream naming conventions: camelCase and snake_case. Experiments were conducted using a randomly selected test set of 200 samples per language.
Key Insights and Ideas
- Ground Truth Isn't Always "Gold": Strikingly, human evaluators consistently rated LLM-generated method names higher than the original developer-written reference names found in the datasets. This highlights the severe limitations of evaluating MNP tasks purely based on token overlap with existing codebases.
- LLMs as Scalable Meta-Evaluators: The study confirms that LLM-based evaluation provides a viable, reference-free alternative to human grading, capturing semantic nuances that traditional metrics completely miss.
- Verbs are the Critical Link: Through ablation studies, the authors discovered that explicitly isolating the key action verb (Step 2 of their CoT refinement) was the single most impactful factor in generating high-quality names. Skipping this step caused the sharpest decline in performance.
Key Results
- Human Alignment: Spearman correlation analysis showed that LLM evaluators (especially DeepSeek-based ones) strongly correlate with human judgments, whereas traditional metrics like Exact Match showed almost zero correlation.
- SMNP Superiority: SMNP consistently outperformed both direct generation and naive summarization-and-refinement strategies across 5 major LLMs (including GPT-4o-mini, DeepSeek-Reasoner, DeepSeek-Coder, Qwen2.5, and Qwen2.5-Coder).
- Error Resolution: SMNP successfully resolved 78% of summarization semantic inaccuracies and over 70% of semantic misalignments compared to the baseline pipeline, proving that structured reasoning prevents the model from drifting into generic or misleading terminology.
Limitations and Future Work
While highly effective, the authors note a few boundaries to their study. The evaluation was conducted on a dataset of 200 samples per language, which, while sufficient for deep qualitative and human analysis, could be expanded to larger scales. Additionally, the study focused strictly on Java and Python; future work is required to determine how well these prompt structures generalize to functional languages or highly specialized domain-specific languages. Finally, mitigating the inherent prompt sensitivity and slight output randomness of LLMs remains an ongoing challenge for production deployment.
Summary updated