Automatic Prompt Optimization with "Gradient Descent" and Beam Search

Reid Pryzant, Dan Iter, Jerry Li, Yin Tat Lee, Chenguang Zhu +1 more
5/4/2023
cs.CLcs.AIcs.LG

No official code found. Best implementation: microsoft/LMOps (4,440 stars, MIT, last commit 2026-04-30). 1 more below.

Abstract

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.

View on arXivView PDF

Code Implementations(2)

microsoft/LMOpsCommunity100%
MIT

General technology for enabling AI capabilities w/ LLMs and MLLMs

4,440377C, C++Dec 13, 20225 months agoMIT
agigptlanguage-modelllmlm+6 more

A simple Auto Prompt Optimization: Implementation of https://arxiv.org/pdf/2305.03495

20Oct 26, 20241 years ago

Similar Papers

Cite this paper

@article{pryzant2023automatic,
  title  = {Automatic Prompt Optimization with "Gradient Descent" and Beam Search},
  author = {Reid Pryzant and Dan Iter and Jerry Li and Yin Tat Lee and Chenguang Zhu and Michael Zeng},
  year   = {2023},
  eprint = {2305.03495},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2305.03495v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2305.03495.svg)](https://codeofpaper.com/paper/2305.03495)

Discussion