[Paper Review] Automatic Prompt Optimization with "Gradient Descent" and Beam Search
This paper introduces Prompt Optimization with Textual Gradients (ProTeGi), a nonparametric, API-based method that uses natural language 'gradients' derived from model feedback to iteratively refine prompts via a beam search guided by bandit selection. It improves initial prompts by up to 31% on NLP benchmarks and jailbreak detection, outperforming prior methods with fewer LLM API calls.
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.
Motivation & Objective
- To address the high human effort required to manually craft effective prompts for large language models (LLMs).
- To develop a general-purpose, nonparametric method for automatic prompt optimization that works with standard LLM APIs without requiring access to internal model states.
- To improve prompt quality by systematically refining vague or suboptimal prompts using semantic feedback from model predictions.
- To enhance algorithmic efficiency through beam search with bandit-based candidate selection, reducing reliance on random or directionless search.
- To demonstrate the method's effectiveness across diverse NLP tasks, including novel applications like LLM jailbreak detection.
Proposed method
- The method uses minibatches of training data to generate natural language 'gradients'—feedback describing flaws in the current prompt’s predictions—mimicking numerical gradient descent.
- These textual gradients are used to guide prompt edits in the opposite semantic direction, effectively performing discrete, semantic 'gradient descent' on the prompt.
- A beam search is employed to explore multiple prompt candidates, with expansion guided by the textual gradients to maintain semantic directionality.
- Candidate selection within the beam uses a best-arm identification strategy from bandit literature to efficiently select the most promising prompts.
- The process is iterative: each round evaluates the current prompt on a batch, generates a gradient, edits the prompt, and proceeds to the next iteration.
- The framework relies solely on LLM API interactions, using GPT-based prompts for feedback generation and editing, avoiding any model fine-tuning or auxiliary training.
Experimental results
Research questions
- RQ1Can a nonparametric, API-only method improve prompt quality without requiring access to model internals or hyperparameter tuning?
- RQ2Can textual gradients derived from model feedback guide effective, directed prompt optimization in a discrete, natural language space?
- RQ3How does beam search with bandit selection improve efficiency and performance compared to random or monte-carlo search in prompt optimization?
- RQ4To what extent can this method improve performance on diverse NLP tasks, including novel applications like jailbreak detection?
- RQ5How interpretable and robust is the optimization process when applied to real-world prompts?
Key findings
- ProTeGi improved an initial prompt’s performance by up to 31% across three benchmark NLP tasks and a novel jailbreak detection task.
- The method outperformed state-of-the-art prompt learning baselines by an average of 4-8% across all evaluated tasks.
- Despite relying on many LLM API calls, ProTeGi achieved significant performance gains with relatively fewer calls than baseline methods, indicating improved algorithmic efficiency.
- The optimization process was interpretable, with each prompt revision clearly reflecting feedback from model predictions and data.
- The framework demonstrated robustness across diverse tasks, including text classification and safety-related detection, suggesting broad applicability.
- The method’s performance was limited by API rate limits, with optimization taking over an hour even with small query budgets, highlighting a key scalability constraint.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.