Large Language Models (LLMs) excel in various tasks, but they rely on carefully crafted prompts that often demand substantial human effort. To automate this process, in this paper, we propose a novel framework for discrete prompt optimization, called EvoPrompt, which borrows the idea of evolutionary algorithms (EAs) as they exhibit good performance and fast convergence. To enable EAs to work on discrete prompts, which are natural language expressions that need to be coherent and human-readable, we connect LLMs with EAs. This approach allows us to simultaneously leverage the powerful language processing capabilities of LLMs and the efficient optimization performance of EAs. Specifically, abstaining from any gradients or parameters, EvoPrompt starts from a population of prompts and iteratively generates new prompts with LLMs based on the evolutionary operators, improving the population based on the development set. We optimize prompts for both closed- and open-source LLMs including GPT-3.5 and Alpaca, on 9 datasets spanning language understanding and generation tasks. EvoPrompt significantly outperforms human-engineered prompts and existing methods for automatic prompt generation by up to 25% and 14% respectively. Furthermore, EvoPrompt demonstrates that connecting LLMs with EAs creates synergies, which could inspire further research on the combination of LLMs and conventional algorithms.
翻译:大型语言模型(LLMs)在各类任务中表现出色,但其依赖精心设计的提示(prompts),这往往需要大量人力投入。为实现自动化,本文提出一种名为EvoPrompt的新型离散提示优化框架,该框架借鉴演化算法(EAs)的思想,因其兼具良好的性能与快速收敛特性。为让EAs能够处理离散提示(即需保持连贯性与可读性的自然语言表述),我们将LLMs与EAs相结合。该方法可同时利用LLMs强大的语言处理能力与EAs高效的优化性能。具体而言,无需任何梯度或参数,EvoPrompt从初始提示群体出发,基于演化算子迭代地通过LLMs生成新提示,并根据开发集改进群体。我们针对GPT-3.5和Alpaca等闭源与开源LLMs,在涵盖语言理解与生成任务的9个数据集上优化提示。EvoPrompt在自动提示生成方面相比人工设计提示及现有方法分别提升高达25%和14%。此外,EvoPrompt证明LLMs与EAs的连接可产生协同效应,这将为LLMs与传统算法结合的进一步研究提供启示。