利用语义距离估计基于大语言模型的代码生成的不确定性
Using Semantic Distance to Estimate Uncertainty in LLM-Based Code Generation
AI总结:
本文提出基于语义距离的不确定性估计方法,通过衡量生成程序执行行为的差异性,提升代码生成的正确性评估效果,在多个基准测试中优于现有方法。
摘要:
LLMs在代码生成中表现出色,但其输出缺乏正确性保证。基于样本的不确定性估计器通过生成多个候选程序并测量其分歧来解决这一问题。然而,现有估计器在行为识别、聚合、引用和比较方面的设计选择不同,使它们难以评估。因此,本文首先引入了一个分类学,将这些选择解耦并揭示了一个缺失的设计点:语义距离感知的不确定性估计,该方法不仅测量采样程序是否分歧,还测量其执行行为差异的严重程度。在LiveCodeBench、MBPP、HumanEval-X和BigCodeBench上,涵盖Python、Java和C++的多个基准测试中,我们的指标提供了强大的正确性代理,并在封闭源模型(GPT-3.5-Turbo、GPT-4o-mini、Gemini-2.5-Flash-Lite、Claude Opus 4.5)和开源模型(DeepSeek-Coder-V2)上一致优于现有样本基线。该方法具有实用性:不需要模型内部信息或LLM-as-judge调用,能够在不同模型、语言、采样温度和模糊设置下保持稳健,并将运行时间减少约48-79%相对于现有基线。
英文摘要:
LLMs show strong performance in code generation, but their outputs lack correctness guarantees. Sample-based uncertainty estimators address this by generating multiple candidate programs and measuring their disagreement. However, existing estimators make different design choices about how behaviours are identified, aggregated, referenced and compared, making them difficult to assess. We therefore first introduce a taxonomy that disentangles these choices and reveals a missing design point: semantic distance-aware uncertainty estimation, which measures not only whether sampled programs disagree, but how severely their execution behaviours differ. Across LiveCodeBench, MBPP, HumanEval-X and BigCodeBench, spanning Python, Java and C++, our metrics provide strong proxies for correctness, and consistently outperform state-of-the-art sample-based baselines across both closed-source models (GPT-3.5-Turbo, GPT-4o-mini, Gemini-2.5-Flash-Lite, Claude Opus 4.5) and an open-source model (DeepSeek-Coder-V2). The method is practical: it requires neither model internals nor LLM-as-judge calls, remains robust across models, languages, sampling temperatures and fuzzing settings, and reduces runtime by approximately 48-79% relative to existing baselines.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。