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 31 datasets covering language understanding, generation tasks, as well as BIG-Bench Hard (BBH) tasks. EvoPrompt significantly outperforms human-engineered prompts and existing methods for automatic prompt generation (e.g., up to 25% on BBH). 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的新型离散提示优化框架,该框架借鉴进化算法(EA)思想,因其具有良好性能与快速收敛特性。为使EA能处理离散提示——即需要连贯且可读的自然语言表达——我们将LLMs与EA相结合。该方法可同时利用LLMs强大的语言处理能力和EA高效的优化性能。具体而言,无需任何梯度或参数,EvoPrompt从一组初始提示出发,基于进化算子迭代式地利用LLMs生成新提示,并依据开发集改进种群。我们在涵盖语言理解、生成任务及BIG-Bench Hard(BBH)任务的31个数据集上,对包括GPT-3.5和Alpaca在内的闭源与开源LLMs进行提示优化。EvoPrompt显著优于人工设计的提示及现有自动提示生成方法(例如,在BBH上提升高达25%)。此外,EvoPrompt证明了LLMs与EA的结合能产生协同效应,这将启发关于LLMs与传统算法结合的进一步研究。