arXiv:2409.05923cs.SEcs.AI2024-09被引 8

通过不确定性筛选噪声,提升大模型单次生成代码的质量

$\mathbb{USCD}$: Improving Code Generation of LLMs by Uncertainty-Aware Selective Contrastive Decoding

  • 用特殊提示生成噪声,根据预测不确定性识别并剔除噪声
  • 在多个主流数据集上平均提升16.59%的通过率
  • 无需训练、可直接插入推理流程,适配各类代码大模型

大型语言模型在代码生成方面表现出色,但幻觉(如输出噪声)导致其难以一次生成高质量代码。本文提出一种简单有效的不确定性感知选择性对比解码机制($$\mathbb{USCD}\u0024$),以提升单次生成质量并减少输出噪声影响。我们设计了一种负向提示(即弱提示),通过移除标准少样本提示中的输入输出示例来生成噪声输出。初步研究表明,标记分布不确定性与输出噪声之间的Jensen-Shannon散度约为0.25,表明二者高度相关。随后,基于标准提示下的预测分布不确定性,选择性地消除由弱提示引发的输出噪声。该方法为仅推理阶段使用的即插即用型机制,具有良好的灵活性。在HumanEval、MBPP和MultiPL-E等广泛使用的基准上,针对InCoder-6b、CodeLlama-7b、WizardCoder-15b、StarCoder和Llama2-7b等多个模型进行的大量实验表明,所提方法显著提升了单次代码生成效果,平均通过率(pass@1)提升16.59%。代码与数据将开源于GitHub。

原文摘要 · Abstract (English)

Large language models (LLMs) have shown remarkable capabilities in code generation. However, the effects of hallucinations (e.g., output noise) make it particularly challenging for LLMs to generate high-quality code in one pass. In this work, we propose a simple and effective \textbf{u}ncertainty-aware \textbf{s}elective \textbf{c}ontrastive \textbf{d}ecoding ($\mathbb{USCD}$) mechanism to improve the quality of one-pass code generation in LLMs and reduce the impact of output noise. To be specific, we first elaborately designed a negative prompt (namely lame prompt) to output noise by removing input-output examples from the standard few-shot prompt. Our preliminary study shows that the Jensen-Shannon divergence (JS divergence) between token distribution uncertainty and the output noise is relatively low (approximately $0.25$), indicating their high relevance. Then, we selectively eliminate output noise induced by lame prompts based on the uncertainty of the prediction distribution from the standard prompt. Notably, our proposed plug-and-play mechanism is an inference-only method, enjoying appealing flexibility. Extensive experiments on widely used benchmarks, e.g., HumanEval, MBPP, and MultiPL-E, upon several LLMs (i.e., Inocder-6b, CodeLlama-7b, WizardCoder-15b, StarCoder, and Llama2-7b), demonstrate that our proposed USCD significantly improves one-pass code generation, with an average \textit{pass@$1$} scores increase of 16.59\%. We will release code and data on GitHub.

代码生成大模型去噪推理优化

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