arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2412.00314cs.SE
收藏

基于LLM的递归语义理解实现类人代码质量评估

Human-Like Code Quality Evaluation through LLM-based Recursive Semantic Comprehension

Fangzhou Xu, Sai Zhang, Zhenchang Xing, Xiaowang Zhang, Yahong Han, Zhiyong Feng

AI总结:

针对现有代码质量评估方法成本高、语义捕捉不足及LLMs直接评估相关性低的问题,提出基于LLM的递归语义理解评估方法HuCoSC,通过递归交互与语义解耦提升评估准确性,实验结果优于现有方法。

摘要:

代码质量评估需根据特定问题描述的参考代码,对生成代码的质量进行评分。当前代码质量评估主要有两种形式:基于匹配的评估和基于执行的评估。前者需要收集大量测试用例,成本极高;后者依赖表面代码匹配作为评估指标,无法准确捕捉代码语义。此外,大量研究表明,基于匹配的评估无法真实反映代码质量。近年来,随着大型语言模型(LLMs)的发展,研究已证明将LLMs用作生成任务评估器的可行性。然而,由于幻觉和不确定性等问题,LLMs与人类判断的相关性仍处于较低水平,直接使用LLMs进行代码质量评估面临挑战。为此,我们提出基于LLM的递归语义理解的类人代码质量评估(HuCoSC)。我们采用递归方法,使LLMs每次独立理解代码语义的部分,通过与LLMs的多次交互获取代码语义。我们设计了语义依赖解耦存储,使独立分析成为可能,让LLMs通过分解复杂问题实现更准确的语义理解。最后,基于参考代码与生成代码的语义比较对生成代码进行评分。实验结果表明,HuCoSC在与人类专家的相关性和与代码执行的相关性方面均优于现有最先进方法。

英文摘要:

Code quality evaluation involves scoring generated code quality based on a reference code for a specific problem statement. Currently, there are two main forms of evaluating code quality: match-based evaluation and execution-based evaluation. The former requires the collection of a large number of test cases, making a huge cost. The latter relies on superficial code matching as an evaluation metric, which fails to accurately capture code semantics. Moreover, extensive research has demonstrated that match-based evaluations do not truly reflect code quality. With the development of large language models (LLMs) in recent years, studies have proven the feasibility of using LLMs as evaluators for generative tasks. However, due to issues like hallucinations and uncertainty in LLMs, their correlation with human judgment remains at a lower level, making the direct use of LLMs for code quality evaluation challenging. To address these issues, we propose Human-Like Code Quality Evaluation through LLM-based Recursive Semantic Comprehension (HuCoSC). We employ a recursive approach to enable LLMs to comprehend portions of code semantics independently each time, obtaining the code semantics through multiple interactions with LLMs. We designed a Semantic Dependency Decoupling Storage to make independent analysis feasible, allowing LLMs to achieve more accurate semantics by breaking down complex problems. Finally, the generated code is scored based on a semantic comparison between the reference code and itself. Experimental results indicate that HuCoSC surpasses existing state-of-the-art methods in terms of correlation with human experts and correlation with code execution.

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

↑