arXiv:2604.01849cs.CL2026-04

让代码模型学会在不确定时留空,降低修改成本。

From Guessing to Placeholding: A Cost-Theoretic Framework for Uncertainty-Aware Code Completion

  • 模型在高不确定位置输出占位符,由用户直接填写。
  • 实测编辑成本降低19%至50%,且不损失常规生成质量。
  • 适合需要高效开发的程序员和注重代码准确性的团队。

大型语言模型在代码补全中表现优异,但通常采用硬补全(HC)模式,即使上下文不足也强制生成完整代码。对300万次真实交互的分析显示,61%的建议被修改或拒绝,尽管与用户后续代码相似度超过80%,表明模型在特定位置频繁误判。为此,我们提出自适应占位符补全(APC),通过在高熵位置输出显式占位符,让用户通过IDE导航直接填充。理论上,我们将代码补全建模为不确定性下的成本最小化问题,证明在熵阈值以上,使用占位符的期望成本低于硬补全。我们基于过滤后的真实编辑日志构建训练数据,并设计基于成本的奖励函数用于强化学习。在15亿至140亿参数模型上的评估表明,APC将预期编辑成本从19%降至50%,同时保持传统补全性能。本工作为不确定性感知的代码补全提供了理论基础与可训练框架,证明自适应放弃生成可端到端学习,且不影响传统补全质量。

原文摘要 · Abstract (English)

While Large Language Models (LLMs) have demonstrated exceptional proficiency in code completion, they typically adhere to a Hard Completion (HC) paradigm, compelling the generation of fully concrete code even amidst insufficient context. Our analysis of 3 million real-world interactions exposes the limitations of this strategy: 61% of the generated suggestions were either edited after acceptance or rejected despite exhibiting over 80% similarity to the user's subsequent code, suggesting that models frequently make erroneous predictions at specific token positions. Motivated by this observation, we propose Adaptive Placeholder Completion (APC), a collaborative framework that extends HC by strategically outputting explicit placeholders at high-entropy positions, allowing users to fill directly via IDE navigation. Theoretically, we formulate code completion as a cost-minimization problem under uncertainty. Premised on the observation that filling placeholders incurs lower cost than correcting errors, we prove the existence of a critical entropy threshold above which APC achieves strictly lower expected cost than HC. We instantiate this framework by constructing training data from filtered real-world edit logs and design a cost-based reward function for reinforcement learning. Extensive evaluations across 1.5B--14B parameter models demonstrate that APC reduces expected editing costs from 19% to 50% while preserving standard HC performance. Our work provides both a theoretical foundation and a practical training framework for uncertainty-aware code completion, demonstrating that adaptive abstention can be learned end-to-end without sacrificing conventional completion quality.

代码生成大模型不确定性占位符

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。