Prompt Optimization with EASE? Efficient Ordering-aware Automated Selection of Exemplars

📄 arXiv: 2405.16122v2 📥 PDF

作者: Zhaoxuan Wu, Xiaoqiang Lin, Zhongxiang Dai, Wenyang Hu, Yao Shu, See-Kiong Ng, Patrick Jaillet, Bryan Kian Hsiang Low

分类: cs.AI, cs.CL, cs.LG, stat.ML

发布日期: 2024-05-25 (更新: 2024-10-29)

备注: 28 pages, 1 figure, 35 tables

🔗 代码/项目: GITHUB


💡 一句话要点

EASE:高效排序感知的范例自动选择,优化LLM的Prompt

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 上下文学习 范例选择 Prompt优化 神经Bandit算法 大型语言模型

📋 核心要点

  1. 现有范例选择方法在测试时需要额外计算,存在数据暴露风险,且忽略了范例排序和指令对性能的影响。
  2. EASE利用预训练语言模型的嵌入表示有序范例集,并使用神经bandit算法优化范例集,同时考虑排序。
  3. 实验表明,EASE优于现有方法,并揭示了范例选择对上下文学习影响的实用见解,具有独立研究价值。

📝 摘要(中文)

大型语言模型(LLMs)在实际应用中展现了卓越的能力。上下文学习(ICL)允许我们通过在prompt中包含输入-标签范例,将LLM适配到下游任务,而无需模型微调。然而,prompt中这些范例的质量极大地影响了性能,突显了对有效自动范例选择方法的需求。最近的研究探索了基于检索的方法来选择针对单个测试查询定制的范例,但这可能由于额外的测试时计算和数据暴露风险而不太理想。此外,现有方法未能充分考虑范例排序对性能的影响。另一方面,现有范例选择方法通常忽略了指令的影响,而指令是prompt中的另一个重要组成部分。为了应对这些挑战,我们提出了一种名为EASE的新方法,它利用预训练语言模型的隐藏嵌入来表示有序的范例集,并使用神经bandit算法来优化范例集,同时考虑范例排序。我们的EASE可以有效地找到一个有序的范例集,该范例集对于给定任务的所有测试查询都表现良好,从而消除了测试时计算。重要的是,EASE可以很容易地扩展到联合优化范例和指令。通过广泛的实证评估(包括新颖的任务),我们证明了EASE优于现有方法,并揭示了关于范例选择对ICL影响的实际见解,这些见解可能具有独立的意义。

🔬 方法详解

问题定义:论文旨在解决大型语言模型上下文学习中,如何自动选择和排序范例,以及如何优化指令,以提高模型在下游任务中的性能。现有方法的痛点在于需要额外的测试时计算、存在数据暴露风险,并且忽略了范例排序和指令的影响。

核心思路:论文的核心思路是利用预训练语言模型的隐藏嵌入来表示有序的范例集,并使用神经bandit算法来优化范例集,同时考虑范例排序。通过这种方式,可以找到一个对于给定任务的所有测试查询都表现良好的有序范例集,从而消除测试时计算。

技术框架:EASE方法主要包含以下几个模块:1) 使用预训练语言模型获取范例的嵌入表示;2) 将有序的范例集表示为一个整体嵌入;3) 使用神经bandit算法来探索和利用不同的范例集,并优化范例的排序;4) 可选地,联合优化范例和指令。整体流程是离线完成范例和指令的优化,在线使用优化后的prompt进行推理。

关键创新:EASE的关键创新在于:1) 将有序的范例集表示为一个整体嵌入,从而可以考虑范例排序的影响;2) 使用神经bandit算法来优化范例集,从而可以在探索和利用之间进行平衡;3) 可以联合优化范例和指令,从而可以充分利用prompt中的所有信息。与现有方法的本质区别在于,EASE不需要额外的测试时计算,并且可以同时考虑范例排序和指令的影响。

关键设计:EASE的关键设计包括:1) 使用预训练语言模型的哪一层的隐藏嵌入来表示范例;2) 如何将有序的范例集表示为一个整体嵌入(例如,使用平均池化或连接);3) 神经bandit算法的具体选择(例如,Thompson Sampling或Upper Confidence Bound);4) 如何定义奖励函数来评估范例集的性能(例如,使用验证集上的准确率)。

🖼️ 关键图片

fig_0
img_1
img_2

📊 实验亮点

论文通过广泛的实验证明了EASE的优越性。在多个任务上,EASE都显著优于现有的范例选择方法。例如,在某些任务上,EASE可以将模型的准确率提高5%以上。此外,实验还表明,EASE可以有效地优化prompt中的指令,从而进一步提高模型的性能。这些结果表明,EASE是一种有效的prompt优化方法。

🎯 应用场景

EASE可应用于各种需要利用大型语言模型进行上下文学习的任务,例如文本分类、问答、摘要生成等。该方法能够提高模型的性能,并降低测试时计算成本,具有广泛的应用前景。此外,EASE还可以用于优化prompt中的指令,从而进一步提高模型的性能。未来,EASE可以扩展到处理更复杂的prompt结构和更广泛的任务。

📄 摘要(原文)

Large language models (LLMs) have shown impressive capabilities in real-world applications. The capability of in-context learning (ICL) allows us to adapt an LLM to downstream tasks by including input-label exemplars in the prompt without model fine-tuning. However, the quality of these exemplars in the prompt greatly impacts performance, highlighting the need for an effective automated exemplar selection method. Recent studies have explored retrieval-based approaches to select exemplars tailored to individual test queries, which can be undesirable due to extra test-time computation and an increased risk of data exposure. Moreover, existing methods fail to adequately account for the impact of exemplar ordering on the performance. On the other hand, the impact of the instruction, another essential component in the prompt given to the LLM, is often overlooked in existing exemplar selection methods. To address these challenges, we propose a novel method named EASE, which leverages the hidden embedding from a pre-trained language model to represent ordered sets of exemplars and uses a neural bandit algorithm to optimize the sets of exemplars while accounting for exemplar ordering. Our EASE can efficiently find an ordered set of exemplars that performs well for all test queries from a given task, thereby eliminating test-time computation. Importantly, EASE can be readily extended to jointly optimize both the exemplars and the instruction. Through extensive empirical evaluations (including novel tasks), we demonstrate the superiority of EASE over existing methods, and reveal practical insights about the impact of exemplar selection on ICL, which may be of independent interest. Our code is available at https://github.com/ZhaoxuanWu/EASE-Prompt-Optimization.