Papers
Topics
Authors
Recent
Search
2000 character limit reached

Optimal Prompt Learning (OPL)

Updated 6 July 2026
  • Optimal Prompt Learning (OPL) is a framework that adapts frozen models by optimizing prompt interfaces, including discrete, continuous, and hybrid forms.
  • It leverages various algorithmic paradigms such as adversarial, reinforcement, and Bayesian methods to optimize prompts at both task-level and query-specific granularity.
  • Empirical findings show that OPL methods achieve notable performance gains and efficiency improvements in language, vision, and multimodal applications under limited data conditions.

Optimal Prompt Learning (OPL) denotes a family of prompt-optimization formulations in which a frozen foundation model is adapted by optimizing prompts rather than model parameters. In one formulation, OPL asks: given a frozen LLM, how can we find the best discrete prompt, consisting of an instruction and kk exemplars, under limited labeled data and compute; in Visual In-Context Learning (VICL), OPL is formulated as selecting a demonstration subset PSP\subseteq S that minimizes validation loss; in vision-LLMs, OPL also appears as learning multiple continuous prompts aligned to local visual features by optimal transport (Do et al., 2023, Zhu et al., 15 Jan 2025, Chen et al., 2022).

1. Conceptual scope

Across recent work, OPL is not a single algorithm but a problem class. The optimized object may be a discrete natural-language instruction, a set of in-context demonstrations, an ordering over examples, a role-playing system prompt, a query-dependent prompt generated by a smaller policy model, a prompt pool selected by a lightweight controller, or a set of continuous prompt embeddings attached to a frozen encoder. The common constraint is that the backbone model remains frozen or nearly frozen, while the prompt interface becomes the locus of adaptation (Do et al., 2023, Kong et al., 2024, Duan et al., 3 Jun 2025).

The term also spans several granularity levels. Some methods seek a single task-level prompt for an entire dataset, as in VICL task-level prompting. Others explicitly pursue query-specific prompts, arguing that task-level optimization overlooks query-preferred prompts. Still others treat prompt selection as instance-dependent routing over a fixed prompt pool, or as a sequential refinement process under a limited evaluation budget (Zhu et al., 15 Jan 2025, Kong et al., 2024, Li et al., 2023, Wang et al., 7 Jan 2025).

A recurrent motivation is the trade-off between prompt quality and optimization cost. Prior work cited in these papers includes heuristic re-scoring, soft prompts requiring back-propagation, reinforcement-learning-based methods with additional policy networks or reward models, and manual prompt engineering by trial and error. OPL methods therefore differ not only in what they optimize, but in how they exploit labeled data, feedback, and search structure (Do et al., 2023, Liu et al., 2024, Wang et al., 7 Jan 2025).

2. Mathematical formulations

A generic discrete OPL formulation for LLMs defines prompt parameters PP as the exact wording of the instruction and demonstration pairs, with the objective of maximizing end-task performance when the prompt is fed to the LLM in an in-context fashion. In adversarial in-context learning, this becomes a minimax problem over generator and discriminator prompts: J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big], with

minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).

Here the prompts UU and VV replace parameter updates: the generator prompt is optimized to lower the adversarial objective, while the discriminator prompt is optimized to raise it (Do et al., 2023).

In VICL, the prompt is a KK-shot demonstration set PSP\subseteq S, where S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\} is a labeled validation pool and PSP\subseteq S0 is a pre-trained Vision Foundation Model. The sample-level objective seeks

PSP\subseteq S1

but because PSP\subseteq S2 is unknown at test time, prior work relies on a scoring function PSP\subseteq S3 to select demonstrations. The task-level reformulation instead defines a single prompt

PSP\subseteq S4

thereby replacing per-query prompt search with average-loss minimization on a held-out validation split (Zhu et al., 15 Jan 2025).

Query-dependent Prompt Optimization casts prompt generation as a single-step MDP PSP\subseteq S5, where states are natural-language queries and actions are prompts. The policy factorizes autoregressively over prompt tokens, and the reward combines query-level and task-level components. Training uses an offline objective

PSP\subseteq S6

where PSP\subseteq S7 is the prompt log-likelihood under teacher forcing and PSP\subseteq S8 is reward-prediction MSE (Kong et al., 2024).

A different formalization appears in sequential optimal learning for automated prompt engineering. There, prompts are encoded as a PSP\subseteq S9-dimensional feature vector PP0, the scalar utility is the logit-transform of the observed score, and a Bayesian regression posterior defines a knowledge state PP1. The acquisition function is the forward-looking Knowledge-Gradient

