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

理解链式思维在代码生成中的有效性:一项经验性与信息论分析

Understanding Chain-of-Thought Effectiveness in Code Generation: An Empirical and Information-Theoretic Analysis

State Key Laboratory for Novel Software Technology, Nanjing University(南京大学软件新技术国家重点实验室);The State Key Laboratory of Blockchain and Data Security, Zhejiang University(浙江大学区块链与数据安全国家重点实验室)

Naizhu Jin, Zhong Li, Guang Yang, Tian Zhang, Qingkai Zeng

AI总结:

本研究通过经验分析和信息论方法,揭示了链式思维在代码生成中有效性的影响因素,发现结构化CoT在提升生成质量方面表现更优,且其效果受语言系统和模型容量影响。

摘要:

大型语言模型(LLMs)在代码生成任务上表现出色,但链式思维(CoT)提示如何帮助其提升性能的机制仍不明确。我们对神经代码生成中的CoT有效性进行了系统性的经验性与信息论研究,评估了五个范式(零样本、零样本CoT、自规划、结构化CoT、推理CoT)在六个Python基准测试、一个包含12种编程语言的多语言基准测试以及六个从7B到480B参数的模型上的表现,使用条件互信息$I(Y;C|X)$作为概念视角。我们的结果表明,外部引导的CoT在大多数情况下均优于直接生成,结构化方法在平均上将Pass@1提升5-12%,同时使用的token数量远少于反思推理。此外,CoT的收益取决于语言类型系统和模型容量。我们进一步发现,推理质量至关重要:高质量的结构化CoT由强生成器产生,其准确性显著高于使用相同模板的轻量级替代方案,而naive Zero-Shot CoT甚至可能降低性能。这些发现为根据模型容量、语言特征和任务复杂性选择CoT策略提供了实用指导。

英文摘要:

Large language models (LLMs) achieve strong performance on code generation, but the mechanisms by which Chain-of-Thought (CoT) prompting helps remain unclear. We present a systematic empirical and information-theoretic study of CoT effectiveness in neural code generation, evaluating five paradigms (Zero-Shot, Zero-Shot CoT, Self-Planning, Structured CoT, Reasoning-CoT) across six Python benchmarks, a multilingual benchmark with 12 programming languages, and six models from 7B to 480B parameters, using conditional mutual information $I(Y;C|X)$ as a conceptual lens. Our results show that externally guided CoT consistently outperforms direct generation, with structured methods improving Pass@1 by 5--12\% on average while using substantially fewer tokens than reflective reasoning, and that CoT benefits depend on language type systems and model capacity. We further find that reasoning \emph{quality} is critical: high-quality structured CoT from strong generators yields significantly higher accuracy than lightweight alternatives with the same template, whereas naive Zero-Shot CoT can even degrade performance. These findings provide practical guidance for choosing CoT strategies based on model capacity, language characteristics, and task complexity.

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

↑