面向大语言模型代码生成的不确定性引导思维链方法
Uncertainty-Guided Chain-of-Thought for Code Generation with LLMs
AI总结:
针对大语言模型代码生成中思维链过度思考的问题,提出不确定性感知思维链UnCert-CoT,通过熵和概率差两种不确定性度量动态决策是否启用多路径推理,在MHPP基准上PassRate最高提升6.1%,兼顾效率与准确率。
摘要:
思维链(Chain-of-Thought, CoT)推理已被证明是提升大语言模型(large language models, LLMs)在代码生成场景下问题求解能力的有效技术。然而,现有CoT方法往往存在“过度思考”的倾向:LLM会不加区分地应用推理策略,未充分考量任务的内在复杂度。这导致LLM在相对简单的任务、或是正确答案已十分明确的问题上,消耗了过多以token计的计算资源。此外,这种过度思考还可能将LLM引向错误的推理路径,最终生成错误代码。\n本文提出了UnCertainty-Aware Chain-of-Thought(UnCert-CoT,不确定性感知思维链)——一种基于LLM的代码生成增强方法,它引入了不确定性感知的CoT推理机制,将计算资源集中在LLM更易出错的节点上。我们提出了两种基于置信度的不确定性度量方法:基于熵的方法和基于概率差的方法。当不确定性较高时,UnCert-CoT会激活CoT解码生成多条推理路径,并选取正确性概率最高的代码作为最终结果;反之,当不确定性较低时,LLM直接生成代码。这种不确定性判断机制让LLM能够优先处理复杂任务,在简单场景下省略不必要的步骤,从而提升代码生成的整体效率与准确率。\n实验结果表明,UnCert-CoT在高难度基准MHPP(Mostly Hard Python Problems,多难度Python问题集)上显著提升了代码生成准确率,其PassRate准确率最高提升6.1%,尤其在传统LLM易出错的场景下效果突出。
英文摘要:
Chain-of-Thought (CoT) reasoning has been demonstrated as an effective technique for improving the problem-solving capabilities of large language models (LLMs) in the context of code generation. However, existing CoT methods often exhibit a tendency toward "overthinking", where the LLM consistently applies reasoning strategies without adequately considering the task's underlying complexity. This results in the LLMs allocating excessive computational resources, in terms of tokens, to relatively simple tasks or problems where the correct answer is already evident. Additionally, this overthinking may lead LLMs down incorrect reasoning paths, resulting in incorrect code generation. In this paper, we introduce UnCertainty-Aware Chain-of-Thought (UnCert-CoT), an LLM-based approach designed to enhance code generation by incorporating an uncertainty-aware CoT reasoning mechanism, which focuses computational resources on targeting points where LLMs are more prone to error. We propose two confidence-based uncertainty measures: Entropy-based and Probability Differential-based methods. When uncertainty is high, UnCert-CoT activates CoT-decoding to generate multiple reasoning paths and selects the final code that exhibits the highest likelihood of correctness. In contrast, LLM directly generates the code when uncertainty is low. This uncertainty judgment mechanism allows LLMs to prioritize complex tasks and avoid unnecessary steps in simpler cases, thereby improving overall efficiency and accuracy in code generation. Our experimental results demonstrate that UnCert-CoT significantly enhances code generation accuracy on challenging benchmark MHPP(Mostly Hard Python Problems), it achieves improvements up to 6.1% on PassRate accuracy, particularly in situations where traditional LLMs are prone to errors.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。