arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2501.12934cs.SEcs.LG
收藏

使用内部表示评估大型语言模型生成代码的正确性

Correctness Assessment of Code Generated by Large Language Models Using Internal Representations

Faculty of Information Technology, VNU University of Engineering and Technology(信息科技学院,越南工程大学)

Tuan-Dung Bui, Thanh Trong Vu, Thu-Trang Nguyen, Son Nguyen, Hieu Dinh Vo

AI总结:

本文提出白盒框架OPENIA,利用LLM内部表示评估生成代码正确性,在独立和仓库场景中分别提升达2倍和46%。

摘要:

确保大型语言模型(LLM)生成的代码的正确性,在人工智能驱动的软件开发中构成了一项重大挑战。现有方法主要依赖黑盒(封闭盒)方法,在生成后评估正确性,未能利用LLM在代码生成过程中内部状态所蕴含的丰富信息。在本文中,我们介绍了OPENIA,一种新颖的白盒(开放盒)框架,利用这些内部表示来评估LLM生成代码的正确性。OPENIA系统地分析了代表性的开源代码专用LLM的中间状态,包括DeepSeek-Coder、CodeLlama和MagicCoder,跨越多种代码生成基准。我们的实证分析揭示,这些内部表示编码了潜在信息,这些信息与生成代码的正确性强烈相关。基于这些见解,OPENIA采用白盒/开放盒方法对代码正确性做出有根据的预测,在适应性和鲁棒性方面相比传统基于分类的方法和零样本方法具有显著优势。实验结果表明,OPENIA始终优于基线模型,在独立代码生成中实现了高达2倍的改进,在仓库特定场景中实现了46%的提升,获得了更高的准确率、精确率、召回率和F1分数。通过释放进程内信号的潜力,OPENIA为LLM辅助代码生成中更主动和高效的质量保证机制铺平了道路。

英文摘要:

Ensuring the correctness of code generated by Large Language Models (LLMs) presents a significant challenge in AI-driven software development. Existing approaches predominantly rely on black-box (closed-box) approaches that evaluate correctness post-generation, failing to utilize the rich insights embedded in the LLMs' internal states during code generation. In this paper, we introduce OPENIA, a novel white-box (open-box) framework that leverages these internal representations to assess the correctness of LLM-generated code. OPENIA systematically analyzes the intermediate states of representative open-source LLMs specialized for code, including DeepSeek-Coder, CodeLlama, and MagicCoder, across diverse code generation benchmarks. Our empirical analysis reveals that these internal representations encode latent information, which strongly correlates with the correctness of the generated code. Building on these insights, OPENIA uses a white-box/open-box approach to make informed predictions about code correctness, offering significant advantages in adaptability and robustness over traditional classification-based methods and zero-shot approaches. Experimental results demonstrate that OPENIA consistently outperforms baseline models, achieving higher accuracy, precision, recall, and F1-Scores with up to a 2X improvement in standalone code generation and a 46% enhancement in repository-specific scenarios. By unlocking the potential of in-process signals, OPENIA paves the way for more proactive and efficient quality assurance mechanisms in LLM-assisted code generation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