•  


GitHub - madaan/self-refine: LLMs can generate feedback on their work, use it to improve the output, and repeat this process iteratively.
Skip to content

madaan/self-refine

Folders and files

Name Name
Last commit message
Last commit date

Latest commit

 

History

120 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Self-Refine: Iterative Refinement with Self-Feedback

With Self-Refine, LLMs can generate feedback on their work, use it to improve the output, and repeat this process.

image


Table of Contents


Updates

Stokes' Theorem Example
Visual Self-Refine Example 1

Unicorn Example
Visual Self-Refine Example 2

Setup

  • We use prompt-lib for querying LLMs. You can install prompt-lib by running the following commands:
git clone https://github.com/reasoning-machines/prompt-lib
pip install prompt-lib/

Depending on your default settings, you may want to use the following to set a PYTHONPATH:

export
 PYTHONPATH=
"
.:../:.:src:../:../../:.:prompt-lib
"

Getting Started with Acronym Generation

python -u src/acronym/run.py 
"
Using language models of code for few-shot commonsense
"
  • Since we sample with temperature 0.7, you'll get different results each time you run the above command.
0
 INIT
>
 Using language models of code for few
-
shot commonsense

0
 GEN
>
 CLoCK
0
 SCORES
>
 *
 Ease of pronunciation
:
 CLoCK is 
pronounced
 "
clah-k
"
.
 This is 
easy
 acronym to pronounce
.
 4
/
5
 
*
 Ease of spelling
:
 CLoCK is 
easy
 to spell
.
 5
/
5
 
*
 Relation to title
:
 CLoCK stands for 
"
Code Language Models of Commonsense Knowledge
"
 which is 
related
 to the title
.
 5
/
5
 
*
 Positive connotation
:
 CLoCK is 
a
 positive acronym
.
 It
 implies accuracy and efficiency
.
 5
/
5
 
*
 Well
-
known
:
 CLoCK is 
not
 a well
-
known acronym
.
 2
/
5


*
 Total score
:
 21
/
25


1
 GEN
>
 CMNSC
1
 SCORES
>
 *
 Ease of pronunciation
:
 CMNSC is 
pronounced
 "
see-min-es-see
"
.
 This is 
a
 difficult acronym to pronounce
.
 1
/
5
 
*
 Ease of spelling
:
 CMNSC is 
difficult
 to spell
.
 1
/
5
 
*
 Relation to title
:
 CMNSC stands for 
"
Commonsense
"
 which is 
related
 to the title
.
 4
/
5
 
*
 Positive connotation
:
 CMNSC is 
a
 neutral acronym
.
 3
/
5
 
*
 Well
-
known
:
 CMNSC is 
not
 a well
-
known acronym
.
 1
/
5


*
 Total score
:
 10
/
25


2
 GEN
>
 COMMIT
2
 SCORES
>
 *
 Ease of pronunciation
:
 COMMIT is 
pronounced
 "
com-mit
"
.
 This is 
an
 easy acronym to pronounce
.
 4
/
5

*
 Ease of spelling
:
 COMMIT is 
easy
 to spell
.
 5
/
5

*
 Relation to title
:
 COMMIT stands for 
"
Commonsense Model of Code for Intuitive Training
"
 which is 
related
 to the title
.
 5
/
5
 
*
 Positive connotation
:
 COMMIT is 
a
 positive acronym
.
 It
 implies commitment and dedication
.
 5
/
5

*
 Well
-
known
:
 COMMIT is 
not
 a well
-
known acronym
.
 2
/
5


*
 Total score
:
 21
/
25

Dialogue Response Generation

PYTHONPATH=
"
.
"
 python -u src/responsegen/run.py --output 
<
OUTPUT FILE
>
 --size 
<
DATA SIZE
>
  • Use size 0 for running on all test instances

Code Readability Improvement

  • Note: Please unzip 'data/tasks/codeclean/code_readability/codenet-python-train.jsonl.zip' before running the following commands!
  • Running:
PYTHONPATH=
"
.
"
 python -u src/readability/readability.py --output 
<
OUTPUT FILE
>
  • Evaluation:
PYTHONPATH=
"
.
"
 python -u src/readability/{count_comment
|
count_function
|
count_meaningful_var}.py --file 
<
INPUT FILE
>

Commongen

  • We use a hard version of commongen. The data is located in data/prompt/commongen . You can download the data by running the following commands:
python -u src/commongen/run.py cmd stair bubble team dryer puppy aliens cat 

GSM-8k

  • To run the GSM-8k task:
python -u src/gsm/run.py 
  • The outputs will be saved in data/tasks/gsm/gsm_outputs.jsonl

  • To evaluate the outputs:

python src/gsm/gsm_selfref_eval.py --path  data/tasks/gsm/gsm_outputs.jsonl
  • The evaluation script will also generate a report ( data/tasks/gsm/gsm_outputs.jsonl.reports.txt ) showing examples of wrong generations, feedback, and refined feedback generations.

Yelp

  • To run the Yelp task:
python -u src/sentiment_transfer_sr/run.py data/tasks/yelp/yelp-extreme.jso
nl 4 none
  • The outputs will be saved in data/tasks/yelp/

PIE

  • To run the PIE task:
python -u src/pie/run.py --slow_programs_file data/tasks/pie/codenet-python-test-1k.jsonl --max_attempts 4 --outfile data/tasks/pie/output --feedback_type rich

General setup

  • Each task has three different types of prompts:
  1. Init : used to initialize the task. This is how the initial output is generated.

  2. Feedback : used to get feedback from the model on the intermediate results.

  3. Iterate : used to get the next iteration from the model, based on the feedback.

  • Every task has a run.py that initializes the prompts and runs the task.

  • As an example, the prompts for commongen are as follows:

  1. Init prompt:
python src/commongen/task_init.py
  1. Feedback prompt:
 python src/commongen/feedback.py
  1. Iterate prompt:
python src/commongen/task_iterate.py

You can also see these prompts on our website .

Citation

@misc{madaan2023selfrefine,
      title
=
{Self
-
Refine: Iterative Refinement with Self
-
Feedback}, 
      author
=
{Aman Madaan 
and
 Niket Tandon 
and
 Prakhar Gupta 
and
 Skyler Hallinan 
and
 Luyu Gao 
and
 Sarah Wiegreffe 
and
 Uri Alon 
and
 Nouha Dziri 
and
 Shrimai Prabhumoye 
and
 Yiming Yang 
and
 Sean Welleck 
and
 Bodhisattwa Prasad Majumder 
and
 Shashank Gupta 
and
 Amir Yazdanbakhsh 
and
 Peter Clark},
      year
=
{
2023
},
      eprint
=
{
2303
.
17651
},
      archivePrefix
=
{arXiv},
      primaryClass
=
{
cs
.
CL
}
}
flowchart LR
    Generator -->|Initializes| Unrefined
    Critic_1 --> Critique_fb
    ... --> Critique_fb
    Critic_k --> Critique_fb
    Critique_fb --> Unrefined{Output to Refine}
    Unrefined --> Refiner
    Refiner --> |R: y_t, x, fb| Refined_Output{Refined Output}
    Refined_Output --> |Stopping Criteria Not Met| Unrefined
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본