mlsanityData to 7 Oct 2026

On LLMs' Internal Representation of Code Correctness

arXiv 2512.07404 ↗First posted 8 Dec 2025cs.SE cs.AI cs.LGcited by 5

Not on the map. Why?

Abstract (arXiv)

Despite the effectiveness of large language models (LLMs) for code generation, they often output incorrect code. One reason is that model output probabilities are often not well-correlated with correctness, and reflect only the final output of the generation process. Inspired by findings that LLMs internally encode concepts like truthfulness, this paper explores if LLMs similarly represent code correctness. Specifically, we identify a correctness representation inside LLMs by contrasting the hidden states between pairs of correct and incorrect code for the same programming tasks. By experimenting on four LLMs, we show that exploiting this extracted correctness representation outperforms standard log-likelihood ranking, as well as verbalized model confidence. Furthermore, we explore how this internal correctness signal can be used to select higher-quality code samples, without requiring test execution. Ultimately, this work demonstrates how leveraging internal representations can enhance code generation systems and make LLMs more reliable, thus improving confidence in automatically generated code.

Key facts. Cited by 5 papers in the map (data through 7 Oct 2026). Builds on 63 of its 93 references that are in the map. First posted on arXiv 8 Dec 2025.

Builds on

63 of 93 references.

References · 63

  1. 2017Attention Is All You Needcited by 59,932
  2. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  3. 2020Measuring Massive Multitask Language Understandingcited by 7,768
  4. 2023DINOv2: Learning Robust Visual Features without Supervisioncited by 7,764
  5. 2017On Calibration of Modern Neural Networkscited by 4,860
  6. 2018Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challengecited by 4,710
  7. 2016SQuAD: 100,000+ Questions for Machine Comprehension of Textcited by 4,115
  8. 2021Program Synthesis with Large Language Modelscited by 3,509
  9. 2023SWE-bench: Can Language Models Resolve Real-World GitHub Issues?cited by 3,193
  10. 2021TruthfulQA: Measuring How Models Mimic Human Falsehoodscited by 2,919
  11. 2018Can a Suit of Armor Conduct Electricity? A New Dataset for Open Book Question Answeringcited by 2,114
  12. 2018CommonsenseQA: A Question Answering Challenge Targeting Commonsense Knowledgecited by 1,793
38 more
  1. 2022Language Models (Mostly) Know What They Knowcited by 1,783
  2. 2022Competition-Level Code Generation with AlphaCodecited by 1,427
  3. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,332
  4. 2016Man is to Computer Programmer as Woman is to Homemaker? Debiasing Word Embeddingscited by 1,304
  5. 2023Representation Engineering: A Top-Down Approach to AI Transparencycited by 1,239
  6. 2021Measuring Coding Challenge Competence With APPScited by 879
  7. 2023Just Ask for Calibration: Strategies for Eliciting Calibrated Confidence Scores from Language Models Fine-Tuned with Human Feedbackcited by 788
  8. 2022Teaching Models to Express Their Uncertainty in Wordscited by 731
  9. 2023Towards Automated Circuit Discovery for Mechanistic Interpretabilitycited by 700
  10. 2018CoQA: A Conversational Question Answering Challengecited by 674
  11. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
  12. 2023Large Language Models for Software Engineering: A Systematic Literature Reviewcited by 389
  13. 2023CodeT5+: Open Code Large Language Models for Code Understanding and Generationcited by 327
  14. 2020IntelliCode Compose: Code Generation Using Transformercited by 225
  15. 2022Grounded Copilot: How Programmers Interact with Code-Generating Modelscited by 216
  16. 2022Leveraging Large Language Models for Multiple Choice Question Answeringcited by 199
  17. 2023Planning with Large Language Models for Code Generationcited by 179
  18. 2025Reasoning Models Know When They're Right: Probing Hidden States for Self-Verificationcited by 154
  19. 2017Learning to Generate Reviews and Discovering Sentimentcited by 147
  20. 2022Natural Language Descriptions of Deep Visual Featurescited by 136
  21. 2024Rethinking Interpretability in the Era of Large Language Modelscited by 110
  22. 2023Navigating the Grey Area: How Expressions of Uncertainty and Overconfidence Affect Language Modelscited by 91
  23. 2022Coder Reviewer Reranking for Code Generationcited by 83
  24. 2024LUQ: Long-text Uncertainty Quantification for LLMscited by 79
  25. 2024Can multiple-choice questions really be useful in detecting the abilities of LLMs?cited by 66
  26. 2025Which of These Best Describes Multiple Choice Evaluation with LLMs? A) Forced B) Flawed C) Fixable D) All of the Abovecited by 51
  27. 2024Calibration and Correctness of Language Models for Codecited by 49
  28. 2023Hot or Cold? Adaptive Temperature Sampling for Code Generation with Large Language Modelscited by 37
  29. 2023Security Weaknesses of Copilot-Generated Code in GitHub Projects: An Empirical Studycited by 36
  30. 2022Fault-Aware Neural Code Rankerscited by 33
  31. 2023Beyond Surface Statistics: Scene Representations in a Latent Diffusion Modelcited by 29
  32. 2024InternalInspector I2: Robust Confidence Estimation in LLMs through Internal Statescited by 29
  33. 2024Towards Understanding the Characteristics of Code Generation Errors Made by Large Language Modelscited by 28
  34. 2025Right Answer, Wrong Score: Uncovering the Inconsistencies of LLM Evaluation in Multiple-Choice Question Answeringcited by 27
  35. 2023Assessing the Security of GitHub Copilot Generated Code -- A Targeted Replication Studycited by 24
  36. 2019BERT has a Moral Compass: Improvements of ethical and moral values of machinescited by 21
  37. 2021A Few More Examples May Be Worth Billions of Parameterscited by 19
  38. 2023Trustworthy and Synergistic Artificial Intelligence for Software Engineering: Vision and Roadmapscited by 19

50 most cited of 63 All 63 (JSON)

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2026: 5.

5 papers.