arXiv:2605.01047cs.CRcs.AI2026-05

通过自适应遗忘技术,精准抑制大模型代码生成中的幻觉,降低恶意包攻击风险。

LLM Ghostbusters: Surgical Hallucination Suppression via Adaptive Unlearning

  • 采用混合标记级目标,同时强化真实输出、压制幻觉内容。
  • 将包幻觉率降低81%,显著缩小恶意包攻击面。
  • 无需人工标注,可自动发现新幻觉场景,适用于多种领域。

幻觉——看似合理却事实错误的输出——仍是部署后大语言模型面临的挑战。在代码生成中,模型常虚构不存在的软件包,推荐虚假库的导入和安装命令,引发供应链漏洞:攻击者可提前注册带恶意载荷的虚构包,被开发者或自主代理下载执行,形成称为slopsquatting的包混淆攻击。模型部署后难以缓解:全量重训成本高,现有方法或严重损害模型实用性,或依赖预设遗忘集,而该假设不适用于无限可能的幻觉空间。为此,我们提出自适应遗忘(AU)框架,可在部署后精准抑制幻觉并保持模型通用能力。AU采用混合标记级目标,同时强化有效输出、抑制幻觉生成;结合自适应发现循环,无需人工监督即可持续识别新幻觉上下文,实现对未见提示和幻觉的泛化。实验表明,AU使包幻觉率下降81%,大幅减少slopsquatting攻击面,同时在标准编码基准上保持性能。分析显示,分布变化集中于包相关生成,整体编码行为基本不变,验证了其靶向性。AU仅使用模型生成数据,无需人工标注,具备跨领域泛化能力。

原文摘要 · Abstract (English)

Hallucinations, outputs that sound plausible but are factually incorrect, remain an open challenge for deployed LLMs. In code generation, models frequently hallucinate non-existent software packages, recommending imports and installation commands for fictional libraries. This creates a critical supply-chain vulnerability: an attacker can proactively register such packages on public registries with malicious payloads that are subsequently installed and executed by developers or autonomous agents, a class of package confusion attack known as slopsquatting. Once a model is deployed, mitigating this failure mode is difficult: full retraining is costly, and existing approaches either cause severe degradation of model utility or rely on a pre-specified forget-set, an assumption that does not apply to the unbounded space of hallucinations. To address this problem, we present Adaptive Unlearning (AU), a post-deployment framework that surgically suppresses hallucinations while preserving general model utility. AU introduces a hybrid token-level objective that simultaneously reinforces valid outputs and suppresses hallucinated ones. Combined with an adaptive discovery loop that continuously surfaces new hallucination-inducing contexts without human supervision, AU enables generalization to unseen prompts and hallucinations. We demonstrate that AU reduces package hallucination rates by 81%, corresponding to a substantial reduction in slopsquatting attack surface, while maintaining performance on standard coding benchmarks. Our analysis shows that distributional changes are concentrated on package-related generations, leaving general coding behavior largely unaffected and confirming that AU's effect is isolated to the targeted distribution. AU operates entirely on model-generated data, requires no human annotation, and generalizes across domains.

幻觉抑制代码生成安全防御自适应学习

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