PP2

and the next prompt is selected by PP3. This turns prompt search into sequential optimal learning under a finite evaluation budget (Wang et al., 7 Jan 2025).

3. Algorithmic paradigms

Representative OPL methods span adversarial optimization, reinforcement learning, Bayesian sequential decision-making, and structured prompt selection (Do et al., 2023, Liu et al., 2024, Li et al., 2023, Kong et al., 2024, Wang et al., 7 Jan 2025, Duan et al., 3 Jun 2025, Lu et al., 23 Mar 2026, Esfahani et al., 18 May 2026).

Method Optimized prompt object Optimization mechanism
adv-ICL Discrete generator and discriminator prompts Two-player minimax game with a prompt modifier
GRL-Prompt In-context examples and their order RL over a knowledge-graph state with HGT, ICMN, and PEC
PP4 Readable discrete prompt set and input-specific prompt choice GPT-4 dialogue generation, SUE screening, and policy-gradient matching
QPO Query-specific natural-language prompt Multi-loop offline RL with dataset augmentation
ORPP Role-playing system prompt Iterative optimization on a small subset plus few-shot transfer
SOPL-KG Feature-based prompt vector Bayesian regression with Knowledge-Gradient and MISOCP
PPP5O Prompt templates for hard samples GEPA prompt evolution plus policy optimization
PPO code prompting Refined code-generation prompt PPO with direct, lexical-mutation, and semantic-rewrite actions

Adversarial and prompt-editing methods treat prompt search as black-box optimization over discrete text. adv-ICL employs one LLM as generator, another as discriminator, and a third as prompt modifier. Each iteration uses PP6 samples, PP7 candidates per edit, and PP8 rounds, and the method updates only prompts rather than model parameters (Do et al., 2023). ORPP restricts the search space to role-playing descriptions, iteratively optimizes prompts on a small subset PP9, and then transfers the optimization experience by using the top J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],0 optimized prompt-question pairs as few-shot exemplars for the remaining questions; its reported hyperparameters are J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],1 optimization rounds, J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],2 candidate prompts per round, and J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],3 few-shot exemplars (Duan et al., 3 Jun 2025).

RL-based OPL methods differ in the state and feedback they expose to the optimizer. GRL-Prompt constructs a knowledge graph J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],4 with a query node and candidate nodes, uses a two-layer Heterogeneous Graph Transformer to obtain contextualized node embeddings, and factorizes the joint policy into an In-Context Matching Network for selection and a Pairwise Edge Classifier for ordering. Its reward is J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],5, combining fuzzy textual similarity with cosine similarity between sentence embeddings (Liu et al., 2024). J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],6 generates a readable candidate prompt pool by multi-round dialogue with GPT-4, scores candidates with the SUE metric, and trains a two-layer MLP policy network with only J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],7 M new parameters, approximately J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],8 of RoBERTa-Large’s 354 M (Li et al., 2023). QPO instead learns a small GPT-2 policy entirely from offline prompting demonstration data and bootstraps both the dataset and the policy over J(DV,GU)=E(x,y)D[logDV(x,y)]+ExD[log(1DV(x,GU(x)))],\mathcal{J}(D_V, G_U) = \mathbb{E}_{(x,y)\sim \mathcal{D}}\big[\log D_V(x,y)\big] + \mathbb{E}_{x\sim \mathcal{D}}\big[\log(1 - D_V(x,\,G_U(x)))\big],9 loops (Kong et al., 2024).

Joint policy-prompt methods optimize prompts to improve exploration or dense supervision. PminUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).0O introduces a finite set of discrete prompt templates minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).1, identifies hard samples when empirical success falls below a near-zero threshold, evolves templates via Genetic-Pareto prompt optimization, and updates model parameters with context distillation so that prompt-induced reasoning gains are internalized by the policy (Lu et al., 23 Mar 2026). In code generation, prompt refinement is treated as a finite-horizon MDP with a hybrid action space minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).2, MiniLM prompt embeddings as states, and PPO as the optimizer (Esfahani et al., 18 May 2026).

4. Vision and multimodal instantiations

