动态路由引导代码生成,复杂任务用意图推理,简单任务直接生成。
Intention Chain-of-Thought Prompting with Dynamic Routing for Code Generation
- 根据任务难度自动切换提示策略,简单任务用少样本,复杂任务用意图链推理。
- 在六个基准上达到顶尖性能,平均减少46.37%的令牌消耗。
- 适合需要高效、高质量代码生成的研究者与开发者使用。
大型语言模型在代码生成中展现出强大能力。现有思维链(CoT)提示方法虽能增强推理,但存在两大缺陷:一是统一应用导致简单任务过度思考;二是缺乏对代码生成中核心意图(如算法逻辑与时间复杂度)的抽象,使模型关注表面结构而忽视全局目标。受认知经济原则启发,我们提出RoutingGen——一种难度感知的动态路由框架,仅在必要时启用结构化推理。对于复杂任务,引入意图思维链(ICoT),引导模型捕捉核心算法设计与效率目标。在三个模型和六个标准代码生成基准上的实验表明,RoutingGen在多数场景下达到当前最优表现,平均减少46.37%的总令牌用量。此外,ICoT在挑战性基准上优于六种现有提示基线。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。