[论文解读] Automatic Prompt Optimization with "Gradient Descent" and Beam Search
本文提出文本梯度提示优化(ProTeGi),一种非参数化、基于API的方法,利用从模型反馈中提取的自然语言“梯度”,通过带 bandit 选择的束搜索迭代优化提示。该方法在 NLP 基准测试和 jailbreak 检测任务中,将初始提示性能提升最高达 31%,且在更少的大语言模型 API 调用下超越了先前方法。
Large Language Models (LLMs) have shown impressive performance as general purpose agents, but their abilities remain highly dependent on prompts which are hand written with onerous trial-and-error effort. We propose a simple and nonparametric solution to this problem, Automatic Prompt Optimization (APO), which is inspired by numerical gradient descent to automatically improve prompts, assuming access to training data and an LLM API. The algorithm uses minibatches of data to form natural language "gradients" that criticize the current prompt. The gradients are then "propagated" into the prompt by editing the prompt in the opposite semantic direction of the gradient. These gradient descent steps are guided by a beam search and bandit selection procedure which significantly improves algorithmic efficiency. Preliminary results across three benchmark NLP tasks and the novel problem of LLM jailbreak detection suggest that Automatic Prompt Optimization can outperform prior prompt editing techniques and improve an initial prompt's performance by up to 31%, by using data to rewrite vague task descriptions into more precise annotation instructions.
研究动机与目标
- 解决为大型语言模型(LLMs)手动设计有效提示所需的高昂人力成本问题。
- 开发一种通用的、非参数化的自动提示优化方法,仅依赖标准 LLM API,无需访问模型内部状态。
- 通过利用模型预测提供的语义反馈,系统性地改进模糊或次优提示的质量。
- 通过使用束搜索结合基于 bandit 的候选选择策略,提升算法效率,减少对随机或无方向搜索的依赖。
- 在多种 NLP 任务中验证该方法的有效性,包括 LLM jailbreak 检测等新型应用场景。
提出的方法
- 该方法使用训练数据的小批量来生成自然语言“梯度”——即描述当前提示预测缺陷的反馈,模拟数值梯度下降过程。
- 这些文本梯度被用于引导提示的修改,方向与语义相反,从而在提示上实现离散的、语义上的“梯度下降”。
- 采用束搜索来探索多个提示候选,通过文本梯度引导扩展过程,以保持语义方向性。
- 束内候选选择采用 bandit 文献中的最优臂识别策略,高效选择最具潜力的提示。
- 该过程为迭代式:每轮在小批量上评估当前提示,生成梯度,修改提示,并进入下一轮迭代。
- 该框架仅依赖 LLM API 交互,使用基于 GPT 的提示生成反馈与编辑,避免任何模型微调或辅助训练。
实验结果
研究问题
- RQ1一种仅基于 API 的非参数化方法是否能在不访问模型内部结构或超参数调优的情况下,提升提示质量?
- RQ2从模型反馈中提取的文本梯度是否能有效引导离散自然语言空间中的有向提示优化?
- RQ3与随机或蒙特卡洛搜索相比,结合 bandit 选择的束搜索在提示优化中如何提升效率与性能?
- RQ4该方法在多种 NLP 任务中,包括 jailbreak 检测等新型应用,能将性能提升到何种程度?
- RQ5当应用于真实世界提示时,该优化过程的可解释性与鲁棒性如何?
主要发现
- ProTeGi 在三个基准 NLP 任务和一项新型 jailbreak 检测任务中,将初始提示性能最高提升了 31%。
- 在所有评估任务中,该方法平均优于最先进提示学习基线方法 4%-8%。
- 尽管依赖大量 LLM API 调用,ProTeGi 仍以远少于基线方法的调用次数实现了显著的性能提升,表明其具有更高的算法效率。
- 优化过程具有可解释性,每次提示修改均清晰反映了来自模型预测与数据的反馈。
- 该框架在多种任务中表现出鲁棒性,包括文本分类和安全相关检测任务,表明其具有广泛适用性。
- 该方法的性能受限于 API 速率限制,即使在小查询预算下,优化过程仍耗时超过一小时,凸显了其关键的可扩展性瓶颈。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。