通过模型编辑缓解大型语言模型中的包幻觉
Mitigating Package Hallucinations in Large Language Models via Model Editing
AI总结:
提出BOUND框架,通过定位与包幻觉相关的模块并应用边界感知的LoRA适配器编辑,有效降低LLM在包推荐、代码生成等任务中的包幻觉率,同时保持有效包推荐。
摘要:
大型语言模型(LLMs)在软件工程任务中展现了强大能力,如代码生成、库推荐和依赖配置。然而,最近研究表明LLMs可能遭受包幻觉,即生成不存在或无效的包名。这些幻觉可能被利用于软件供应链攻击,因为攻击者可能以幻觉名称注册恶意包。因此,缓解包幻觉对于提高LLM辅助软件开发的可靠性和安全性至关重要。本文介绍了BOUND,一个轻量级的局部模型编辑框架,用于缓解LLMs中的包幻觉。BOUND将包幻觉缓解形式化为一个包有效性边界编辑问题,其中边界指模型在给定任务上下文中区分有效包与幻觉包名的能力。它首先通过风险感知定位策略定位与包幻觉相关的模块,然后使用边界感知目标(强化有效包、抑制幻觉包并保持局部行为)通过轻量级LoRA适配器编辑这些模块。实验结果表明,BOUND有效减少了包幻觉,同时保留了有效的包推荐。在包推荐任务中,BOUND在编辑提示上降低了79.9%的包级幻觉率(Package-HR),在未见提示上降低了65.4%。学习到的包有效性边界进一步泛化到其他包相关任务,在代码生成中降低了12.8%的Package-HR,在pip install推荐中降低了34.0%。这些结果表明BOUND优化了LLMs的包有效性边界,并提高了包相关输出的可靠性。
英文摘要:
Large language models (LLMs) have demonstrated strong capabilities in software engineering tasks, such as code generation, library recommendation, and dependency configuration. However, recent studies show that LLMs may suffer from package hallucination, where they generate non-existent or invalid package names. These hallucinations can be exploited in software supply chain attacks, as attackers may register malicious packages under hallucinated names. Therefore, mitigating package hallucination is important for improving the reliability and security of LLM-assisted software development. In this paper, we introduce BOUND, a lightweight localized model editing framework for mitigating package hallucinations in LLMs. BOUND formulates package hallucination mitigation as a package-validity boundary editing problem, where the boundary refers to the model's ability to distinguish valid packages from hallucinated package names under a given task context. It first locates modules related to package hallucination through a risk-aware localization strategy, and then edits these modules with lightweight LoRA adapters using a boundary-aware objective that reinforces valid packages, suppresses hallucinated packages, and preserves locality behavior. Experimental results show that BOUND effectively reduces package hallucinations while preserving valid package recommendations. In the package recommendation task, BOUND reduces package-level hallucination rate (Package-HR) by 79.9% on edit prompts and by 65.4% on unseen prompts. The learned package-validity boundary further generalizes to other package-related tasks, reducing Package-HR by 12.8% in code generation and by 34.0% in pip install recommendation. These results show that BOUND refines the package-validity boundary of LLMs and improves the reliability of package-related outputs.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。