Source-linked AI summary
BayesPrompt: human readable prompts that make sense
Franky Kevin Nando Tezoh, Ali Hussaini Umar, Alessandro Laio, Guido Sanguinetti, Riccardo Rende
TL;DR
Prompt optimisation often produces effective but unintelligible pseudoprompts, leaving fluency and task confidence in tension. BayesPrompt reframes optimisation as Bayesian inference and reports low-perplexity prompts with high readability, improving on existing techniques across question-and-answer tasks.
Problem
Existing prompt-optimisation methods often trade off task effectiveness against human fluency, leaving no prior method that achieves both.
Method
BayesPrompt reframes prompt optimisation as Bayesian inference, incorporating a prior over questions and sampling prompts with MCMC.
Results
The framework obtains low-perplexity prompts with high readability and significantly improves on existing techniques across question-and-answer tasks.
Takeaways & Limitations
For a target answer, the MCMC approach jointly improves confidence and fluency while uniquely sampling a probability distribution over questions.
Takeaways & Limitations
The analysis was performed on the relatively small Llama-3.2-1B model for computational efficiency.
Abstract
from arXiv · showhide
Reconstructing prompts that can elicit a desired answer or behaviour in an LLM is an open and important research topic. Optimisation methods which aim at minimising the perplexity of a given answer, however, consistently yield so-called pseudoprompts, unintelligible strings of tokens which can lack human interpretability. We argue that this is a consequence of the ill-posedness of the prompt optimisation task. By reframing the task as a Bayesian posterior inference over prompts, we propose an efficient algorithm to sample prompts which are both efficient (in terms of perplexity) and human readable. We compare our approach with state of the art alternatives showing on a real data set a marked improvement over a range of metrics.
1 INTRODUCTION
BayesPrompt reframes prompt optimisation as Bayesian inference to address pseudoprompts—short, non-sensical token sequences that can steer models reliably—and proposes an efficient method for human-readable prompts. Across question-and-answer tasks, the framework achieves low perplexity and high readability, improving on existing techniques.
- Problem: Optimal prompts are often short non-sensical token sequences that reliably steer models toward target outputs.These pseudoprompts reveal a gap between human intuition and model behavior.
- Bayesian reformulation: Neglecting the prior term in prompt optimisation gives rise to the pseudoprompt phenomenon.The paper explains this phenomenon by reformulating prompt optimisation in terms of Bayesian inference.
- Method: The proposed Markov-chain Monte Carlo algorithm obtains human readable prompts.Its aim is to produce prompts that are efficient in terms of resulting in the correct output with low perplexity and are also human interpretable.
- Method: Reverse language modelling provides effective initialisation that greatly improves prompt reconstruction quality for Bayesian and optimisation methods.The initialisation is used for both Bayesian and optimisation approaches.
- Evaluation: The framework obtains low perplexity prompts with high readability and significantly improves on existing techniques across question and answer tasks.The validation is both qualitative and quantitative.
2 RELATED WORK
Prior work frames prompt recovery as reverse engineering in discrete or continuous spaces, while developing gradient-based search and sampling methods for related language tasks. Existing methods face a trade-off between effective but uninterpretable prompts and fluent but task-disconnected prompts.
- Prompt learning: Prompt recovery inverts the usual question-to-answer direction and can be formulated in discrete token space or continuous embedding space.Early continuous-space studies found that learned soft prompts yield higher confidence in t…
- Prompt learning: Gradient-based discrete token search identifies replacements using gradients with respect to one-hot token encodings and was later adapted to elicit target generations.The initial method increased classification loss, while later work applied the strategy to target generation from LLMs.
- Sampling methods: MCMC sampling has been used for text generation by treating masked-language-model conditionals as proposal distributions in Metropolis-Hastings sampling.This approach draws samples from the model’s implicit energy rather than a valid joint distribution represented by the masked conditionals.
- Research gap: Existing literature presents a strict trade-off: optimized prompts are effective but uninterpretable, whereas fluent prompts are semantically disconnected from the target task.The paper identifies the absence of a prior method achieving both high task confidence and human fluency as the gap addressed by its framework.
3 BAYESIAN REFORMULATION OF THE PROBLEM
The paper reformulates prompt optimization as Bayesian inference by adding a prior over questions, encouraging fluent prompts while retaining answer likelihood. It then solves the resulting objective with gradient-based baselines and Metropolis-Hastings sampling using context-informed edits.
- Bayesian reformulation: Minimizing answer negative log-likelihood alone often produces ungrammatical, seemingly random-token prompts because the optimization problem is ill-posed.The model learns question tokens against a pretrained language model while holding its neural-network parameters fixed.
- Bayesian reformulation: Adding the prior P(q) makes the objective well-defined and encourages optimization toward fluent prompts.The prior factorizes autoregressively as P(q) = ∏ P(q_i|q_<i).
- Optimization methods: The resulting objective is addressed with greedy coordinate gradient, gradient descent, and Markov Chain Monte Carlo algorithms.GCG proposes token replacements using gradient information, while GD optimizes continuous sequence embeddings before mapping them back to discrete vocabulary tokens.
- Metropolis-Hastings sampler: Metropolis-Hastings samples prompts from P(q|a) by targeting −log P(a, q), balancing prior-respecting natural language structure with answer likelihood.The chain explores the prompt space V^n and requires initialization and proposals that promote good mixing in practice.
- Metropolis-Hastings sampler: MH proposals use discrete replacement, insertion, and deletion edits, with token replacements sampled from either preceding or succeeding lexical context.The forward model supplies left-context probabilities, while the independently trained backward model supplies right-context probabilities.
4 IMPLEMENTATION DETAILS
The method is evaluated on NQ-OPEN using a supervised fine-tuned forward Llama-3.2-1B-Instruct model and a LoRA-trained reverse model. Prompt inference applies GCG/GD optimization and Metropolis-Hastings MCMC to generate questions conditioned on answers.
- Dataset and Model: Evaluation uses the NQ-OPEN natural-language question-answer dataset with its standard train/test split and a supervised fine-tuned Llama-3.2-1B-Instruct model.The forward model is fine-tuned on the NQ-OPEN TRAIN split.
- GCG and GD for NQ-OPEN TEST: For each NQ-OPEN TEST answer, prompt learning uses greedy coordinate gradient for discrete token selection and gradient descent for continuous-space learning.These optimization procedures are applied using the forward Llama-3.2-1B-Instruct model and equation 2.
- Reverse-model: The reverse model is LoRA-fine-tuned on fully reversed NQ-OPEN TRAIN sequences to generate a reversed question from a reversed answer.This reverse-generation setup follows the procedure described in section 3.1.
- MCMC for NQ-OPEN TEST: Metropolis-Hastings MCMC explores P(q|a) ∝P(a|q) P(q) to generate diverse question samples conditioned on each answer.After fine-tuning both forward and reverse models, only the final state of each fixed-answer Markov-chain trajectory is retained as the optimized question.
5 RESULTS AND DISCUSSION
The results compare MCMC with optimisation-based baselines on prompt fluency and answer confidence, showing that MCMC best combines near-ground-truth confidence with fluency and stronger qualitative evaluations. Optimisation-based prompts often exhibit a pathological confidence–fluency trade-off and lack grammatical, syntactic, and semantic coherence.
- MCMC achieves the highest fluency, with a distribution closest to the ground truth, while GCG, GCG-Reg, and GD-PEZ remain noticeably less fluent.
- MCMC is the only compared method to jointly achieve near-ground-truth confidence and the best fluency.
- GCG’s excess confidence comes at the cost of a marked fluency gap, exemplifying the paper’s pseudoprompt trade-off.
- Warm-start initialisation does not meaningfully change GCG’s confidence pattern, whereas GD-PEZ remains close to ground truth under both initialisation schemes.
- Random-initialisation prompts from unregularized GCG, GCG-Reg, and GD-PEZ primarily consist of gibberish, unnecessary formatting symbols, and ungrammatical mixed-language text.
- Across plausibility and grammar correctness, MCMC outperforms GCG, GCG-Reg, and GD-PEZ under random initialisation.
6 CONCLUSION
The work reframes prompt optimisation as Bayesian inference, using a question prior and warm-start initialisation to produce fluent prompts that balance answer confidence and fluency. Its MCMC sampler also supports probabilistic sampling of questions, while the evaluation is limited to a small model and suggests broader methodological extensions.
- 6 CONCLUSION: Bayesian inference with a prior over questions is essential for learning fluent prompts instead of uninterpretable token sequences.The approach is contrasted with unregularized GCG and GD-PEZ.
- 6 CONCLUSION: The MCMC-based approach achieves slightly better joint answer confidence and fluency than regularized GCG with the prior and warm-start initialisation.Regularized GCG also improves the balance between confidence and fluency.
- 6 CONCLUSION: For a given target answer, the MCMC approach is the only method that samples a probability distribution of questions.This matches the probabilistic formulation of language models.
- 6 CONCLUSION: The analysis uses Llama-3.2-1B for computational efficiency, and the schemes can be ported without modification to much larger models.The paper identifies larger-model evaluation as a direction for future work.
- 6 CONCLUSION: Future work could replace Metropolis-Hastings with alternative sampling schemes such as Rosenbluth Sequential Monte Carlo.This is proposed as a computationally oriented extension.
- 6 CONCLUSION: Prompt inversion could also be extended to JEPA by defining inversion in representational space over latent states rather than token sequences.JEPA learns by predicting abstract latent representations of its target input.
A COMPARATIVE GRAPHS
Under warm-start initialisation, comparative graphs show MCMC consistently combines strong fluency with high confidence in the target answer, while GCG is preferable when confidence relative to ground truth is prioritised.
- A COMPARATIVE GRAPHS: Under warm-start initialisation, MCMC consistently yields prompts combining strong fluency with high confidence in the target answer, whereas GCG is preferable for confidence relative to ground truth.The comparison covers ground-truth, sampling, and optimisation frameworks across all methods.
B CONVERGENCE OF THE METROPOLIS-HASTINGS
Warm-started forward and backward Metropolis-Hastings chains converge to the same target-distribution region, indicating good mixing and little dependence on proposal direction. Both chains also show low, stable acceptance rates across sampling steps, while qualitative prompt recovery is compared across optimization and MCMC methods.
- Chain convergence: Warm-started forward and backward chains converge to the same region of the target distribution.This demonstrates that the Metropolis-Hastings sampler is well-mixed.
- Chain convergence: The proposal direction does not materially affect the outcome of warm-started sampling.The forward and backward strategies reach the same target-distribution region.
- Acceptance rates: Both warm-started chains exhibit low, stable mean Metropolis-Hastings acceptance rates over the sampling steps (t).Figure 6 (right) reports the mean acceptance rate across sampling steps.
- Qualitative prompt analysis: Figure 7 qualitatively compares prompts recovered by GCG, GCG-Reg, GD-PEZ, and the MCMC sampler for each target answer.The comparison includes the MCMC final sample and forward proposal under warm-start initialisation.
C QUALITATIVE ANALYSIS RESULTS
This section presents representative examples of prompts recovered by each method. The examples are not exhaustive, with additional results provided in Figures 7 and 8.
- The section presents representative examples of prompts recovered by each method.
- The displayed examples are not exhaustive.
- Figures 7 and 8 provide additional results.
D PLAUSIBILITY AND GRAMMAR SCORES PROMPTS
The section evaluates recovered prompts with separate plausibility and grammar judgments. Plausibility emphasizes semantic relevance to the target answer, while grammar scoring isolates linguistic quality across methods.
- Plausibility: Plausibility rankings assess how naturally four candidate questions elicit the target answer, weighting semantic relevance most heavily alongside naturalness and lexical overlap.The LMSYS judge is instructed to evaluate candidates as a careful human reviewer and account for non-English characters.
- Grammar: Grammar scores evaluate MCMC, GCGC, GCG-Reg, and GD-PEZ independently of semantics, using spelling, punctuation, word order, repetition, malformed phrases, and corrupted tokens.Each method receives a score from 0.0 for malformed English to 1.0 for perfect English.
- Qualitative analysis: Qualitative examples pair ground-truth questions with prompts recovered by GCG, GCG-Reg, GD-PEZ, and MCMC, revealing malformed token sequences alongside more interpretable question-like samples.The examples cover targets including the location of a Baylor–Vanderbilt game and the number of Old Testament history books.