基于大语言模型的测试驱动代码生成中贝叶斯提示优化的探索性研究
An Exploratory Study of Bayesian Prompt Optimization for Test-Driven Code Generation with Large Language Models
AI总结:
本文提出BODE-GEN方法,通过贝叶斯优化优化提示以提高大语言模型生成代码的准确性,实验表明其在代码生成准确性上优于固定提示和手动提示工程。
摘要:
我们考虑使用大语言模型(LLMs)生成功能正确的代码任务。生成代码的正确性受用于查询给定基础LLM的提示的影响。我们将寻找合适提示的问题表述为组合搜索过程,并提出一种称为"贝叶斯优化(BO)用于代码生成(BODE-GEN)"的贝叶斯优化方法。BODE-GEN在提示上进行自适应数据驱动搜索,该搜索由训练数据形式的尝试过的提示和生成代码在给定测试用例上的功能准确性引导。关键见解是通过使用辅助LLM在连续嵌入空间中进行贝叶斯优化,以弥合离散提示空间和连续嵌入空间之间的差距。我们利用两个协同思想,即随机投影和维度缩放先验,来构建有效的高维嵌入空间上的高斯过程基于替代模型。我们在HumanEval+基准上使用多种基础LLM进行实验,结果表明BODE-GEN在代码生成准确性方面比固定提示和手动提示工程有所提升。此外,我们证明BODE-GEN是样本高效的,只需要相对较少的BO迭代次数就能在代码准确性上取得改进。
英文摘要:
We consider the task of generating functionally correct code using large language models (LLMs). The correctness of generated code is influenced by the prompt used to query the given base LLM. We formulate the problem of finding the appropriate prompt as combinatorial search process and propose a Bayesian optimization (BO) approach referred to as {\em BO for Code GENeration (BODE-GEN)}. BODE-GEN performs an adaptive data-driven search over prompts guided by training data in the form of prompts tried and the functional accuracy of the generated code over a set of given test cases. The key insight is to perform BO in continuous embedding space by using an auxiliary LLM to bridge the gap between discrete prompt space and continuous embedding space. We leverage two synergistic ideas, namely, random projections and dimensionality scaled priors, to build effective Gaussian process based surrogate models over the high-dimensional embedding space. Our experiments on the HumanEval+ benchmark using multiple base LLMs show that BODE-GEN can improve performance in terms of code generation accuracy compared to fixed prompts and manual prompt engineering. Additionally, we demonstrate that BODE-GEN is sample-efficient, requiring relatively few iterations of BO to demonstrate improvements in code accuracy.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。