paperbot · PL 论文追踪

全部论文 待读 收藏

P2 On LLMs’ Internal Representation of Code Correctness

论 LLM 对代码正确性的内部表示
ICSE Proceedings of the 2026 IEEE/ACM 48th International Conference on Software Engineering2026匹配度 3/10 · 论文研究LLM内部隐藏状态中的代码正确性表示,用于生成代码筛选,属于LLM可解释性与代码生成可靠性方向,与用户核心关注的静态分析、形式化验证、Agentic程序分析以及浮点/贝叶斯程序分析交叉较远。虽然涉及程序正确性,但并未将LLM/Agent作为改进静态分析或验证的工具。引用 8 inbox
Francisco Ribeiro, Claudio Spiess, Premkumar Devanbu, Sarah Nadi
crossref: 2026-09-12arxiv: 2026-09-12

AI 速览

一句话:通过对比正确与错误代码的隐藏状态,发现并利用 LLM 内部的代码正确性表示来筛选更可靠的生成代码。

尽管大语言模型(LLM)在代码生成上表现出色,但输出概率常与代码正确性弱相关,且仅反映生成过程的最终结果。受 LLM 内部编码真实性等概念的启发,本文探究 LLM 是否同样表示代码正确性。作者对同一编程任务的正确与错误代码对,对比其隐藏状态,从而识别出 LLM 内部的正确性表示。在四个 LLM 上的实验表明,利用这种提取出的正确性表示进行排序,优于标准对数似然排序以及模型口头表达的信心度。进一步,作者探索如何在不执行测试的情况下,用该内部正确性信号选择更高质量的代码样本。该工作展示了利用内部表示提升代码生成系统与 LLM 可靠性的潜力。

问题
LLM 生成的代码常不正确,而其输出概率与正确性相关性差,仅反映生成过程的最终输出,缺乏对代码正确性的可靠内部信号。
方法
对同一编程任务的正确与错误代码对,对比 LLM 隐藏状态,提取出内部正确性表示,并将其用于代码排序与样本选择。
评估
在四个 LLM 上实验,比较内部正确性表示与标准对数似然排序及模型口头信心度的表现,并验证无需测试执行即可选择更高质量代码样本。
原文摘要(Abstract)

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.

链接与引用

DOI 原文 · arXiv ·

BibTeX
@inproceedings{paperbot11567,
  title = {On LLMs’ Internal Representation of Code Correctness},
  author = {Francisco Ribeiro and Claudio Spiess and Premkumar Devanbu and Sarah Nadi},
  booktitle = {ICSE},
  year = {2026},
  doi = {10.1145/3744916.3787846}
}