Search

Search papers and lessons

Self-Refine: Iterative Refinement with Self-Feedback

Aman Madaan, Niket Tandon, Prakhar Gupta et al. · 2023

Self-Refine has one language model write a draft, critique its own draft, and rewrite it in a loop, with no extra training, and it improves outputs on seven tasks.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

Self-Refine asks one Language Model to do three jobs in a loop: write a first draft, write feedback on that draft, and then rewrite the draft using the feedback. The loop repeats until a stopping rule fires. It needs no supervised data, no extra training and no reinforcement learning; every step is a prompt to the same frozen model. Across seven tasks and three GPT-family models, the paper reports that outputs improved by Self-Refine are preferred by humans and by automatic metrics over one-pass outputs, with an average absolute gain of about 20 points.

Builds on: In-Context Learning, Autoregressive Model, Chain-of-Thought Prompting · Leads to: no lesson in the graph yet

Why it mattered

Most people who use a language model for writing or code know the workflow: ask, read the answer, ask again with notes. Self-Refine turns that habit into a method the model runs by itself, and it measures the effect on seven tasks that range from sentiment reversal to math word problems. The paper's strongest claims are on writing-style tasks, where humans judge the output: GPT-4 with Self-Refine was preferred over plain GPT-4 in the dialogue task, and constrained generation showed some of the largest gains in the paper's table. The same idea, a model critiquing and revising its own work, recurs in later agent designs, and Self-Consistency Improves Chain of Thought Reasoning in Language Models shares its theme of spending more compute at test time on one model, though it samples and votes rather than critiquing.

The problem

Language models often give a reasonable first answer that falls short on requirements that are many-sided or hard to state, such as a dialogue reply that is relevant, engaging and safe at once, or code that is both fast and readable. Before this paper, the usual fixes needed training data or extra models:

  1. Trained refiners. A separate model learns to map a draft to a better one, but it needs domain-specific data for each new task.
  2. Reward models and human labels. Scores from a Reward Model or human annotators guide training, which needs large training sets or costly annotation.

The paper asks whether one model with a plain prompt can supply both the critique and the fix, so no new data is needed.

How it works

Take one tiny instance, using the sentiment-reversal illustration from the paper's Table 4. The task is to rewrite a review so that its sentiment flips.

  1. Input. The review is "The food was fantastic…", and the goal is to reverse its sentiment.
  2. Initial generation, y_0. The model writes a first draft from a few-shot prompt: "The food was disappointing…". The draft flips the sentiment but is mild.
  3. Feedback, fb_0. The same model reads the input and its draft and writes an actionable note: "Increase negative sentiment." The note is actionable because it names a change to make, and it is specific because it names the sentiment to push harder.
  4. Refine, y_1. The model reads the input, the draft and the feedback, then writes a new draft: "The food was utterly terrible…".
  5. Stopping check. The loop asks whether to continue. Here it stops after one round if the target is reached, and in any case stops after at most four rounds in the paper's sentiment setup. The prompt can also ask the model to output a stop score.
  6. Output. The last refinement is returned. For tasks with several quality aspects, the loop keeps the output with the highest total score across iterations.

The paper's ablation shows why step 3 matters: when the feedback is replaced by something generic such as "something is wrong", the sentiment preference rate falls from 85 percent to 73 percent.

flowchart LR
  X[Input x] --> G[Generate y0]
  G --> F[Feedback fb_t from the same model]
  F --> R[Refine to y_t+1 from the same model]
  R --> S{Stop?}
  S -->|no| F
  S -->|yes| O[Return last output]

The math

Definition: Self-Refine loop

Let M be a language model, x the input, p_gen, p_fb and p_refine the task-specific prompts, and the symbol || mean concatenation of prompt text. The loop is defined by three calls to the same M, and it stops when a stopping condition holds.

Step 2 in symbols: initial generation

y0=M(pgen ∥ x).y_{0} = \mathcal{M}\left( p_{\text{gen}} \,\|\, x \right).

The prompt p_gen contains a few input-output examples, so this is Few-Shot Learning prompting, also called in-context learning.

Step 3 in symbols: feedback

fbt=M(pfb ∥ x ∥ yt).fb_{t} = \mathcal{M}\left( p_{\text{fb}} \,\|\, x \,\|\, y_{t} \right).

The feedback prompt contains examples of input, output and feedback triples. The paper asks for feedback that is actionable and specific.

Step 4 in symbols: refinement with history

yt+1=M(prefine ∥ x ∥ y0 ∥ fb0 ∥ … ∥ yt ∥ fbt).y_{t+1} = \mathcal{M}\left( p_{\text{refine}} \,\|\, x \,\|\, y_{0} \,\|\, fb_{0} \,\|\, \dots \,\|\, y_{t} \,\|\, fb_{t} \right).

The paper keeps the full history of earlier drafts and feedback in the refine prompt, so the model can avoid repeating a past mistake.

Step 5 in symbols: the stopping rule

The stopping condition is stop(fb_t, t). It holds either at a fixed step t, or when the feedback contains a stop indicator such as a scalar score. The paper uses at most four iterations in its main setup, and the final output is y_t.

Results

