← Latest papers
🤖 machine learning

Code Correctness Signals in LLM Hidden States: Pre-Generation Probing and Repair Geometry

This paper demonstrates that code correctness is linearly decodable from the hidden states of a Qwen3-4B model before generation, while revealing through rigorous residualization controls that apparent "repair" signals are actually confounded by context rather than representing isolated comprehension features.

Original authors: Carlo Di Cicco

Published 2026-06-15
📖 5 min read🧠 Deep dive

Original authors: Carlo Di Cicco

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine a large language model (LLM) as a brilliant, but slightly secretive, student taking a coding exam. This paper is like a detective story where researchers try to peek inside the student's "brain" (its hidden states) to see what it knows before it writes a single word of code, and to see if its brain changes in a specific way when it tries to fix a mistake.

The researchers used a specific student (a model called Qwen3-4B) and gave it 444 coding problems. Here is what they found, explained through simple analogies.

1. The "Pre-Game" Crystal Ball

The Question: Before the student even starts writing the answer, does their brain already "know" if they are going to get the problem right or wrong?

The Analogy: Imagine you are about to take a math test. You haven't written a single number yet. The researchers looked at the student's brain activity the exact moment they finished reading the question. They asked: "Can we predict a passing grade just by looking at how the brain is buzzing right now?"

The Finding: Yes.
They built a simple "detector" (a linear probe) that looked at the brain's final state after reading the prompt. It was incredibly accurate (about 93% accuracy) at predicting whether the code would pass the tests.

  • The Twist: They worried the detector was just cheating by noticing that harder problems have longer questions. So, they "subtracted" the effect of question length from the brain data. Even after removing the "length" clue, the detector still worked well (dropping slightly to 91% accuracy, but still far better than random guessing).
  • The Takeaway: The model's brain contains a clear signal about whether it can solve the problem before it even tries to generate the solution.

2. The "Fix-It" Direction

The Question: When the student fails a problem and tries to fix it, does their brain shift in a specific, consistent direction that signals "I am about to succeed"?

The Analogy: Imagine the student gets a question wrong. They get a hint (the error message) and try again. The researchers looked at the difference between the brain state of the failed attempt and the brain state of the repair attempt. They asked: "Is there a specific 'arrow' or direction in the brain's activity that points toward a successful fix?"

The Finding: It's complicated.

  • First Look: At first glance, yes! There was a clear "arrow" in the brain data. When the model successfully fixed a bug, the brain moved in a specific direction. When it failed to fix it, the brain moved differently. This looked like a "success signature."
  • The Second Look (The Reality Check): The researchers then asked, "Wait a minute. Is this 'arrow' actually about the model understanding the fix, or is it just reacting to the circumstances of the fix?"
    • They noticed that successful fixes often happened when the original mistake was a specific type of error (like a runtime error) or when the code was shorter.
    • When they mathematically "subtracted" these external circumstances (the context) from the brain data, the "success arrow" disappeared.
  • The Takeaway: The brain didn't have a special "I understand the fix" signal. Instead, the brain was just reacting to the context of the repair (e.g., "Oh, this is a short code with a runtime error, I know how to handle this"). The "success direction" was just a side effect of the situation, not a deep internal realization.

3. The "Magic Eraser" Tool

The paper introduces a method called Residualization. Think of this as a "Magic Eraser" for data.

  • How it works: If you think a signal (like "I know the answer") is real, but you suspect it's actually just caused by something else (like "the question was short"), you use the Magic Eraser to wipe away the "short question" part.
  • The Result:
    • When they used the eraser on the Pre-Game signal, the signal stayed strong. (It was real).
    • When they used the eraser on the Fix-It signal, the signal vanished. (It was an illusion caused by the context).

Summary

The paper teaches us two main lessons about how these AI models think:

  1. They know before they speak: The model's brain holds a clear map of whether it will succeed or fail the moment it finishes reading the instructions.
  2. Don't trust the "Fix" signal blindly: When a model tries to repair its own code, the changes in its brain aren't necessarily a sign of "learning" or "understanding." Often, they are just the model reacting to the specific details of the error message and the code length.

The authors emphasize that their most important contribution isn't just the results, but the honesty of their method. They used the same "Magic Eraser" tool to prove one thing was real and another was an illusion, showing that we must be careful not to mistake the context of a problem for the model's internal understanding.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →