arXiv(opens in a new tab)Computer ScienceMar 2023Cited by 98 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2303.17651

Self-Refine: Iterative Refinement with Self-Feedback

Aman Madaan, Niket Tandon, Prakhar Gupta, Skyler Hallinan, Luyu Gao, Sarah Wiegreffe, Uri Alon, Nouha Dziri, Shrimai Prabhumoye, Yiming Yang, S. Welleck, Bodhisattwa Prasad Majumder, Shashank Gupta, A. Yazdanbakhsh, Peter Clark

Abstract

Like humans, large language models (LLMs) do not always generate the best output on their first try. Motivated by how humans refine their written text, we introduce Self-Refine, an approach for improving initial outputs from LLMs through iterative feedback and refinement. The main idea is to generate an initial output using an LLM; then, the same LLM provides feedback for its output and uses it to refine itself, iteratively. Self-Refine does not require any supervised training data, additional training, or reinforcement learning, and instead uses a single LLM as the generator, refiner and the feedback provider. We evaluate Self-Refine across 7 diverse tasks, ranging from dialog response generation to mathematical reasoning, using state-of-the-art (GPT-3.5 and GPT-4) LLMs. Across all evaluated tasks, outputs generated with Self-Refine are preferred by humans and automatic metrics over those generated with the same LLM using conventional one-step generation, improving by ∼\sim20% absolute on average in task performance. Our work demonstrates that even state-of-the-art LLMs like GPT-4 can be further improved at test-time using our simple, standalone approach..

1 Introduction

Although large language models (LLMs) can generate coherent outputs, they often fall short in addressing intricate requirements. This mostly includes tasks with multifaceted objectives, such as dialogue response generation, or tasks with hard-to-define goals, such as enhancing program readability. In these scenarios, modern LLMs may produce an intelligible initial output, yet may benefit from further iterative refinement—i.e., iteratively mapping a candidate output to an improved one—to ensure that the desired quality is achieved. Iterative refinement typically involves training a refinement model that relies on domain-specific data (e.g., Reid and Neubig (2022); Schick et al. (2022a); Welleck et al. (2022)). Other approaches that rely on external supervision or reward models require large training sets or expensive human annotations (Madaan et al., 2021; Ouyang et al., 2022), which may not always be feasible to obtain. These limitations underscore the need for an effective refinement approach that can be applied to various tasks without requiring extensive supervision.

Iterative self-refinement is a fundamental characteristic of human problem-solving (Simon, 1962; Flower and Hayes, 1981; Amabile, 1983). Iterative self-refinement is a process that involves creating an initial draft and subsequently refining it based on self-provided feedback. For example, when drafting an email to request a document from a colleague, an individual may initially write a direct request such as “Send me the data ASAP”. Upon reflection, however, the writer recognizes the potential impoliteness of the phrasing and revises it to “Hi Ashley, could you please send me the data at your earliest convenience?". When writing code, a programmer may implement an initial “quick and dirty” implementation, and then, upon reflection, refactor their code to a solution that is more efficient and readable. In this paper, we demonstrate that LLMs can provide iterative self-refinement without additional training, leading to higher-quality outputs on a wide range of tasks.

We present Self-Refine: an iterative self-refinement algorithm that alternates between two generative steps–feedback and refine. These steps work in tandem to generate high-quality outputs. Given an initial output generated by a model M\mathcal{M}, we pass it back to the same model M\mathcal{M} to get feedback. Then, the feedback is passed back to the same model to refine the previously-generated draft. This process is repeated either for a specified number of iterations or until M\mathcal{M} determines that no further refinement is necessary. We use few-shot prompting (Brown et al., 2020) to guide M\mathcal{M} to both generate feedback and incorporate the feedback into an improved draft. Figure 1 illustrates the high-level idea, that Self-Refine uses the same underlying language model to generate feedback and refine its outputs.

Figure

Figure 1: Given an input (\raisebox{-1pt} {\footnotesize{0}\vphantom{a}}⃝), Self-Refine starts by generating an output and passing it back to the same model M\mathcal{M} to get feedback (\raisebox{-1pt} {\footnotesize{1}\vphantom{a}}⃝). The feedback is passed back to M\mathcal{M}, which refines the previously generated output (\raisebox{-1pt} {\footnotesize{2}\vphantom{a}}⃝). Steps (\raisebox{-1pt} {\footnotesize{1}\vphantom{a}}⃝) and (\raisebox{-1pt} {\footnotesize{2}\vphantom{a}}⃝) iterate until a stopping condition is met. Self-Refine is instantiated with a language model such as GPT-3.5 and does not involve human assistance.

We evaluate Self-Refine on 7 generation tasks that span diverse domains, including natural language and source-code generation. We show that Self-Refine outperforms direct generation from strong LLMs like GPT-3.5 (OpenAI, ; Ouyang et al., 2022, text-davinci-003 and gpt-3.5-turbo; ) and GPT-4 (OpenAI, 2023) by 5-40% absolute improvement. In code-generation tasks, Self-Refine improves the initial generation by up to absolute 13% when applied to strong code models such as Codex (Chen et al., 2021, code-davinci-002; ). We release all of our code, which is easily extensible to other LLMs. In essence, our results show that even when an LLM cannot generate an optimal output on its first try, the LLM can often provide useful feedback and improve its own output accordingly. In turn, Self-Refine provides an effective way to obtain better outputs from a single model without any additional training, via iterative (self-)feedback and refinement.

(a) Dialogue: xx, yt\mathbf{y_{t}}

⬇

User: I am interested in playing Table tennis.

Response: I’m sure it’s a great way to socialize, stay active

(b) feedback   fb~~\mathbf{fb}

⬇

Engaging: Provides no information about table tennis or how to play it.

User understanding: Lacks understanding of user’s needs and state of mind.

(c) refine   yt+1~~\mathbf{y_{t+1}}

⬇

Response (refined): That’s great to hear (…) ! It’s a fun sport requiring quick reflexes and good hand-eye coordination. Have you played before, or are you looking to learn?

(d) Code optimization: xx, yt\mathbf{y_{t}}

⬇

Generate sum of 1, ..., N

def sum(n):

res = 0

for i in range(n+1):

res += i

return res

(e) feedback   fb~~\mathbf{fb}

⬇

This code is slow as it uses brute force. A better approach is to use the formula … (n(n+1))/2.

(f) refine   yt+1~~\mathbf{y_{t+1}}

⬇

Code (refined)

def sum_faster(n):

return (n*(n+1))//2

Figure 2: Examples of Self-Refine: an initial output generated by the base LLM and then passed back to the same LLM to receive feedback to the same LLM to refine the output . The top row illustrates this for dialog generation where an initial dialogue response can be transformed into a more engaging one that also understands the user by applying feedback. The bottom row illustrates this for code optimization where the code is made more efficient by applying feedback.

References (16)

Cited by (98)