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.


翻译:尽管大型语言模型(LLMs)在代码生成方面表现出色,但其生成的代码常存在错误。一个重要原因在于模型输出的概率分布往往与代码正确性关联较弱,且仅反映生成过程的最终输出结果。受LLMs内部已编码如“真实性”等概念的发现启发,本文探究LLMs是否对代码正确性存在类似的内在表征。具体而言,我们通过对比同一编程任务下正确与错误代码对的隐藏状态,识别出LLMs内部存在的正确性表征。通过对四种LLMs的实验表明,利用该提取的正确性表征进行排序,其效果优于标准的对数似然排序方法及模型语言化置信度评估。此外,我们探索了如何在不执行测试的情况下,利用这种内部正确性信号筛选更高质量的代码样本。本研究最终论证了通过挖掘内部表征可增强代码生成系统的可靠性,提升对自动生成代码的置信度,从而使LLMs生成更可信的代码。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
大型语言模型系统中提示缺陷的分类学
专知会员服务
8+阅读 · 2025年9月19日
大型语言模型(LLMs),附Slides与视频
专知会员服务
70+阅读 · 2024年6月30日
《大型语言模型代码生成》综述
专知会员服务
68+阅读 · 2024年6月4日
大型语言模型公平性
专知会员服务
41+阅读 · 2023年8月31日
自然语言处理中的语言模型预训练方法
PaperWeekly
14+阅读 · 2018年10月21日
【学界】机器学习模型的“可解释性”到底有多重要?
GAN生成式对抗网络
12+阅读 · 2018年3月3日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Arxiv
0+阅读 · 1月6日
VIP会员
相关基金
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员