TL;DR
Optimizing prompt-selection policies from logged user feedback (like clicks) typically fails because large prompt spaces cause extreme variance in importance sampling and high bias in reward models. The authors introduce Direct Sentence Off-policy gradient (DSO), which circumvents this by computing policy gradients directly in the space of generated sentences rather than prompts. By leveraging sentence-level semantic similarity via kernels, DSO dramatically reduces variance and outperforms existing bandit approaches on a newly introduced benchmark suite, OfflinePrompts.
What Problem Does This Paper Address?
Adapting prompts for a frozen Large Language Model (LLM) is safer, cheaper, and more accessible than fine-tuning weights directly—especially when using commercial closed-source APIs. In production systems (such as personalized recommendations or search), we want to learn a prompt policy that selects the best prompt for a specific user using logged interaction data.
However, logged data provides only bandit feedback: we only see user reactions to the single prompt chosen by the historical logging policy. Standard Off-Policy Learning (OPL) methods struggle here:
- Reward regression suffers from heavy bias under covariate shift and complex prompt-reward relationships.
- Importance Sampling (IS) blows up in variance or fails due to deficient support when the candidate prompt set is large.
Crucially, standard bandit methods treat prompts as mutually independent, completely ignoring the fact that distinct prompts often produce semantically similar sentences.
Methods
The paper frames prompt selection as contextual bandits with auxiliary outputs, where a context $x = (u, q)$ (user and query) and chosen prompt action $a$ generate an auxiliary sentence $s \sim p_{\text{LLM}}(s|q, a)$, which subsequently receives reward $r$.
Instead of evaluating gradients in the discrete action space of prompts, the authors propose Direct Sentence Off-policy gradient (DSO):
- Marginalized Sentence Space ($\Phi(\mathcal{S})$): DSO groups generated outputs into neighborhoods using a kernel function $K(s, s'; x, \tau)$ (e.g., Gaussian or uniform) over sentence embeddings, parameterized by bandwidth $\tau$.
-
Sentence-Space Importance Sampling: DSO applies importance weights over sentence neighborhoods rather than raw prompts: $$w(\phi(s), x) = \frac{\pi_\theta(\phi(s)|x)}{\pi_0(\phi(s)|x)}$$ This prevents extreme importance weights because multiple prompts map to overlapping sentence clusters.
-
Implicit Data Augmentation: The weighted score function is evaluated by conditioning actions on generated sentences, effectively spreading credit across multiple prompts that would have yielded similar text.
- Tractable Density Estimation: The logging policy's marginal sentence density $\pi_0(\phi(s)|x)$ is pre-computed once using either Monte Carlo sampling or neural function approximation, eliminating the need to scale with prompt set size $|\mathcal{A}|$.
[User & Query Context]
│
▼
[Prompt Policy] ──(Picks Prompt)──► [Frozen LLM] ──► [Generated Sentence]
│
(DSO Groups Similar Sentences via Kernels)
│
▼
[Reduced-Variance Off-Policy Gradient]
Datasets
The authors release OfflinePrompts, an open-source PyTorch benchmark suite:
- Synthetic Benchmark: Controlled 5-dimensional feature spaces for user contexts, query vectors, prompt actions, and sentence representations (utilizing sinusoidal mappings and controlled Gaussian noise) to systematically evaluate scalability.
- Semi-Synthetic Full-LLM Benchmark (MovieLens-10M): Simulates generating personalized movie descriptions. Titles and user ratings from MovieLens-10M are augmented with Mistral-7B (
Mistral-7B-Instruct-v0.2) generations. Rewards are simulated using a fine-tuned DistilBERT collaborative filtering model, evaluated across a candidate pool of 1,000 prompt keywords scraped fromrelatedwords.io.
Key Insights and Ideas
- Sentences Collapse the Action Space: While there may be thousands of discrete prompt variations, the space of distinct meanings generated by the LLM is far smaller. Smoothing across output sentences relaxes strict action support requirements to a much milder similar sentence support condition.
- The Kernel Bandwidth ($\tau$) Bias-Variance Tradeoff:
- A larger bandwidth increases logging/target policy overlap, shrinking importance weights and variance.
- A smaller bandwidth minimizes within-neighbor reward shift, reducing estimation bias.
- Function Approximation Prevents Tail Instability: Learning a parametric regression model for the marginal density $\pi_0(\phi(s)|x)$ avoids near-zero density division artifacts that plague raw Monte Carlo estimates.
Key Results
- Synthetic Stress-Tests: When scaling action spaces to $|\mathcal{A}| \ge 500$ with reward noise $\sigma_r \ge 1.0$, baseline OPL methods (IS, Doubly Robust, POTEC) deteriorate sharply due to variance. DSO maintains stable optimality. Notably, DSO with only $n=500$ samples outperformed baselines trained on $n=8,000$ samples at $|\mathcal{A}|=1,000$.
- Full-LLM Movie Recommendation: In the MovieLens setup with 1,000 candidate prompts and $n=50,000$ logged interactions, DSO achieved substantially higher policy value gains over a "no-prompt" baseline compared to standard IS, regression, Doubly Robust, and POTEC. This held true using off-the-shelf Mistral-7B sentence embeddings compressed via PCA.
Limitations and Future Work
- Lack of an Efficient Doubly Robust (DR) Formulation: Extending DSO to a DR-style estimator is non-trivial because the regression baseline itself requires importance sampling in sentence space, preventing straightforward variance reduction.
- Embedding Dependency: Performance relies on the quality and metric properties of the sentence embedding space used by the kernel.
- Task Sparsity: In realistic LLM settings, most prompts have negligible effects while only a few alter user reception, creating inherent learning instability across all methods.
- Future Directions: Adapting DSO to continuous generative tasks like text-to-image diffusion models and testing on real-world logged human click datasets.
Summary updated