Cut words out of a clean prompt and its accuracy can rise: a pruned prompt of 10 words scores 86.7% on MultiArith, where the 18-word original scored 81.5%.
Learn why deleting words from a prompt can help a language model, and how an evolutionary search finds the deletions that work.
Press the four prompts in turn and watch which words stay. Then we build, piece by piece, everything underneath: how a model learns from examples in its prompt, why the right deletions are hard to find, and the copy, mutate and select loop that finds them.
You need a feel for what a prompt is (the text you send a language model) and a little Python for the code. We build the rest from zero.
Based on “Evolving Prompts In-Context: An Open-ended, Self-replicating Perspective” by Jianyu Wang, Zhiqiang Hu and Lidong Bing (DAMO Academy, Alibaba Group, Hupan Lab and MiroMind; ICML 2025), arXiv 2506.17930. It is a reading for the lecture Context Evolution in MIT MAS.S62 How to AI an AI for (Almost) Anything. Every idea is re-taught here in our own words and devices.
The scores are the paper’s Table 7 (Appendix B): zero-shot chain-of-thought trigger sentences on MultiArith with InstructGPT (text-davinci-002), accuracy in percent. The first prompt is the paper’s “(Empty)” row, with no trigger sentence. The paper reports these four prompts only, so the fade between stops is animation, not data.
Chapter 0
See why a prompt with words deleted can beat the clean one, and what the paper builds to find the right deletions
You write a careful prompt for a language model. You give it a clear instruction and a worked example. You read it twice and fix the grammar. Then a colleague deletes eight words at random from it and the model gets better at the task.
That sounds like a joke, but the hero at the top of this page is the paper’s own case. A well-known sentence, “Let’s work this out in a step by step way to be sure we have the right answer,” scored 81.5% on a school-maths test. The paper cut it to “Let’s work out step by step sure we right answer.” That scrap of broken English scored 86.7%. Cut everything and the score fell to 17.7%. So the words matter, but not all of them, and not in the way a human reader would guess.
A prompt is the text you hand a language model before it answers. People have two main ways to improve one. The first is hand craft: you try wordings and keep the best. The second is automatic prompt optimization, where a program tries wordings for you and scores each one on examples with known answers.
The usual advice for both is the same. Write a clear instruction. Add a few well-chosen examples, which the paper calls demonstrations. The paper says this “conventional wisdom” is incomplete. Its authors, Jianyu Wang, Zhiqiang Hu and Lidong Bing, show that taking random demonstrations and pruning them into text that reads as nonsense “always matches or surpasses” the best automatic methods they compare with. They call the result “gibberish” on purpose.
Finding the right words to cut is the hard part. A prompt of 300 tokens has more ways to cut than anyone can try. The paper tests ideas that sound sensible, such as asking the model which words matter, and shows they fail. It then builds PromptQuine, a search that lets prompts copy themselves, mutate by losing words, and compete. The name borrows from a quine, a program that prints its own source code. Here the prompt is the thing that gets copied.
Table 1 of the paper uses Llama-3-8B-Instruct, an open model with 8 billion weights tuned to follow instructions. It tests six text-classification tasks, each as a one-example prompt. Averaged over the six, the original prompt scores 69.6%. The PromptQuine prompt scores 77.5%. On Subj, a task that asks whether a movie sentence is subjective or objective, the jump is from 66.7% to 86.5%. Try the paired bars below, then switch to four examples per prompt.
Each pair of bars is one task. Warm is PromptQuine’s pruned prompt, blue is the original prompt. Pick a task to read its numbers, and switch between one example and four examples per prompt.
The numbers are Table 1 of the paper: overall accuracy in percent with Meta-Llama-3-8B-Instruct, averaged over five seeds (the paper also gives a standard deviation for each, left out here). “Original” is the plain in-context prompt with 1 or 4 examples; “pruned” is PromptQuine run on that prompt.
The gain is not even. On SST-2, a movie-review sentiment task, the original already scores 95.9% and the pruned prompt reaches 96.2%, a tie in practice. On SNLI, which asks whether one sentence follows from another, four-example prompts rise from 60.0% to 78.6%. Pruning helps most where the original prompt is shaky.
The finding says something about how language models read. A model trained to follow clear human instructions still reacts strongly to text that no human would write. The authors read this as a sign that alignment, the training that teaches a model to behave, may be “superficial” in places. They also see an opening: if the best prompts are not human prose, then searching, and not hand craft, may be the better way to write them. That is the “open-ended” in the title, a search that is free to find things we would not think to try.
The paper has a clean arc. It states a hypothesis, shows that cheap shortcuts fail, tries simple search, finds where simple search breaks, and then fixes it with evolution. We follow that order.
Chapter 1
See how a frozen language model learns a task from a few examples pasted into its prompt, and why that prompt is so fragile
You run a news site and you want every headline sorted into World, Sports, Business or Tech. You have no labelled data set and no time to train a classifier. You do have a language model that someone else trained. So you paste one labelled headline above the new one and ask it to continue. It writes “Sports”. Nobody changed the model. The example in the prompt was enough.
That trick is in-context learning, or ICL. The model’s weights stay frozen. Everything it needs to learn the task sits in the text it reads right now, which is its context. Each labelled example is a demonstration. A prompt with K demonstrations is a K-shot prompt. A 1-shot prompt carries one pair, a 4-shot prompt carries four.
Here is a 1-shot prompt for the news task. The wording is ours and the layout is typical. The paper’s datasets and label words differ in detail, but the shape is the same.
Four parts matter. The input is the text to classify (“Late goal gives…”). The signal words are the fixed labels in the template, such as “Article:” and “Topic:”. The label word is the answer word for the example (“Sports”). The verbalizer is the map from each class to its label word: World, Sports, Business and Tech for this task. The paper lists the label words of its datasets in Table 5, for example “terrible” and “great” for SST-2.
The paper writes the process in one line, its Equation 1. The model sees K labelled pairs and then the test input. It then draws the test answer from its own next-word distribution.
The paper then maps ytest back to a class with the verbalizer. In practice a program does not wait for free text. It reads the probabilities of the label words directly, which the next device shows.
Follow one request. The prompt above is about 40 tokens. A token is a word or word piece the model counts. The tokenizer turns the text into a list of integer ids, shape [40]. The model reads the list and, at the last position, outputs one score per vocabulary entry. These raw scores are logits, shape [V], where V is the vocabulary size (about 128,000 for Llama 3). A softmax turns logits into probabilities by exponentiating each one and dividing by the total.
To classify, take only the |C| logits of the label words, shape [4] here, and compare them. The paper’s fitness function in Chapter 6 does exactly this. Drag the four logits below and watch the answer and the margin change.
The true topic of the headline is Sports. Each slider is the model’s raw score (logit) for one label word. Drag them and watch the share each word gets among the four.
Illustrative: the logits are made-up numbers, not read from a real model. The arithmetic is exact: softmax over the four label words only, and the gap is the correct word’s probability minus the largest other probability, as defined in the paper’s Appendix D.3.
Try a worked case. With logits 0.5, 1.4, 0.4 and −1.0, exponentiate: 1.65, 4.06, 1.49, 0.37. The total is 7.57. So Sports gets 4.06 / 7.57 = 53.6%. The runner-up, World, gets 21.8%. The model answers Sports, and the margin is 31.8 points. That margin is the paper’s gap, and it will be the core of the search score.
ICL works, but it is touchy. Prior work the paper cites shows that small changes in phrasing, in the order of the examples, or in which examples you pick can change the answer a lot. Nobody has a firm rule for what makes a good demonstration. The paper’s related-work section says there is “a lack of well-grounded principles to guide demonstration design.”
Researchers answered with prompt optimizers. RLPrompt trains a small policy with reinforcement learning to write discrete prompt tokens. EvoPrompt and Promptbreeder use an evolutionary loop where a large language model rewrites instructions. The paper says Promptbreeder leans on handcrafted mutation prompts and outside resources, such as new tokens. Earlier work also found odd, unreadable prompts that work, called secret language. One example is “StaffAreaFocusHardware Advisory” for news classification. Such prompts were seen as accidents, hard to find and hard to scale. This paper turns them into something you can search for.
Chapter 2
State the paper’s hypothesis, count how many pruned prompts exist, and see why you cannot simply follow a gradient to the best one
Take the 16-token prompt in the device below. Each token has a small switch. Flip a switch off and the token vanishes from the text the model reads. After you have flipped some, you hold a shorter prompt. Is it better or worse than the first? The only way to know is to run the model on examples and count right answers.
That is the whole problem of this paper. Before we solve it, we state it precisely, because every later chapter answers one of its parts.
Earlier work found that unreadable prompts can beat readable ones. But those prompts came from searches over the entire vocabulary, and nobody knew why they worked. The authors take a gentler route. Start with a natural-language prompt and only remove tokens from it. They call the guess behind this the Partial Context Hypothesis: some tokens in a natural prompt are redundant or even harmful, and a nearby prompt with them removed can score much higher.
In symbols, let x = (x1, …, xn) be the original prompt with n tokens and task score X. They look for a subsequence z = (z1, …, zm) with m ≤ n, which means z keeps some tokens of x in their original order and drops the rest. They hope its score Z is much larger than X. A pilot study in Appendix B with a simple hill climber supports the hypothesis, including the “let’s work out step by step” example from the hero.
Write the choice as a binary mask m, one bit per token: 1 keeps the token, 0 cuts it. The pruned prompt is z = the tokens of x where m is 1. The paper uses genetic-algorithm words for the same two things. The mask is the genotype, the code that gets copied and mutated. The resulting prompt text is the phenotype, the thing the model actually reads and gets scored on.
The paper keeps the order of the tokens fixed. Reordering tokens would make the space far larger, so it searches only fixed-order prompt subsequences. Try the switches below. Each press is one bit of the mask, and the size line shows how fast the count of masks grows with prompt length.
Press a token to cut it or bring it back. Then drag the length slider to see how many pruned prompts a longer prompt has. The dashed line is the paper’s search budget of 10,000 prompts.
The 16-token prompt is our own toy example. The 10,000 figure is the paper’s default number of iterations (Table 9). The counts are exact: 2 to the power n masks for n tokens, shown as a power of ten.
Do the arithmetic once by hand. For n = 16, there are 216 = 65,536 masks. That is small enough to try all of them. For n = 100 there are about 1.3 × 1030. A real one-shot prompt has hundreds of tokens, so the space has more than 1090 members at 300 tokens. A budget of 10,000 evaluations visits a vanishing share. The search must be clever.
The second part is the search objective, written f(z; x, D). It scores a prompt on a data set D, for example by classification accuracy on a held-out set. A neural network normally trains by gradient ascent: compute how a small change in each knob changes the score, and nudge every knob that way. That needs a smooth score. Here the knobs are discrete (a token is in or out) and the score is a count of right answers. A gradient does not exist, so the paper calls the objective non-differentiable and uses black-box search. The model is a black box too: the search sends text in and reads scores out, with no access to model internals.
The third part is solution selection. When the search ends, you must pick one prompt. The paper judges candidates on a validation set, a held-out slice of data, and reports final numbers on a separate test set. The sets never overlap. If they did, the winning prompt could simply have memorised the test questions, and the reported gain would be fake. For most classification tasks the paper uses 200 validation samples, as in its Appendix B.
One more reframing matters. Researchers usually study prompt compression to make prompts shorter and inference cheaper. The paper turns it around: pruning is a guided prompt search whose goal is a better score. Shorter prompts are a side benefit, not the aim. It uses the word “pruning” to avoid confusion.
Chapter 3
See why scoring each token on its own, or asking a compression tool, cannot tell you which tokens to cut
You have a 300-token prompt and 2300 masks. Searching is expensive, so you look for a cheaper way. Surely there is a way to ask the model which tokens matter, rank them, and cut the bottom of the list. One forward pass and one backward pass, and you are done. The paper tries exactly this and reports that it does not work.
Attribution methods give each input token an importance score. The paper tests two kinds (its Appendix C). The first is gradient-based: compute how much the model’s output changes when you nudge each token’s embedding, and call a large change important (instance attribution, Li et al. 2016). The second reads attention: how much the model attends to a token, in the first layer or averaged over all layers. Each gives a ranking from a single pass.
Prompt compression tools shorten a prompt to save cost. LLMLingua uses a small language model to measure each token’s self-information, which is how surprising it is, and drops the predictable ones. LLMLingua-2 trains a classifier on prompts that GPT-4 summarised, to keep the tokens a human summary would keep. Both aim at saving tokens while keeping meaning.
Then there is human intuition: read the prompt and decide which words are filler. The introduction says none of these “can reliably produce accurate token importance scores to guide the pruning, let alone human intuition according to word semantics.”
Start with compression, in Table 1. The plain 1-shot prompt averages 69.6% over six tasks. LLMLingua averages 68.1% after removing 30.0% of the tokens, a small loss. LLMLingua-2 removes 71.2% of the tokens and drops to 55.7%, with Subj at 60.2 and AG’s News at 58.1. Compare the paper’s own simple hill climber, which removes 60.2% of the tokens and rises to 74.8%. Compression tools measure how much text can go without hurting. The paper asks which text should go in order to help.
For attribution, Figure 5 plots accuracy as the percentage of pruned tokens grows. If a score ranked tokens well, accuracy would first rise as useless tokens leave, then fall once useful ones go. Instead every method “exhibit[s] nonlinear fluctuations.” Table 8 confirms that the best accuracy any of them reaches still lags the hill climber. They also share a practical flaw: they do not produce one final prompt. You must try many pruning percentages and pick one on the validation set.
The reason is that tokens interact. A single-token score measures what happens when you remove one token from the full prompt. It cannot see what happens when two tokens leave together. Here is a small illustrative case with two tokens, A and B, and four prompts.
| Prompt | Score (illustrative) | Change from full |
|---|---|---|
| Keep A and B | 0.60 | baseline |
| Cut A only | 0.58 | −0.02 |
| Cut B only | 0.57 | −0.03 |
| Cut A and B | 0.66 | +0.06 |
Single-removal scores say A matters by 0.02 and B matters by 0.03, so both look worth keeping. A ranking would never cut them. Yet cutting both raises the score by 0.06. Two tokens that only help when they go together form a valley: a step into it looks bad, the step out of it looks great. Real prompts plausibly hold many such pairs, because tokens share jobs. This is also the idea behind the paper’s term deceptive objective, which Chapter 4 returns to.
The device below builds this on a 60-token toy prompt. It has 10 valley pairs like A and B, 34 tokens with small effects and 6 format tokens the task needs. It ranks every free token by its single-removal score, then cuts the k lowest ranked together. You set k.
The curve is the toy score after cutting the k tokens with the smallest single-removal harm. The dashed line is where a hill climber ends on the same toy prompt. Drag k and look for a clean rise then fall.
Illustrative: this is our own toy landscape, not the paper’s data, and it is shared with Chapters 4 and 5. Its score is a made-up accuracy-like number between 0 and 1. The shape of the paper’s own result is in Figure 5 and Table 8.
Run it. At k = 0 the toy prompt scores 0.45. Cutting a few tokens helps a little, because the low-harm tokens are mostly the noise tokens. Then the ranking starts to cut one half of a valley pair without the other, and the score falls. It does not rise and fall once. It wanders, just like the curves in the paper’s Figure 5.
The lesson is the paper’s own: “we stick with our TAPruning, the hill-climbing approach.” Search that tries real subsets, and scores each with the model, sees interactions that one-pass scores miss. The price is many model calls. Chapter 4 begins with the cheapest version.
Chapter 4
Run the simplest search, delete one token at a time and keep what helps, and watch it end in a different place every time the order changes
Imagine editing an essay by deleting one word at a time. After each deletion you read the essay again. If it reads better, you keep the cut. If not, you put the word back and move on. You will not write a masterpiece this way, but you will improve a rough draft fast. This is hill climbing: always take a step that goes up. The paper’s first search, Section 3.1, does exactly this to a prompt, and it is a strong baseline.
The paper calls it TAPruning, for Threshold Accepting pruning. It builds on first-choice hill climbing, which accepts the first change that improves the score instead of hunting for the best one. Algorithm 1 in the appendix runs like this.
Step 4 is the “threshold” in Threshold Accepting (Dueck and Scheuer, 1990). The paper’s example is δ = 0.96, so a candidate within 4% of the best score is allowed in. The reason is the valley from Chapter 3: a step downhill may be the only road to a higher peak.
Take a five-token prompt with score 0.60 and δ = 0.96. The floor for step 4 is 0.60 × 0.96 = 0.576. These scores are illustrative.
Cut token 1: score 0.62. That beats 0.60, so accept. fbest = 0.62 and the floor moves to 0.595. Cut token 2 from the new T: score 0.59. That is below 0.595, so reject. Cut token 3: score 0.60. It is below fbest but above the 0.595 floor, so accept it into T without moving fbest. Cut token 4: score 0.64, accept; fbest = 0.64. Cut token 5: score 0.55, reject. The pass made 5 evaluations and kept three cuts. A second pass starts from the shorter prompt.
Every candidate costs one pass of the model over the search data. The paper uses small search sets, 200 held-out samples for TAPruning, so a pass is cheap. The algorithm also needs no gradients, only scores.
A natural upgrade is steepest-ascent hill climbing. Score every one-token removal, and take only the best one. The paper calls this SAHCPruning (Algorithm 2). It makes a better move each time, but it must score all L candidates before it moves once. The cost shows in Table 11, run on one A100 GPU. On Subj, SAHCPruning takes 13.2 minutes against 4.5 for TAPruning. On AG’s News it takes 25.7 hours against 12 minutes. The extra work does not pay. In Table 1, SAHCPruning averages 75.3% and TAPruning 74.8%, while on Yelp-5 SAHC is worse (58.5 against 60.2).
Hill climbing is guaranteed to reach the global best only when the landscape has one peak. The paper’s Figure 1 (left) tests this. It runs the same pure hill climber with random token orders, on Llama-3-8B-Instruct and subjectivity classification. The runs end at different prompts with clearly different scores. So the landscape has many peaks, and the one you reach depends on the path. The authors call the landscape multimodal. Because the validation score is based on few samples, they also call it deceptive: following it greedily can lead away from the best region.
Run it on the toy prompt below. It has the same valley pairs as Chapter 3. Pick a threshold, press New random order several times, and compare where each run ends.
The top strip is the final mask: warm cells stay, purple cells are cut. The line is the best score as evaluations are spent. Choose a threshold, then try several orders.
Illustrative: our own toy landscape (60 tokens, 10 valley pairs, 6 format tokens), shared with Chapters 3 and 5. Scores are made-up accuracy-like numbers. The loop is the paper’s Algorithm 1; the paper’s own evidence is Figure 1 (left) and Table 11.
With the strict threshold the climber rarely escapes the starting basin: a one-token cut into a valley always looks worse, so it is refused. With 0.96 it can step into a valley and out again, but only if it later reaches the partner token. Which tokens it tries first decides which pairs it completes. That is the paper’s point, and it is why a single path is a poor bet. We need a method that explores many paths at once.
Chapter 5
Build the PromptQuine loop, where a population of pruned prompts copies itself, loses a few tokens each time, and the fitter ones survive
A hill climber is one hiker. If the hiker walks into a small valley, the trip ends. Now send thirty hikers, let each one report its height, and then ask the highest ones to send out scouts in new directions. Some scouts end up in valleys, but the rest of the group does not care. That is the idea of evolutionary search: keep a population of candidates, copy the good ones with small random changes, and let the results compete.
The paper’s method, PromptQuine (Genetic PromptQuine), uses a genetic algorithm (GA, Holland 1992), a standard evolutionary method. It fits the problem well, since a mask is already a string of bits, which is what a GA mutates.
Each individual is one mask over the original prompt. At the start all 30 individuals are copies of the unpruned prompt. The paper says it tried random starting prunings and saw “no significant advantage.”
Mutation makes an offspring. Copy a parent’s mask, then flip some of its 1 bits to 0. The number of flips j is chosen uniformly from {1, 2, 3, 4}. Only 1-to-0 flips exist, so mutation can only prune. The paper leaves out crossover (mixing two parents), saying it gave little benefit and complicates the search.
Fitness is the score of the prompt the mask produces, as Chapter 6 defines. Selection picks parents. The paper uses tournament selection: sample k individuals at random, take the fittest as the parent. Its selection ratio is 0.2, so with 30 individuals k = 6. A small tournament gives the weaker members some chance to breed too, which the paper says “helps mitigate local optima.”
The paper calls its survival rule regularized evolution, after Real et al. In each generation, 50 offspring are made and scored. Then the best 30 of the offspring become the next population. The parents do not take part. So a lucky parent cannot sit forever and block progress, and slightly worse offspring survive if the generation has few good ones. These are the “suboptimal stepping stones” the paper argues are needed to cross valleys. The authors say this simple rule beat several diversity-keeping mechanisms (Appendix D.7) and fixes the “premature convergence” problem where the whole population turns into near copies of one prompt.
Use a population of 4 and 6 offspring, with fitness numbers that are illustrative. The population holds masks with fitness 0.50, 0.50, 0.50 and 0.50 at the start. Draw 6 parents, each from a tournament of 2 (all equal, so the pick is random). Mutate: the six children have fitness 0.47, 0.52, 0.55, 0.45, 0.51 and 0.49. Sort them: 0.55, 0.52, 0.51, 0.49, 0.47, 0.45. The next population is the top four: 0.55, 0.52, 0.51 and 0.49. The old parents are gone, although each of them (0.50) was fitter than the 0.49 child. That child lives on as a stepping stone. The best score so far is 0.55 and is saved in a history list H.
This saved history matters. The loop is not a clean climb. The best prompt found may sit several generations back, so the paper keeps every scored individual and picks the final prompt from that list in a re-ranking step (Chapter 6).
Table 9 gives the defaults for 1-shot prompts: population 30, offspring 50, mutation [1,2,3,4], tournament ratio 0.2, at most 10,000 iterations (prompts explored), and a stopping rule when the population’s mean prompt length reaches 15 tokens. For longer prompts the authors suggest more iterations and larger populations. They offer two flavours. The generational GA (GGA, Algorithm 4) works in batches, so it can be run in parallel with a fast inference server (they use vLLM). The steady-state GA (SSGA, Algorithm 5) updates the population more often and is “more exploratory but sacrifices some runtime efficiency.” SSGA is used for the main 1-shot results, GGA for more shots. Table 11 shows the trade-off on Subj: GGA 4 minutes, SSGA 18 minutes.
Now race it against the two other options on the same toy prompt as Chapters 3 and 4. Random search makes masks by cutting each token with some random probability, with no memory of past results.
Each step spends 50 evaluations on each method. Pink is the evolutionary loop, blue is random search. Press Run 1 generation a few times, then Run 20.
Illustrative: our own toy landscape, shared with Chapters 3 and 4, with the paper’s defaults for the loop (population 30, offspring 50, mutation of 1 to 4 bits, tournament of 6). Scores are made-up. The paper’s own comparison of evolutionary and random search is Figure 1, middle and right.
Expect the pink line to start slowly and then pull away. Random search samples blindly, so each new sample is as likely to be bad as the last. The evolutionary loop builds on earlier survivors, so its samples sit near good masks. The paper measures the same effect in Figure 1 (right): the success rate of random search relative to evolution “approaches zero as task difficulty increases,” for example with longer contexts where good prompts are rare.
Chapter 6
Turn a model’s label probabilities into a fitness number that tells close calls apart, then guard against a fitness that can be gamed
The evolutionary loop of Chapter 5 asks one question tens of thousands of times: how good is this prompt? Each answer costs model calls, so the answer must be cheap. It must also be fine-grained. Suppose you test a prompt on 8 examples and count right answers. The score can only be 0, 1, 2, up to 8. Two prompts that both get 6 look identical, though one is nearly wrong on every example and the other is confident. The search needs a signal that sees the difference.
For classification, the paper’s Appendix D.3 takes the reward from RLPrompt (Deng et al., 2022). It starts from the gap. For an input x with true class c, let Pz(c) be the probability the model gives to the label word of c under prompt z. The gap is that probability minus the largest probability among the other classes.
Work one example. Four classes, probabilities among the label words 0.55, 0.25, 0.15 and 0.05, with the true class the first. The gap is 0.55 − 0.25 = 0.30. The answer is right, so R = 200 × 0.30 = 60. Now swap so the true class has 0.25 and the first has 0.55. The gap is 0.25 − 0.55 = −0.30 and R = 180 × (−0.30) = −54. A near-tie, 0.40 against 0.38, has gap +0.02 and R = 4. The reward is continuous, so it rewards confidence and punishes confident mistakes.
Set the probability of the correct label word and of the best wrong one. The curve is the reward as a function of the gap, and the dot is where you are.
The formula and the constants (λ1 = 180, λ2 = 200) are the paper’s, Appendix D.3, Equation 3. The probabilities are yours. The two sliders need not sum to 1, since other label words may hold the rest.
Compare two prompts on the same 8 examples (our illustrative numbers). Prompt A has gaps +0.60, +0.55, +0.50, +0.45, +0.40, +0.35 on its six right answers and −0.30, −0.25 on its two wrong ones. Prompt B has gaps +0.05, +0.04, +0.03, +0.06, +0.02, +0.05 and −0.02, −0.03. Both have 75% accuracy. For A the right answers add 200 × 2.85 = 570 and the wrong ones 180 × (−0.55) = −99, so the mean reward is 471 / 8 = 58.9. For B they add 200 × 0.25 = 50 and 180 × (−0.05) = −9, so the mean is 41 / 8 = 5.1. Accuracy cannot tell A from B. Fitness can, and B is a coin flip away from collapse.
The paper uses only 8 balanced samples per fitness check, which it finds “generally sufficient.” With so few, an accuracy score would be almost flat. A gap-based score keeps the loop moving.
Eight samples are a thin slice. A prompt can win on those 8 by luck, or by exploiting a quirk. This is the old trap where an agent chases a proxy instead of the goal, and the paper cites work on goal misgeneralization. So the authors add a second stage, which they call calibration-then-selection, or re-ranking. Stage one keeps the top k% of all prompts explored, ranked by fitness, as the elite. Stage two scores each elite prompt on the whole held-out validation set (200 samples), and the best one wins. They note that choosing k is hard: a larger k explores more, a smaller k exploits more.
This also explains the two-data-sets rule of Chapter 2. Fitness uses a few examples from the search data. Re-ranking uses the full validation data. The test set is touched once, at the end.
Generation tasks lack a clean right answer, so the proxy changes. For Yelp sentiment transfer the fitness is the Joint Score from Krishna et al. (2020) (the paper’s Equation 2), computed from unpaired inputs, with 100 inputs for fitness and 200 for re-ranking. Because the metric is imperfect, searches need more samples, and the paper adds early stopping to save compute. For jailbreaking, fitness is an attack success rate measured by exact string match (ASR-EM) or by a judge model, Llama-Guard-3 (ASR-LLM), on 50 validation prompts. As a cheaper proxy they also try a steering vector, a direction in the model’s activations, and compare how far a prompt moves the model along it. That variant scores lower, and the authors call it an initial exploration.
Chapter 7
Read the paper’s main tables row by row, see where PromptQuine wins, where it only ties, and what the search costs in time
A results table is easy to skim and easy to misread. Before you trust a bar chart, you need to know what each row is, what the model was, and how many runs sit behind each number. This chapter reads the four tables that carry the paper’s claims.
Table 1 covers six classification data sets: SST-2 and Subj (movie sentences), AG’s News (news topics), Yelp-5 (five-star reviews), SNLI (does sentence B follow from sentence A) and Yahoo (question topics). Every method uses the same backbone, Meta-Llama-3-8B-Instruct, for fairness. Each cell is an accuracy with a standard deviation in brackets, over five seeds with five different ICL prompts. The last columns give the average and the ratio, the compression ratio against the original 1-shot prompt (bigger means more tokens removed).
The rows fall in groups. First the 1-shot ICL prompt, 69.6% on average. Then two compressors, LLMLingua (68.1) and LLMLingua-2 (55.7). Then ICL with 4 shots (72.0) and three optimizers. RLPrompt averages 67.5, EvoPrompt 73.6 and Promptbreeder 75.8. For the few-shot versions of EvoPrompt and Promptbreeder, the authors append their optimized instruction to the 1-shot prompt. Finally the paper’s methods on the 1-shot prompt: TAPruning 74.8, SAHCPruning 75.3 and PromptQuine 77.5, and on the 4-shot prompt TAPruning 77.3 and PromptQuine 81.3.
Read the bold and underlined best results with care. PromptQuine’s 1-shot average is the best among the 1-shot-based methods, ahead of Promptbreeder by 1.7 points. But it is not best everywhere. On SST-2 it is 96.2 against Promptbreeder at 96.0, a gap smaller than either spread. On Yelp-5 the 4-shot ICL prompt (61.9) and TAPruning (60.2) both beat PromptQuine’s 59.7. The wins are large where the original prompt was weak: Subj (66.7 to 86.5) and SNLI (61.9 to 69.2).
Table 2 is Yelp sentiment transfer: rewrite a negative review as a positive one, or the reverse, and keep the meaning. The score is the Joint Score averaged over both directions. With GPT-2 and greedy decoding, ICL scores 4.6, RLPrompt 10.4, Promptbreeder 10.2, TAPruning 30.2 and PromptQuine 33.3. With Llama-3-8B-Instruct the numbers are 54.4, 4.1, 59.1, 59.6 and 61.0. RLPrompt falls below plain ICL on Llama. The paper also reports Best-of-32 sampling, where PromptQuine again leads (57.9 for GPT-2 and 72.1 for Llama), and notes the results are “largely insensitive to the decoding methods we employed.”
The cost story lives in Table 11, timed on one A100 GPU. PromptQuine with the generational GA takes 4 minutes on Subj and 35 minutes on AG’s News. The steady-state version takes 18 and 51 minutes. TAPruning takes 4.5 and 12 minutes. The token-level searches RLPrompt and PIN take hours: RLPrompt about 12 hours on Subj and 33 on AG’s News. Promptbreeder needs about 30 minutes, held up by calls to an outside model (GPT-4o as the mutator). The paper claims it is “the first token-level search” that can optimize classification prompts “in just minutes.” Choose a table below and compare.
Pick a view. Warm bars are PromptQuine, light warm bars are the paper’s TAPruning and SAHCPruning, blue bars are other methods. Then read the sentence below the chart.
All numbers are copied from the paper: Table 1 (accuracy %, Llama-3-8B-Instruct, mean of five seeds), Table 2 (Joint Score, greedy decoding) and Table 11 (wall time on one A100 GPU, Subj). In the time view RLPrompt is 12 hours and PIN is 3 hours, shown in minutes. Methods with no number in a table are left out.
Three habits help with any table like this. Look at the spread, not only the mean: a one-point lead inside a standard deviation of two is a tie. Look at who paid what: PromptQuine uses only tokens already in the prompt, while Promptbreeder calls an outside model to write mutations. And look at the baseline: a gain of 20 points on a weak original, such as Subj at 66.7, says more about the original than about the method.
Figure 8 varies the number of examples. As in ordinary ICL, scores rise with more shots and may level off, but a “clear performance gap exists between raw (unpruned) ICL and our pruned ICL,” so pruning gives something that more shots do not. The 4-shot row of Table 1 says the same: 72.0 for plain ICL against 81.3 for PromptQuine. In a quick study (examples in Tables 18 to 23) the authors append orthogonal task instructions or even random sentences to prompts. Some beat the human-written, task-specific instruction. The paper adds: “perhaps, prompt engineering is still far from dead.”
The appendix also reports multiple-choice question answering (Table 16) and few-shot chain-of-thought maths (Table 17). We do not reproduce those numbers here; see the paper.
Chapter 8
Look inside the pruned prompts, test how fragile they are to a new template, and weigh the safety finding the authors themselves flag
A search that finds gibberish that works invites two questions. What did the search keep? And will the gain survive when you change something small? The paper answers both honestly, and the second answer is less flattering than the headline.
Section 5.2 looks at the label words in the demonstrations, the answer words such as “great” or “Sports.” In ordinary ICL, earlier work (Min et al., 2022) found that the set of label words helps even when the pairing between inputs and labels is scrambled. Figure 3 counts how often the pruned prompts still contain the label words, with a high rate “surprisingly.” The authors checked that the demonstration inputs themselves did not contain those words. So the search tends to keep them.
Figure 4 tests this by intervention, on Llama-3-8B-Instruct. Removing the label words from the original prompts costs accuracy, and removing them from the pruned prompts costs a little too, “a slight performance drop on average.” Removing the whole output side, the signal words such as “Sentiment:” and the label words together, “largely degrades performance.” So the input-then-label format matters. Pruning keeps the skeleton and trims around it. There are exceptions: on SNLI, removing the whole output improved the pruned prompt, which “underscores the nuanced sensitivity of prompts.”
One surprise sits in Appendix Table 25. With random label words (a verbalizer that maps classes to meaningless words) the unpruned models score near chance. Pruning still lifts some prompts, especially on the 70B model, to nearly the level of prompts with sensible labels. The authors call this “indeed surprising” and leave the mechanism open.
Section 5.1 reports a clear limitation. Take a task and three ICL templates that differ only in signal words, separators, spacing and small wording changes, the kind of variation you see in normal practice. Run PromptQuine on each, with three seeds, and compare test scores. Table 4 lists the spread from the lowest to the highest template.
Each bar spans the worst to the best template for one task, on a shared axis from 45 to 85. Pick a task to read its numbers.
The numbers are the paper’s Table 4: scores of PromptQuine-pruned prompts on the official test sets, across three random ICL templates with three 1-shot seeds each. The SNLI and PIQA scores are accuracy; the Yelp scores are style-transfer Joint Scores. The last column of the table (standard deviation) is shown in the read-out.
On SNLI the spread is 14.3 points, from 60.8 to 75.1, with a standard deviation of 7.2. On PIQA, a physical-commonsense multiple-choice task, it is 2.6 points (79.5 to 82.1). On Yelp positive transfer it is 2.5 (49.9 to 52.4) and on negative transfer 1.0 (69.8 to 70.8). The authors say this “emphasizes that PromptQuine, or fixed-order ICL pruning in general, exhibit instability when exposed to template differences.” A gain on one template is not a promise on the next.
They give a reason. The search only deletes. New tokens that might help are never tried, and fitness-based selection would throw out useful additions too early. More aggressive mutations such as replacing tokens, or searching the whole vocabulary like RLPrompt, are “riskier.” They suggest novelty search (Lehman and Stanley, 2011), which rewards new behaviour and not only high fitness, as a way forward.
The paper also uses the same search to attack aligned models. Table 3 pairs a few-shot priming setup with AdvBench, and measures attack success rate (ASR): the share of harmful requests the model answers instead of refusing. ASR-EM checks for exact refusal strings. ASR-LLM uses Llama-Guard-3 as judge. We report only the aggregate numbers, as the paper does.
| Model and prompt | ASR-EM (%) | ASR-LLM (%) |
|---|---|---|
| Vicuna-7b-v1.5, 2-shot ICL | 50.4 | 54.7 |
| Vicuna-7b-v1.5, PromptQuine (ASR-LLM fitness) | 99.4 | 97.5 |
| Mistral-7B-Instruct-v0.3, 2-shot ICL | 48.0 | 47.2 |
| Mistral-7B-Instruct-v0.3, PromptQuine (ASR-LLM fitness) | 99.8 | 98.1 |
The paper says this “nearly doubl[es]” the usual ICL result. Its impact statement draws the lesson: current alignment, trained mostly on natural language, leaves a gap that unnatural language can exploit, even in large models that have been red-teamed. The authors urge work on inner alignment and, for commercial models, output-level restrictions on top of red teaming. Read the result as a warning about how alignment generalises, not as a how-to.
Fixed order and deletion only. A fitness proxy on 8 samples that can be gamed. A search that was tuned to 1-shot prompts, with larger populations advised for more shots. And an open question the authors state plainly: why pruned, unnatural prompts work at all.
What should a practitioner take away? Treat a pruned prompt as a tuned artifact, like a trained model. It belongs to one model, one template and one task. Keep the search script, so you can run it again when any of those three change, and keep the validation set that picked it.
Chapter 9
Keep the numbers, the terms, a checklist and the core code on one page, then go back and prune the prompt again
The paper makes one claim and defends it in three steps. Claim: deleting tokens from a natural few-shot prompt can raise accuracy, and the result can match the best automatic prompt optimizers. Defence: shortcuts such as attribution and compression cannot find the right deletions (Chapter 3). Simple hill climbing finds some but gets trapped (Chapter 4). A population that copies, mutates and selects, with only offspring competing, gets out of the traps (Chapter 5). Scoring uses a gap-based reward and a re-ranking step (Chapter 6). The gain is real on classification and style transfer (Chapter 7), and fragile across templates (Chapter 8).
| What | Value | Where in the paper |
|---|---|---|
| MultiArith, step-by-step prompt, original to pruned | 81.5 → 85.3 → 86.7 (empty prompt 17.7) | Table 7, Appendix B |
| Six-task average, 1-shot ICL to PromptQuine | 69.6 → 77.5 | Table 1 |
| Six-task average, 4-shot ICL to PromptQuine | 72.0 → 81.3 | Table 1 |
| Subj, 1-shot, original to PromptQuine | 66.7 → 86.5 | Table 1 |
| Defaults: population, offspring, mutation bits | 30, 50, 1 to 4 | Table 9 |
| Defaults: tournament ratio, iterations, stop length | 0.2, 10,000, 15 tokens | Table 9 |
| Reward constants λ1, λ2 | 180, 200 | Appendix D.3 |
| Samples for fitness, for validation re-ranking | 8 balanced, 200 | Section 4.1 |
| AG’s News search time: SAHCPruning, TAPruning, PromptQuine (GGA) | 25.7 hr, 12 min, 35 min | Table 11 |
| Template spread on SNLI | 14.3 points (60.8 to 75.1) | Table 4 |
| Vicuna-7b attack success rate, ICL to PromptQuine (ASR-LLM) | 54.7 → 97.5 | Table 3 |
| Term | Plain meaning |
|---|---|
| ICL, K-shot | A model learns a task from K labelled examples written in the prompt. No weights change. |
| Verbalizer, label word | The map from classes to answer words, such as “terrible” and “great”. |
| Mask, genotype, phenotype | A bit per token (1 keep, 0 cut); the code that is mutated; the prompt text it produces. |
| Partial Context Hypothesis | Some tokens of a natural prompt hurt, so a nearby subsequence can score higher. |
| TAPruning, SAHCPruning | First-choice hill climbing with threshold accepting; steepest-ascent hill climbing. |
| Regularized evolution | Only new offspring compete for the next population; parents drop out. |
| Gap, fitness, elite, re-ranking | Correct label probability minus the best wrong one; mean reward on a few samples; the top shortlist; the final choice on a larger validation set. |
This is our own compact reading of the paper’s Algorithm 3, Algorithm 4 (the generational version) and Equation 3. It is a sketch, not the authors’ release. Their code is in the PromptQuine repository linked from the paper. The helpers model.label_probs and accuracy stand for calls to your model.
import random
def reward(probs, true, l1=180, l2=200):
"""Equation 3. probs: label-word probabilities, shape [C]. true: index of the right class."""
other = max(p for c, p in enumerate(probs) if c != true)
gap = probs[true] - other # in [-1, 1]
return (l2 if gap > 0 else l1) * gap # right answers are scaled up a little more
def render(tokens, mask):
return " ".join(t for t, keep in zip(tokens, mask) if keep)
def fitness(tokens, mask, model, samples):
"""Mean reward over a few balanced samples (the paper uses 8). model.label_probs(prompt, x) -> [C]."""
prompt = render(tokens, mask)
return sum(reward(model.label_probs(prompt, x), c) for x, c in samples) / len(samples)
def prompt_quine(tokens, model, search, val, P=30, C=50, k=6, iters=10_000,
min_len=15, elite_frac=0.1):
n = len(tokens)
full = [1] * n
pop = [(full, fitness(tokens, full, model, search))] * P # P copies of the original
history, explored = list(pop), 0
while explored < iters and sum(map(sum, (m for m, _ in pop))) / P >= min_len:
kids = []
for _ in range(C): # C offspring per generation
parent = max(random.sample(pop, k), key=lambda p: p[1]) # tournament of k
child = list(parent[0])
kept = [i for i, bit in enumerate(child) if bit]
for i in random.sample(kept, min(random.randint(1, 4), len(kept))):
child[i] = 0 # flip 1 -> 0, only pruning
kids.append((child, fitness(tokens, child, model, search)))
explored += 1
kids.sort(key=lambda p: p[1], reverse=True)
pop = kids[:P] # only offspring compete
history += kids
# calibration-then-selection: shortlist by fitness, then rank on the full validation set
elite = sorted(history, key=lambda p: p[1], reverse=True)[: max(1, int(elite_frac * len(history)))]
best = max(elite, key=lambda p: accuracy(render(tokens, p[0]), model, val))
return render(tokens, best[0])
PromptQuine sits between two families. One edits natural-language instructions with help from another language model (EvoPrompt, Promptbreeder, OPRO-style optimizers). The other searches token by token in an unreadable space (RLPrompt, PIN). It keeps the first family’s start from a clean prompt and the second family’s tolerance for gibberish, and uses neither an outside model nor a new vocabulary. In the course, this reading backs the lecture’s theme that context, not weights, can be the thing that evolves.
Credit: this lesson re-teaches “Evolving Prompts In-Context: An Open-ended, Self-replicating Perspective” by Jianyu Wang, Zhiqiang Hu and Lidong Bing (DAMO Academy, Alibaba; Hupan Lab; MiroMind), ICML 2025, arXiv 2506.17930. All paper numbers belong to the authors. The toy landscape, the worked examples marked illustrative and the Python sketch are ours.
Open the Present and Teach modes to explain the loop in your own words, or go back to the hero and prune the prompt again.