Visual OPL introduces a distinct question: whether prompts should be optimized per query or once per task. In task-level VICL, more than minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).3 of test samples achieve their best performance under the same prompt minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).4, whereas sample-level search methods such as UnsupPR and SupPR find the “optimal” prompt for approximately minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).5 of samples. This motivates replacing per-sample search with task-level search. The Top-minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).6 strategy computes one-shot scores for each candidate and selects the top minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).7 examples, with minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).8 forward-passes or minUmaxVJ(DV,GU).\min_U \max_V \mathcal{J}(D_V, G_U).9 including sorting; the Greedy strategy iteratively adds the example whose inclusion most lowers validation loss and has worst-case UU0 forward-passes (Zhu et al., 15 Jan 2025).

The empirical effect is substantial. On single-object detection, Greedy achieves UU1 mIoU versus the best sample-level method at approximately UU2. On foreground segmentation, Greedy reaches UU3 average mIoU versus the best sample-level method at approximately UU4. On colorization, Greedy obtains UU5 MSE UU6, matching the Oracle upper bound. Across tasks, Greedy comes within UU7 of the Oracle while using less than UU8 of the search time of sample-level methods (Zhu et al., 15 Jan 2025).

In vision-LLMs, PLOT uses OPL in a different sense: learning multiple continuous prompts per class and aligning them to local visual features by optimal transport. Visual and prompt features are modeled as discrete distributions, the cost matrix is defined by UU9, and the entropically regularized OT distance is optimized by Sinkhorn iterations in an inner loop, while supervised classification loss updates the prompt vectors in an outer loop. With VV0 prompts, local features from RN50’s last attention pooling, and VV1, PLOT improves the average over 11 few-shot datasets from CoOp’s VV2 to VV3 at shots VV4, corresponding to gains of VV5 (Chen et al., 2022).

RPLKG emphasizes interpretability and efficiency rather than continuous prompt optimization. It converts ConceptNet triplets into human-readable prompts, caches CLIP text and image embeddings after a one-time forward pass, and learns only a small Gumbel-Softmax selection head with approximately VV6 M parameters, less than VV7 of CLIP. Reported efficiency numbers are training time per step of approximately VV8 s versus CoOp’s VV9 s and CoCoOp’s KK0 s, and peak GPU memory of approximately KK1 GB versus approximately KK2 GB to KK3 GB (Lim et al., 2023).

5. Empirical findings and efficiency patterns

Several language-side OPL methods report gains under strict data or compute constraints. adv-ICL is evaluated on 13 benchmarks across generation, classification, reasoning, MMLU, and BIG-Bench Hard. Relative to few-shot prompting, average absolute gains are KK4 ROUGE-L, KK5 percentage points, and KK6 percentage points for Text-Davinci-002; KK7 ROUGE-L, KK8 percentage points, and KK9 percentage points for Vicuna-13B; and PSP\subseteq S0 ROUGE-L, PSP\subseteq S1 percentage points, and PSP\subseteq S2 percentage points for ChatGPT. On MMLU with 5-shot ChatGPT, the average rises from PSP\subseteq S3 to PSP\subseteq S4; on BBH with 3-shot CoT ChatGPT, performance rises from PSP\subseteq S5 to PSP\subseteq S6 (Do et al., 2023).

PSP\subseteq S7 reports PSP\subseteq S8 average accuracy on four sentiment datasets versus RLPrompt’s PSP\subseteq S9, a S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}0 gain, while training only S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}1 M new parameters and requiring S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}2 minutes on SST-2, which is S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}3 of RLPrompt’s S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}4 minutes on a single RTX 3090 (Li et al., 2023). QPO reports average accuracy across six NLU tasks of S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}5 in zero-shot versus Prompt-OIRL’s S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}6, S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}7 in 6-shot versus S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}8, and S={(x1,y1),,(xN,yN)}S=\{(x_1,y_1),\dots,(x_N,y_N)\}9 in 3-shot versus the best baseline at PSP\subseteq S00; on math reasoning it reports PSP\subseteq S01 versus Prompt-OIRL’s PSP\subseteq S02, while using PSP\subseteq S03-PSP\subseteq S04 lower LLM-inference cost (Kong et al., 2024).

