arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2309.02772cs.SEcs.CL
收藏

热还是冷?面向大型语言模型代码生成的自适应温度采样

Hot or Cold? Adaptive Temperature Sampling for Code Generation with Large Language Models

Academy of Military Sciences(军事科学院);Peking University(北京大学);Advanced Institute of Big Data(大数据高级研究院)

Yuqi Zhu, Jia Li, Ge Li, YunFei Zhao, Jia Li, Zhi Jin, Hong Mei

AI总结:

本文提出自适应温度采样方法,根据代码令牌难度动态调整温度,显著提升代码生成性能。

摘要:

近年来,大型语言模型(LLMs)在代码生成方面展现出了令人印象深刻的能力。然而,现有的LLMs解码策略是为自然语言(NL)生成设计的,忽视了自然语言与编程语言(PL)之间的差异。由于这一忽视,针对代码生成的更优解码策略仍是一个开放问题。在本文中,我们进行了首次系统性研究,探索专门针对代码生成的解码策略。通过对代码令牌的损失分布进行分析,我们发现代码令牌可分为两类:难以预测的挑战性令牌和易于推断的自信令牌。其中,挑战性令牌主要出现在代码块的开始部分。基于上述发现,我们提出了一种简单而有效的方法:自适应温度(AdapT)采样,它在解码不同令牌时动态调整温度系数。当对挑战性令牌进行采样时,我们应用更大的温度,使LLMs能够探索多样化的选择。对于自信令牌,我们采用较小的温度,以避免尾部随机噪声的影响。我们将AdapT采样应用于不同规模的LLMs,并在两个流行的数据集上进行了评估。结果表明,AdapT采样显著优于最先进的解码策略。

英文摘要:

Recently, Large Language Models (LLMs) have shown impressive abilities in code generation. However, existing LLMs' decoding strategies are designed for Natural Language (NL) generation, overlooking the differences between NL and programming languages (PL). Due to this oversight, a better decoding strategy for code generation remains an open question. In this paper, we conduct the first systematic study to explore a decoding strategy specialized in code generation. With an analysis of loss distributions of code tokens, we find that code tokens can be divided into two categories: challenging tokens that are difficult to predict and confident tokens that can be easily inferred. Among them, the challenging tokens mainly appear at the beginning of a code block. Inspired by the above findings, we propose a simple yet effective method: Adaptive Temperature (AdapT) sampling, which dynamically adjusts the temperature coefficient when decoding different tokens. We apply a larger temperature when sampling for challenging tokens, allowing LLMs to explore diverse choices. We employ a smaller temperature for confident tokens avoiding the influence of tail randomness noises. We apply AdapT sampling to LLMs with different sizes and conduct evaluations on two popular datasets. Results show that AdapT sampling significantly outperforms state-of-the-art decoding strategy.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