Introduction
While Code Large Language Models (LLMs) are becoming increasingly adept at writing and summarizing code, they often struggle with a surprisingly fundamental property: staying "self-consistent." This paper introduces IdentityChain, a novel framework designed to evaluate whether a model’s generated code matches its own natural language summaries. The authors reveal that even top-tier models like GPT-4 struggle to maintain semantic meaning when translating back and forth between text and code, highlighting a critical gap in how we evaluate model trustworthiness.
The Problem: Beyond One-Way Accuracy
The standard approach to evaluating Code LLMs relies on "one-way" accuracy metrics: can the model generate correct code from a natural language prompt (NL-to-PL), or can it accurately summarize existing code (PL-to-NL)?
The authors argue that evaluating these tasks in isolation is insufficient. In a truly trustworthy model, these two tasks should be symmetric. If a model generates a Python function from a docstring and then summarizes that same function back into a docstring, the underlying meaning should remain identical. This property is known as self-consistency. If a model fails this "round-trip" test, it suggests that it does not genuinely understand the shared semantics underlying natural language and programming languages, relying instead on surface-level pattern matching.
Methodology: The IdentityChain Framework
To rigorously test this, the researchers developed IdentityChain, a framework that subjects models to an iterative "telephone game" of translation.
The process unfolds as follows:
- Start: Begin with a human-written docstring ($nl_0$).
- Step 1 (Generation): The model writes code ($pl_0$) based on $nl_0$.
- Step 2 (Summarization): The model summarizes its own code ($pl_0$) into a new docstring ($nl_1$).
- Step 3 (Generation): The model writes new code ($pl_1$) based on its own summary ($nl_1$).
- Repeat: This cycle continues for $n$ steps.
To measure whether meaning is preserved across these steps, the authors introduce the Test Output Match (TOM) score. Unlike traditional metrics like BLEU—which merely look at superficial word overlap—TOM executes the code generated at different steps of the chain on the same test cases. If the outputs match exactly (even if they produce the same errors), the semantics are considered preserved. The evaluation also utilizes greedy decoding; if the model produces an exact string match of a previous step, the chain is deemed "self-consistent" and terminates early, making the evaluation highly efficient.
Datasets and Evaluation
The study evaluated eleven prominent Code LLMs, including GPT-4, GPT-3.5, Gemini Pro, Code Llama, and StarCoder. The evaluation utilized two primary benchmarks:
- HumanEval / HumanEvalPlus: 164 hand-crafted Python problems with rigorous test cases.
- MBPP (Sanitized): 257 entry-level Python programming concepts.
Key Insights and Results
The findings from IdentityChain reveal several critical insights about the current state of Code LLMs:
- Accuracy $\neq$ Consistency: A model can be highly accurate at writing code but fail miserably at remaining consistent. For example, a model might achieve high Pass@1 accuracy on a single task but lose the "thread" of meaning after just one round of back-translation.
- Universal Failure: All eleven models tested failed to maintain perfect self-consistency. Even GPT-4, the top performer, saw its consistency score drop as the chain length increased.
- GPT-4 vs. The Rest: While GPT-4’s standard accuracy was only slightly higher than GPT-3.5 on some benchmarks, its self-consistency was over 50% higher. This suggests that consistency is a far better metric for distinguishing truly capable models from those relying on memorization.
- Scaling Isn't Everything: Simply increasing a model's parameter count does not guarantee better consistency. In some instances, smaller versions of a model family outperformed their larger siblings in maintaining semantic alignment.
IdentityChain as a Diagnostic Tool
Beyond scoring, IdentityChain serves as a powerful debugger. By analyzing where the translation chain breaks, the authors identified three specific "blind spots" in current LLMs:
- Weak Sense of Data Types: Models frequently ignore type constraints (e.g., confusing "integers" with general "numbers") in their summaries.
- Ignoring Implicit Logic: Models tend to summarize explicit
ifchecks but completely ignore implicitelselogic or edge cases. - Execution Blindness: When asked to provide examples in a docstring, models frequently generate code that looks plausible but produces the wrong output upon execution.
Limitations and Future Work
The current study focuses exclusively on Python and the relationship between code and natural language. The authors suggest that future research should expand this framework to evaluate consistency during code-to-code translation (e.g., Java to Python) and text-to-text paraphrasing (e.g., technical documentation). Furthermore, IdentityChain could be utilized to generate fine-tuning data, helping future models "close the loop" and achieve true self-consistency during their training phase.
Summary updated