Interpreting Code Correctness in Language Models through Activation Steering

Aditya Narendra, Shubham Kamble, Subhankar Panda, Kanav Benipuri, vibha mishra, Chandresh Kumar MauryaDL4C @ ICML 2026

TL;DR

Researchers have discovered a single "correctness axis" hidden within the internal activations of code-generating LLMs. By identifying this one-dimensional subspace and applying "activation steering"—essentially nudging the model's internal state along this axis—they can causally improve a model's coding accuracy (pass@1) by up to 15.6% without any fine-tuning.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly used for software engineering, yet they suffer from a major reliability gap: they often generate buggy code with the same "confidence" (token-level probability) as correct code. Because next-token probabilities are poorly correlated with functional correctness, it is difficult to know if a model is about to produce a masterpiece or a mess.

This paper investigates whether these models internally "know" when they are being correct. The authors look beyond the output probabilities and dive into the residual stream—the internal "scratchpad" of activations that passes through the model's layers—to see if functional adequacy is represented as a specific geometric direction.

Methods

The authors employ a three-stage pipeline to find and manipulate the "correctness" signal:

  1. Contrastive Filtering: They generate multiple solutions for the same programming problem. They specifically look for "contrastive" cases where the model generates both correct and incorrect solutions for the same prompt.
  2. Probing & Extraction: Using logistic regression (probing), they test if they can linearly separate the internal states of correct vs. incorrect runs. They then extract a difference-in-means direction ($\hat{d}_l$), which represents the vector pointing from "wrong" to "right" in the model's activation space.
  3. Activation Steering: To prove this direction is causal (and not just a random correlation), they intervene during the generation process. By adding a scaled version of this vector to the residual stream at specific layers, they attempt to "steer" the model toward correct code.
  4. Symmetry Scoring: A novel contribution of this paper is the Correctness-Axis Symmetry Score. It measures whether the direction used to fix a failing run is the geometric opposite of the direction that corrupts a successful run. They argue that high symmetry is a better predictor of steering success than simple probing accuracy.

Datasets

The study uses MBPP+ (Mostly Basic Python Problems Plus), an augmented version of the standard MBPP benchmark. MBPP+ is more rigorous because it includes significantly more test cases per problem, reducing the chance that "correct" code passes just by luck. The authors used a split of 378 problems, generating 5 solutions each to build their contrastive dataset.

Key Insights and Ideas

  • Correctness is Linear: One of the most striking findings is that functional correctness—a complex property involving logic and syntax—is mediated by a simple, one-dimensional linear subspace. You don't need a complex non-linear map to find it.
  • Causality, Not Just Correlation: By successfully steering the model (making it better or worse at will), the authors prove that this internal representation is "causally operative." The model uses this internal "sense" of correctness to guide its generation.
  • The Symmetry Requirement: The authors found that just because a probe can detect correctness doesn't mean you can steer it. Effective steering requires "geometric coherence"—the axis must be consistent across both easy and hard problems.
  • Model Scale Matters: The 7B parameter model showed much higher linear decodability (up to 93.4% AUROC) compared to the 1.5B model, suggesting that larger models develop clearer internal representations of their own functional adequacy.

Key Results

The authors tested their method on the Qwen2.5-Coder family (1.5B and 7B versions):

  • Forward Steering (Improving Code): Adding the correctness direction increased the pass@1 rate by 15.6% for the 1.5B model and 11.0% for the 7B model on the contrastive test set.
  • Backward Steering (Corrupting Code): Subtracting the direction successfully degraded performance by 12.9% and 11.7% respectively, proving bidirectional control.
  • Layer Localization: The most effective interventions happened in the middle-to-late layers (e.g., layers 17–21 of 28), where the model has processed the logic but hasn't yet finalized the output tokens.

Limitations and Future Work

  • Scope of Models: The study focused exclusively on the Qwen2.5-Coder family. While these are state-of-the-art open-weight models, it remains to be seen if these findings generalize to other architectures like Llama or StarCoder.
  • Benchmark Diversity: The results are based on MBPP+. Testing on more complex benchmarks (like HumanEval or SWE-bench) would determine if this "correctness axis" holds up for multi-file or highly complex logic.
  • Inference Overhead: While activation steering is computationally efficient compared to fine-tuning, it still requires identifying the correct layers and steering magnitudes ($\alpha$) for each model.
  • Future Direction: The authors suggest that this work could lead to "self-correcting" models that monitor their own internal states to catch bugs before they are even typed out.

Summary updated

BibTeX
@inproceedings{narendra2026interpreting,
  author = {Aditya Narendra and Shubham Kamble and Subhankar Panda and Kanav Benipuri and vibha mishra and Chandresh Kumar Maurya},
  title = {{Interpreting Code Correctness in Language Models through Activation Steering}},
  booktitle = {DL4C @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=iIbMQK0twN},
}
Figure