Abstract
Code Large Language Models (Code LLMs) are being increasingly employed in real-life applications, so evaluating them is critical. While the conventional accuracy evaluates the performance of Code LLMs on a set of individual tasks, their self-consistency across different tasks is overlooked. Intuitively, a trustworthy model should be self-consistent when generating natural language specifications for its own code and generating code for its own specifications. Failure to preserve self-consistency reveals a lack of understanding of the shared semantics underlying natural language and programming language, and therefore undermines the trustworthiness of a model. In this paper, we first formally define the self-consistency of Code LLMs and then design a framework, IdentityChain, which effectively and efficiently evaluates the self-consistency and conventional accuracy of a model at the same time. We study eleven Code LLMs and show that they fail to preserve self-consistency, which is indeed a distinct aspect from conventional accuracy. Furthermore, we show that IdentityChain can be used as a model debugging tool to expose weaknesses of Code LLMs by demonstrating three major weaknesses that we identify in current models using IdentityChain.
Introduction
The standard evaluation of Code Large Language Models (LLMs) typically focuses on accuracy in isolated tasks: code generation (translating natural language to programming language) and code summarization (translating programming language to natural language). However, these metrics fail to capture whether a model maintains a coherent internal logic. A truly robust model should be self-consistent: if it generates code from a prompt, it should be able to summarize that code accurately enough to regenerate the same logic later.
This paper argues that current metrics like BLEU or Pass@k are insufficient for measuring this "back-and-forth" reliability. When a model lacks self-consistency, it suggests that its performance is based on sophisticated pattern matching rather than a deep understanding of underlying semantics. To address this gap, the authors introduce IdentityChain.
Methodology: The IdentityChain Framework
IdentityChain evaluates models through a multi-step "semantic telephone" game. The process begins with an initial natural language specification ($nl_0$), from which the model generates code ($pl_0$). This code is then summarized back into a new docstring ($nl_1$), which in turn serves as the prompt for a second round of code generation ($pl_1$).
To measure success, the authors utilize the Test Output Match (TOM) Score. Unlike text-matching metrics, TOM executes both the original and regenerated code against a suite of test cases. If the outputs match exactly, the models are considered semantically consistent. To ensure the evaluation is rigorous, the framework uses deterministic greedy decoding and replaces specific function names with generic identifiers to prevent the model from "cheating" based on descriptive naming conventions.
Experimental Results
The study evaluated eleven popular Code LLMs, including GPT-4, Gemini-Pro, and CodeLlama, using the HumanEvalPlus and MBPP Sanitized benchmarks. The results highlight a significant divergence between accuracy and self-consistency.
Key insights from the data include:
- Accuracy vs. Consistency: High accuracy does not imply high self-consistency. For example, while GPT-3.5 is highly accurate, its self-consistency (measured by $SSC_5$) drops significantly as the chain progresses.
- The GPT-4 Capability Gap: While GPT-4 is only slightly more accurate than GPT-3.5 on some benchmarks, it is over 50% more self-consistent. This suggests that self-consistency is a more sensitive metric for identifying true reasoning capabilities.
- Performance Decay: All models showed a decline in "Strong Self-Consistency" (SSC) as the chain length increased, indicating that maintaining perfect semantic loops remains a challenge for current LLMs.
Model Debugging and Weaknesses
IdentityChain also serves as a diagnostic tool, revealing three major recurring weaknesses in current models:
- Data Type Confusion: Models often fail to distinguish between general numbers and specific integers, leading to logic errors in edge cases.
- Ignoring Implicit Semantics: Models frequently fail to summarize "else" branches or implicit return values during the summarization phase.
- Execution Hallucination: Models often generate docstring examples that do not actually match the logic of the code they wrote.
Conclusion
IdentityChain provides a new lens for evaluating the trustworthiness of Code LLMs. By looking beyond single-step accuracy, it exposes the semantic "blind spots" of even the most advanced models. Future work will expand this framework to other programming languages and explore using IdentityChain to generate higher-quality training data to improve model consistency.
Summary updated