arXiv:2606.03130cs.LG2026-06

用顶尖模型生成虚假代码补全,提升小模型抗幻觉能力

Synthetic Hallucinations, Real Gains: Hard Negatives from Frontier Models for FIM Hallucination Mitigation

论文配图:Synthetic Hallucinations, Real Gains: Hard Negatives from Frontier Models for FIM Hallucination Mitigation
图 1 · 摘自论文原文
  • 用前沿模型生成逼真的错误补全作为难负样本
  • 微调后在8种语言上准确率提升18.8点,编辑相似度提高0.22
  • 无需执行环境或人工标注,适合开源代码补全场景

小型开源代码模型在智能补全时仍会产生填空式(FIM)幻觉:语法合理但不存在于项目中的方法、参数、变量和导入。现有缓解方法要么需要每语言的执行沙盒(不支持中途输入),要么依赖大规模人工标注数据。本文提出无需执行的替代方案:利用前沿代码模型生成看似合理实则错误的补全作为硬负样本,通过其与真实开发者修改之间的对比,构建监督微调信号。管道从公共GitHub中抓取八种语言的FIM上下文,邀请三个前沿生成器针对四种来自Delulu分类法的幻觉类型各生成一个硬负样本,形成成对选择/拒绝数据集。在10万条精选子集上微调Qwen2.5-Coder-7B-Instruct,在所有语言和所有类型上,Delulu精确匹配提升18.8点,编辑相似度提升0.22;同时改善HumanEval-Infilling所有子集及SAFIM各类别。3B版本同样提升12.8点精确匹配,存在轻微通用补全性能下降。五维消融实验(规模、类型混合、语言覆盖、基模型族、难度感知误判率)及SFT vs. DPO/ORPO头对头对比,揭示关键设计因素。论文开源完整流程代码——生成、误判率判断、筛选与微调配方,可在任何宽松许可语料上端到端复现。

原文摘要 · Abstract (English)

Small open-source code models that power IDE autocomplete still emit hallucinated Fill-in-the-Middle (FIM) completions: syntactically natural calls to methods, parameters, variables, and imports that do not exist in the surrounding project. Existing mitigations either require per-language execution sandboxes that do not apply at mid-keystroke or preference-optimisation pipelines that need large human-labelled corpora. We propose an execution-free alternative: use frontier code models to synthesise plausible-but-wrong completions as hard negatives, then leverage the contrast between these synthetic hallucinations and the ground-truth developer edit as a supervised fine-tuning signal. Our pipeline scrapes multilingual FIM contexts from public GitHub across eight languages and asks a panel of three frontier generators to produce one hard negative per context for each of four hallucination types drawn from the Delulu taxonomy, a Docker-verified multilingual FIM hallucination benchmark, yielding a paired chosen/rejected dataset. Fine-tuning Qwen2.5-Coder-7B-Instruct on a 100K-row curated subset lifts Delulu exact match by +18.8 points and edit similarity by +0.22 on every language and every type, while also improving every HumanEval-Infilling split and every SAFIM subset. The same recipe at 3B lifts Delulu by +12.8 EM with a small, characterised general-FIM trade-off. Five-axis ablations (size, type mix, language coverage, base-model family, and a difficulty-aware fool rate) plus a head-to-head SFT vs. DPO/ORPO comparison map which design choices drive the gain. We release the full pipeline source code -- generation, fool-rate LLM judging, curation, and the FIM fine-tuning recipe -- so that the experiments in this paper can be reproduced end-to end on any permissively licensed corpus.

代码生成幻觉抑制微调FIM

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