从猜测到占位:一种基于代价理论的不确定性感知代码补全框架
From Guessing to Placeholding: A Cost-Theoretic Framework for Uncertainty-Aware Code Completion
AI总结:
针对硬补全范式在不确定上下文中生成错误代码的问题,提出自适应占位补全框架,在高熵位置输出占位符,理论证明其期望代价低于硬补全,实验显示编辑代价降低19%-50%。
摘要:
尽管大型语言模型(LLMs)在代码补全方面表现出卓越的能力,但它们通常遵循硬补全(HC)范式,即使在上下文不足的情况下也强制生成完全具体的代码。我们对300万次真实交互的分析揭示了这种策略的局限性:61%的生成建议在采纳后被编辑或拒绝,尽管与用户后续代码的相似度超过80%,这表明模型在特定标记位置经常做出错误预测。受此观察启发,我们提出了自适应占位补全(APC),一种协作框架,通过在高熵位置策略性地输出显式占位符来扩展HC,允许用户通过IDE导航直接填充。理论上,我们将代码补全表述为不确定性下的代价最小化问题。基于填充占位符比纠正错误代价更低的观察,我们证明了存在一个临界熵阈值,超过该阈值APC的期望代价严格低于HC。我们通过从过滤后的真实编辑日志中构建训练数据,并设计基于代价的奖励函数用于强化学习,实例化了该框架。在1.5B至14B参数模型上的广泛评估表明,APC将期望编辑代价降低了19%至50%,同时保持了标准的HC性能。我们的工作为不确定性感知代码补全提供了理论基础和实用训练框架,证明了自适应放弃可以在不牺牲传统补全质量的情况下进行端到端学习。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。