Structured and role-based methods also show consistent gains. GRL-Prompt outperforms recent state-of-the-art methods with average improvements of PSP\subseteq S05 ROUGE-1, PSP\subseteq S06 ROUGE-2, PSP\subseteq S07 ROUGE-L, and PSP\subseteq S08 BLEU, and its ablations report drops of PSP\subseteq S09 ROUGE-1, PSP\subseteq S10 ROUGE-2, PSP\subseteq S11 ROUGE-L, and PSP\subseteq S12 BLEU without the knowledge graph, plus further drops without RL (Liu et al., 2024). ORPP reports, for example, on Qwen-32B, PSP\subseteq S13 on GPQA versus the base model’s PSP\subseteq S14, PSP\subseteq S15 on MATH versus PSP\subseteq S16, and PSP\subseteq S17 on MMLU-Pro versus PSP\subseteq S18; it also reports that ORPP + CoT often yields additional gains, including PSP\subseteq S19 on MMLU-Pro for 14B and PSP\subseteq S20 for 32B (Duan et al., 3 Jun 2025).

Prompt optimization can also be coupled directly to policy learning. PPSP\subseteq S21O reports DeepMath-5K performance rising from a GRPO baseline of PSP\subseteq S22 to PSP\subseteq S23 for PPSP\subseteq S24O(Self-Ref), and DeepScaler-5K performance rising from PSP\subseteq S25 to PSP\subseteq S26 for PPSP\subseteq S27O(Teacher-Ref), corresponding to PSP\subseteq S28 on the out-of-distribution benchmark; on AIME24 and AIME25 it reports gains of PSP\subseteq S29 and PSP\subseteq S30 over GRPO (Lu et al., 23 Mar 2026). In code generation, PPO-based prompt optimization achieves strict Pass@1 on the 500-task MBPP+ test set of PSP\subseteq S31, PSP\subseteq S32, and PSP\subseteq S33 for CodeT5+, CodeLLaMA, and DeepSeek-Coder, respectively, with corresponding soft Pass@1 of PSP\subseteq S34, PSP\subseteq S35, and PSP\subseteq S36 (Esfahani et al., 18 May 2026).

6. Limitations, debates, and open directions

A central debate concerns whether optimal prompts are task-level or query-level. The VICL results suggest that searching sample-level prompts can be redundant because many queries share the same best prompt, and Greedy task-level search reaches near-oracle performance at a fraction of the search cost (Zhu et al., 15 Jan 2025). QPO argues the opposite for language prompting: most existing prompt optimization methods only focus on task-level performance, overlooking the importance of query-preferred prompts, which leads to suboptimal performances (Kong et al., 2024). These results do not strictly contradict one another; rather, they suggest that the appropriate granularity of OPL depends on modality, task structure, and the geometry of the prompt-response landscape.

Another misconception is that prompt optimization concerns prompt wording alone. The surveyed methods optimize example selection, example ordering, role framing, prompt pools, continuous prompt embeddings, prompt features, and prompt templates for hard-sample exploration. This suggests that “prompt” in OPL is best understood as an interface variable between data and a frozen model, not merely as a sentence prefix (Liu et al., 2024, Chen et al., 2022, Wang et al., 7 Jan 2025, Lu et al., 23 Mar 2026).

The limitations reported across papers are also heterogeneous. VICL task-level OPL requires a labeled validation pool PSP\subseteq S37, depends on the representativeness of PSP\subseteq S38, and offers no formal convergence guarantee for the Greedy procedure (Zhu et al., 15 Jan 2025). adv-ICL relies on the prompt modifier’s paraphrasing quality and on balancing generator and discriminator capacity; as a black-box method, it has no formal guarantee of global optimum in finite time (Do et al., 2023). GRL-Prompt uses purely automatic reward based on ROUGE, BLEU, and embedding similarity, which may not align with human preference (Liu et al., 2024). ORPP depends on a separate reward model, and some prompt combinations can hurt performance (Duan et al., 3 Jun 2025). Sequential optimal learning requires manual feature construction and may face expensive MISOCP solves as the feature dimension grows (Wang et al., 7 Jan 2025). PPO-based code prompting incurs high computational cost because each step involves multiple LLM generations and sandboxed execution (Esfahani et al., 18 May 2026).

The research directions proposed in these works are convergent. They include scaling to multimodal or vision-language settings, integrating human feedback or RLHF-style supervision, jointly optimizing prompt length and content, learning adaptive numbers of prompts per class, extending from discrete prompts to continuous or hybrid prompt spaces, and developing stronger theory for convergence and sample efficiency under discrete search (Do et al., 2023, Chen et al., 2022, Liu et al., 2024, Duan et al., 3 Jun 2025, Wang et al., 7 Jan 2025). A plausible implication is that future OPL systems will combine structured prompt representations, cheap proxy models or reward models, and explicit budget-aware search, rather than relying on any single prompt-engineering heuristic.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Optimal Prompt Learning (OPL).