它们都好吗?评估基于LLM的代码生成中CoT的质量
Are They All Good? Evaluating the Quality of CoTs in LLM-based Code Generation
AI总结:
本研究通过分析失败样本和CoT-代码对,实证评估了LLM生成CoT的质量,发现外部因素主导质量问题,并验证了通过细化描述可改进低质量CoT。
摘要:
大型语言模型(LLMs)在代码生成方面展示了令人印象深刻的表现,尤其是在结合思维链(CoT)提示技术时。它们将需求分解为中间推理步骤,这些步骤作为设计依据,指导LLMs像人类程序员一样编写代码。因此,这些步骤的质量对于确保生成代码的正确性和可靠性至关重要。然而,关于LLMs生成的CoT质量知之甚少。我们在多大程度上可以信任LLMs生成的思维?它们有多好?本文通过分析两个广泛使用的代码生成基准上的1,023个失败代码样本,实证探讨了LLMs生成不满意CoT的外部因素和内部因素。我们还通过分析210个CoT-代码对,并通过提示LLMs来改进不满意的CoT,评估了它们对代码生成性能的影响。我们的研究揭示了三个关键发现:(1)外部因素(53.60%),如需求不明确和缺乏上下文,主要影响CoT质量,而内部因素(40.10%)源于LLMs对提示的误解。(2)即使CoT正确,18.5%的生成代码仍因指令遵循问题而包含错误;相反,11.90%的正确代码与有缺陷的CoT配对。(3)改进低质量CoT是可行的,即当给出详细的问题描述时,LLMs会有所改进。这些发现突出了基于CoT的代码生成中的关键挑战,并为改进LLMs的推理和可靠性指明了方向。
英文摘要:
Large language models (LLMs) have demonstrated impressive performance in code generation, particularly when augmented with chain-of-thought (CoT) prompting techniques. They break down requirements into intermediate reasoning steps, which act as design rationales to guide LLMs in writing code like human programmers. Thus, the quality of these steps is crucial for ensuring the correctness and reliability of the generated code. However, little is known about the quality of CoT generated by LLMs. To what extent can we trust the thoughts generated by LLMs? How good are they? This paper empirically explores the external and internal factors of why LLMs generate unsatisfactory CoTs by analyzing 1,023 failed code samples on two widely used code generation benchmarks. We also evaluate their impact on code generation performance by analyzing 210 CoT-code pairs and refining the unsatisfied CoTs by prompting LLMs. Our study reveals three key findings: (1) External factors (53.60%), such as unclear requirements and lack of context, mainly affect CoT quality, while internal factors (40.10%) stem from LLMs' misunderstanding prompts. (2) Even when CoTs are correct, 18.5% of the generated code contains errors due to instruction-following issues; conversely, 11.90% of correct code is paired with flawed CoTs. (3) Refining low-quality CoTs is feasible, i.e., LLMs improve when given detailed problem descriptions. These findings highlight key challenges in CoT-based code generation and suggest directions for improving LLM reasoning and reliability.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。