具有动态路由的意图链式思维提示法用于代码生成
Intention Chain-of-Thought Prompting with Dynamic Routing for Code Generation
AI总结:
RoutingGen通过动态路由策略优化代码生成,结合少样本提示与结构化推理策略ICoT,提升生成效率与质量。
摘要:
大型语言模型(LLMs)表现出强大的生成能力,并在代码生成中展现出巨大潜力。现有的链式思维(CoT)提示方法通过引发中间步骤来增强模型推理能力,但存在两个主要局限性:首先,其统一应用往往会诱导在简单任务上过度思考。其次,它们在代码生成中缺乏意图抽象,例如显式建模核心算法设计和效率,导致模型关注表面结构而忽视全局问题目标。受认知经济原则的启发,即仅在必要时进行结构化推理以节省认知资源,我们提出了RoutingGen,一种新的难度感知路由框架,能够动态适应代码生成的提示策略。对于简单任务,它采用少样本提示;对于更复杂的任务,它调用结构化推理策略,称为意图链式思维(ICoT),我们引入该策略以引导模型捕捉任务意图,如核心算法逻辑及其时间复杂度。在三个模型和六个标准代码生成基准上的实验表明,RoutingGen在大多数设置中实现了最先进的性能,同时在大多数设置中平均减少了46.37%的总token使用量。此外,ICoT在挑战性基准上优于六个现有的提示基线。
英文摘要:
Large language models (LLMs) exhibit strong generative capabilities and have shown great potential in code generation. Existing chain-of-thought (CoT) prompting methods enhance model reasoning by eliciting intermediate steps, but suffer from two major limitations: First, their uniform application tends to induce overthinking on simple tasks. Second, they lack intention abstraction in code generation, such as explicitly modeling core algorithmic design and efficiency, leading models to focus on surface-level structures while neglecting the global problem objective. Inspired by the cognitive economy principle of engaging structured reasoning only when necessary to conserve cognitive resources, we propose RoutingGen, a novel difficulty-aware routing framework that dynamically adapts prompting strategies for code generation. For simple tasks, it adopts few-shot prompting; for more complex ones, it invokes a structured reasoning strategy, termed Intention Chain-of-Thought (ICoT), which we introduce to guide the model in capturing task intention, such as the core algorithmic logic and its time complexity. Experiments across three models and six standard code generation benchmarks show that RoutingGen achieves state-of-the-art performance in most settings, while reducing total token usage by 46.37% on average across settings. Furthermore, ICoT outperforms six existing prompting baselines on challenging benchmarks.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。