TL;DR
This paper introduces IdentityChain, a framework that evaluates Code Large Language Models (LLMs) by their "self-consistency"—their ability to maintain the same meaning when translating back and forth between code and natural language. The authors reveal that even high-accuracy models like GPT-4 suffer from "semantic drift," failing to preserve the logic of their own generated code over multiple iterations.
What Problem Does This Paper Address?
Current evaluations for Code LLMs typically focus on one-way accuracy:
- Code Generation: Can the model write code from a prompt? (NL-to-PL)
- Code Summarization: Can the model describe what code does? (PL-to-NL)
However, these tasks are usually evaluated in isolation. A model might generate code that passes tests but then fail to summarize that same code accurately. Or, it might summarize code correctly but then generate different, broken code when prompted with its own summary.
The authors argue that a truly "trustworthy" model should be self-consistent. If a model truly understands the underlying semantics, it should be able to cycle between code and natural language indefinitely without losing the original meaning. The paper addresses the lack of formal definitions and efficient metrics for this property.
Methods
The authors propose the IdentityChain framework, which treats NL-to-PL and PL-to-NL as symmetric translation tasks.
- The Chain: Starting with a natural language specification ($nl_0$), the model generates code ($pl_0$), then summarizes that code ($nl_1$), then generates new code from that summary ($pl_1$), and so on.
- Test Output Match (TOM) Score: Traditional metrics like BLEU (for text) or Pass@k (for code) are insufficient for consistency. The authors introduce TOM, which executes the code from different steps of the chain on the same test cases and compares the exact outputs. If $pl_0$ and $pl_1$ produce the same results (including specific error messages), they are considered semantically identical.
- Efficiency: To avoid infinite loops, they use greedy decoding and early stopping. If the model generates an exact string match to a previous step, the chain is considered stabilized and self-consistent.
Datasets
The study evaluates eleven popular Code LLMs (including GPT-4, Gemini-Pro, and CodeLlama) using two major benchmarks:
- HumanEvalPlus: An augmented version of the classic HumanEval dataset with significantly higher test case coverage to ensure semantic differences are caught.
- MBPP Sanitized: A manually verified subset of the Mostly Basic Python Problems dataset.
To ensure the models weren't "cheating" by using descriptive function names, the authors replaced meaningful names with a generic func in intermediate steps.
Key Insights and Ideas
- Accuracy $\neq$ Consistency: A surprising "aha moment" is that scaling a model doesn't automatically make it more consistent. For example, StarCoderBase-7B is more self-consistent than its larger 15B counterpart, despite being less accurate overall.
- The "Drift" Phenomenon: Most models lose their way very quickly. As shown in the figure below, both self-consistency (SC) and strong self-consistency (SSC) scores drop sharply within the first three steps of the chain before stabilizing.
- TOM > BLEU: The authors prove that their execution-based TOM score correlates much better with human judgment of "semantic identity" than standard text-similarity metrics like BLEU or BERTScore.
Key Results
The quantitative results highlight a significant gap in model reliability:
- Semantic Decay: For Gemini-Pro on HumanEvalPlus, the initial accuracy (Pass@1) is 54.6%, but the "Strong Self-Consistency" over 5 steps (SSC5) plunges to just 20.2%—a 63% relative decline.
- GPT-4 Superiority: While GPT-4 is only slightly more accurate than GPT-3.5 (74.8% vs 71.8% on HumanEvalPlus), it is vastly more consistent, with an SC5 score 51.2% higher than GPT-3.5. This suggests that consistency is a better differentiator for "frontier" models than simple accuracy.
- Debugging Weaknesses: IdentityChain exposed three specific flaws in current LLMs:
- Weak Sense of Data Types: Models often confuse
intwith general "numbers" in summaries. - Ignoring Implicit Logic: Models often fail to summarize
elsebranches that aren't explicitly written. - Execution Blindness: Models frequently generate correct descriptions but hallucinate incorrect input-output examples in docstrings.
Limitations and Future Work
- Language Scope: The current study is limited to Python. The authors suggest extending this to PL-to-PL (code translation) and NL-to-NL (paraphrasing) tasks.
- Semantic vs. Pragmatic: The evaluation focuses strictly on functional semantics (input/output). It does not account for code quality, security, or readability, which are also vital for real-world use.
- Fine-tuning: The authors propose that IdentityChain could be used to generate synthetic data for fine-tuning, potentially teaching models to be more consistent by training on their own "stabilized" chains.
Summary updated