The paper reports results on seven tasks with GPT-3.5 (text-davinci-003), ChatGPT (gpt-3.5-turbo) and GPT-4, with a maximum of four feedback-refine iterations. Values below are copied from Table 1 of the paper (base, then with Self-Refine).

  • Sentiment reversal. GPT-3.5: 8.8 to 30.4. ChatGPT: 11.4 to 43.2. GPT-4: 3.8 to 36.2.
  • Dialogue response. GPT-3.5: 36.4 to 63.6. ChatGPT: 40.1 to 59.9. GPT-4: 25.4 to 74.6.
  • Code optimisation (percent of programs optimised). GPT-3.5: 14.8 to 23.0. ChatGPT: 23.9 to 27.5. GPT-4: 27.3 to 36.0.
  • Code readability. GPT-3.5: 37.4 to 51.3. ChatGPT: 27.7 to 63.1. GPT-4: 27.4 to 56.2.
  • Math reasoning (GSM8K solve rate). GPT-3.5: 64.1 to 64.1. ChatGPT: 74.8 to 75.0. GPT-4: 92.9 to 93.1.
  • Acronym generation. GPT-3.5: 41.6 to 56.4. ChatGPT: 27.2 to 37.2. GPT-4: 30.4 to 56.0.
  • Constrained generation. GPT-3.5: 28.0 to 37.0. ChatGPT: 44.0 to 67.0. GPT-4: 15.0 to 45.0.

The paper's Table 13 adds confidence intervals. It reports that nearly all GPT-4 gains are statistically significant, while ChatGPT gains are significant on 4 of 7 tasks and GPT-3.5 gains on 3 of 7.

Other results from the paper:

  • Human A/B test (Table 6, 150 examples per task). Self-Refine outputs were preferred 75.00 percent of the time against 21.43 percent for direct output on sentiment transfer, and 44.59 against 12.16 percent on acronym generation (with 43.24 percent judged equal).
  • Feedback matters (Table 2). On code optimisation the score is 27.5 with specific feedback, 26.0 with generic feedback and 24.8 with no feedback. On sentiment reversal it is 43.2, 31.2 and 0.
  • Iterations help, with diminishing returns. On code optimisation the initial score of 22.0 rises to 28.8 after three iterations; on constrained generation it rises from 29.0 to 49.7 over three iterations.
  • Math with oracle feedback (Table 9). Using correctness information to decide when to refine raises GPT-3.5 from 64.06 to 68.9.
  • Weaker model. Vicuna-13B could not follow the feedback and refine prompts reliably. A mixed setup in which Vicuna-13B drafts and ChatGPT gives feedback and refinement raised math reasoning from 24.18 to 40.5.

Limits. The paper states its own limits: the base model must already follow few-shot prompts well; the experiments use closed models whose details are not public; and all data is in English. Its math results are also sobering: with self-feedback alone the gains are modest, because the model often says "everything looks good" on a wrong answer. The error analysis on code optimisation and math shows the feedback is the weak link: when Self-Refine failed to improve a draft, 61 percent of failures came from feedback suggesting an inappropriate fix and 33 percent from feedback pointing at the wrong place, against 6 percent from a refiner that misapplied good feedback. In a 1 vs k comparison with ChatGPT (k = 4), the outputs of Self-Refine were still preferred by humans over all four plain drafts, which the authors read as evidence that feedback-driven refinement, not just extra samples, drives the gain.

Reading guide

  • Abstract and Section 1 (Introduction). Needs In-Context Learning, since the method is few-shot prompting, and Instruction Tuning only as background for why the models follow prompts well.
  • Section 2 (Iterative Refinement with Self-Refine). Needs Language Model, Autoregressive Model and Transformer for the idea that the model generates text token by token from a prompt. Read with "How it works" and "The math" above.
  • Section 3 (Evaluation). Needs only the metric definitions in Section 3.2. Table 1 is the main result, summarised above.
  • Section 4 (Analysis). The feedback ablation (Table 2), iteration curves, and the 1 vs k sampling check. No new theory.
  • Section 5 (Related work). Compares to learned refiners and to reinforcement learning. Reading it needs Reinforcement Learning from Human Feedback (RLHF) as the reference point.
  • Appendices. Prompts (Appendix S) and per-task details. Appendix H.1 has the oracle-feedback experiment, and Appendix J the confidence intervals.

Check yourself

QuestionRecall: which three roles does the same language model play in one Self-Refine loop?Show answer

It generates the initial output, gives feedback on its own output, and refines the output using that feedback. No second model and no training step is used.

QuestionCompute: on the code optimisation task with GPT-4, the paper's Table 1 reports 27.3 for the base model and 36.0 with Self-Refine. What is the absolute gain in points, and what is the relative gain as a percentage of the base score?Show answer

The absolute gain is 36.0 minus 27.3, which is 8.7 points. The relative gain is 8.7 divided by 27.3, which is about 0.319, so about 31.9 percent. The paper's text reports the same 8.7 percent absolute gain.

QuestionWhy: why does the paper ablate generic feedback against specific feedback, rather than only comparing Self-Refine with and without refinement?Show answer

Generic feedback still gives the model a reason to change its draft, so comparing against no feedback alone would not show whether the content of the feedback matters. Comparing specific with generic feedback isolates the effect of actionable, specific feedback: on sentiment reversal the score fell from 43.2 to 31.2, and on code optimisation from 27.5 to 26.0.

QuestionApplied: a team wants to use Self-Refine to improve a customer-support reply that must be polite, correct and short. Their model is a small instruction-tuned model that fails to produce feedback in the required format. What does the paper suggest about this setting?Show answer

The paper's Vicuna-13B experiment suggests the loop depends on the base model following few-shot feedback and refine prompts. When the model could not produce feedback in the required format and often repeated its output, the loop did not produce useful refinements. The paper's tested alternative was a mixed setup in which a stronger model supplies feedback and refinement. The team should first check that their model follows the feedback format before expecting improvement.

Sources

Read the full paper

Aman Madaan, Niket Tandon, Prakhar Gupta et al., 2023. arXiv:2303.17651