Self-refine with Gemini 1.5

Agentic Patterns
Reflection
Prompt Engineering
Paper Reading
Published

July 6, 2024

Self-refine [1] is an approach that iteratively improves a model’s output based on its own feedback. It is suitable for stronger models. Given an initial output, it consists of 2 main steps: feedback and refine. The feedback contains concrete actions that can improve the output and identifies specific phrases in the output to be improved. Good feedback is crucial for the approach to work.


Source: Madaan et al. [1]

Self-refine uses three prompts: initial generation, feedback and refinement. The authors used few-shot prompting as in-context learning to guide the model:

This notebook experiments with self-refine for constrained generation using Gemini 1.5 models.

Import necessary libraries
import json
import nltk
import os
import re
import spacy
import sys
import time
import google.generativeai as genai

from google.ai.generativelanguage import Part, Content
from urllib.request import urlopen

sys.path.append('../src')
import utils

from dotenv import load_dotenv
load_dotenv();

Prepare 3 prompt templates

All three prompt templates are constructed using data from authors’ repo at madaan/self-refine.

1. init prompt template

Show the help functions
def download_examples(file_url):
    with urlopen(file_url) as f:
        lines = f.readlines()
    examples = list(map(lambda x: json.loads(x), lines))
    return examples
def construct_init_prompt_template():
    examples_url='https://raw.githubusercontent.com/madaan/self-refine/main/data/prompt/commongen/init.jsonl'
    examples = download_examples(examples_url)
    
    prompt_head = """
I want you to create a sentence that contains all the specified concepts.

Here are some examples:
    """.strip()
    prompt_end = """
Now create a sentence using the following concepts:

Concepts: {concepts}
The sentence is:
    """.strip()

    example_template = """
Concepts: {concepts}
The sentence is: {sentence}
    """.strip()
    
    examples_prompt = ''
    for example in examples:
        examples_prompt += '\n\n' + example_template.format(
            concepts=example['concepts'],
            sentence=example['target']
        )
    prompt_template = prompt_head + examples_prompt + '\n\n' + prompt_end
    return prompt_template
init_prompt_template = construct_init_prompt_template()
utils.display_html(init_prompt_template, 'Show init prompt template')
Show init prompt template
I want you to create a sentence that contains all the specified concepts.

Here are some examples:

Concepts: ['footage', 'motion', 'ruin', 'tilt', 'window']
The sentence is: time lapse footage with tilt up motion of the sun streaking through window of ruin

Concepts: ['cause', 'hate', 'hut', 'local', 'love']
The sentence is: new beach huts on the island have caused some controversy some locals love them others hate them

Concepts: ['call', 'contain', 'dress', 'gown', 'wallpaper']
The sentence is: the wallpaper probably containing a gown and a dinner dress called

Concepts: ['knock', 'leave', 'pew', 'rush', 'seat']
The sentence is: She leaves the confessional and rushes past a pew, knocking a Bible from the seat.

Concepts: ['help', 'moment', 'spend', 'uplift', 'world']
The sentence is: every moment that we spend in higher consciousness helps uplift the consciousness of the whole world

Concepts: ['label', 'pende', 'stamp', 'text', 'write']
The sentence is: abstract stamp or label with the text pending written inside

Concepts: ['create', 'ferry', 'silhouette', 'stream', 'terminal']
The sentence is: light streams through windows at the railroad and ferry terminal creating a beautiful silhouette

Concepts: ['chair', 'couch', 'hang', 'room', 'wall']
The sentence is: A room with a couch, chairs and art hanging on the wall.

Concepts: ['boat', 'building', 'harbour', 'moor', 'quay']
The sentence is: the harbour and port with fishing boats moored and old buildings on the quay

Concepts: ['admirer', 'arrive', 'commander', 'crowd', 'greet']
The sentence is: military commander is greeted by a crowd of admirers as he arrives

Now create a sentence using the following concepts:

Concepts: {concepts}
The sentence is:

2. feedback prompt template

def construct_feedback_prompt_template():
    examples_url='https://raw.githubusercontent.com/madaan/self-refine/main/data/prompt/commongen/feedback.jsonl'
    examples = download_examples(examples_url)
    
    prompt_head = """
I want you to provide feedback on a sentence that is constructed using given concepts. \
Follow the following instructions:
- First, find out what concepts from the concept list are missing from the constructed sentence
- Second, if the sentence doesn't make sense, provide a short explanation; otherwise, provide "None" as your answer.

Here are some examples:
    """.strip()

    prompt_end ="""
Now provide your feedback on the following concepts and the constructed sentence.
- First, find out what concepts from the concept list are missing from the constructed sentence
- Second, if the sentence doesn't make sense, provide a short explanation; otherwise, provide "None" as your answer.

Concepts: {concepts}
Constructed sentence: {sentence}
    """.strip()

    example_template = """
Concepts: {concepts}
Constructed sentence: {sentence}
Missing concepts: {missing_concepts}
Commonsense Feedback: {commonsense_feedback}
    """.strip()
    
    examples_prompt = ''
    for example in examples:
        examples_prompt += '\n\n' + example_template.format(
            concepts=example['concepts'],
            sentence=example['sentence'],
            missing_concepts=', '.join(example['concept_feedback']).replace('NONE', 'None'),
            commonsense_feedback=example['commonsense_feedback'].replace('NONE', 'None')
        )

    prompt_template = prompt_head + examples_prompt + '\n\n' + prompt_end
    return prompt_template
feedback_prompt_template = construct_feedback_prompt_template()
utils.display_html(feedback_prompt_template, 'Show feedback prompt template')
Show feedback prompt template
I want you to provide feedback on a sentence that is constructed using given concepts. Follow the following instructions:
- First, find out what concepts from the concept list are missing from the constructed sentence
- Second, if the sentence doesn't make sense, provide a short explanation; otherwise, provide "None" as your answer.

Here are some examples:

Concepts: ['beat', 'drum', 'pen', 'sit', 'use']
Constructed sentence: A man uses a drum to beat a pen.
Missing concepts: sit
Commonsense Feedback: None

Concepts: ['chair', 'clipper', 'cut', 'hair', 'sit']
Constructed sentence: A girl sitting on the couch with her hair up.
Missing concepts: clipper, cut, chair
Commonsense Feedback: None

Concepts: ['grass', 'hose', 'spray', 'stand', 'water']
Constructed sentence: A man standing next to a water dripping out of the grass.
Missing concepts: hose, spray
Commonsense Feedback: None

Concepts: ['front', 'gong', 'hit', 'mallet', 'stand']
Constructed sentence: The musician hit the gong with a mallet while standing in front of the audince.
Missing concepts: None
Commonsense Feedback: None

Concepts: ['ball', 'dunk', 'hoop', 'jump', 'run']
Constructed sentence: A young boy runs up to the hoop and jumps off of the ball.
Missing concepts: dunk
Commonsense Feedback: None

Concepts: ['card', 'chip', 'deal', 'dealer', 'table']
Constructed sentence: a dealer offers a card to a group of people at a table
Missing concepts: chip, deal
Commonsense Feedback: None

Concepts: ['clean', 'climb', 'gutter', 'house', 'ladder']
Constructed sentence: A man is climbing a ladder to clean a gutter in a house.
Missing concepts: None
Commonsense Feedback: None

Concepts: ['animal', 'catch', 'horse', 'lasso', 'ride']
Constructed sentence: A horse is being caught by a cowboy with a lasso.
Missing concepts: animal, ride
Commonsense Feedback: None

Concepts: ['beat', 'drum', 'pen', 'sit', 'use']
Constructed sentence: The drum sits on the pen and uses the beat.
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because a drum cannot sit on a pen and use a beat.

Concepts: ['chair', 'clipper', 'cut', 'hair', 'sit']
Constructed sentence: The clipper sits on the chair.
Missing concepts: cut, hair
Commonsense Feedback: The sentence does not make sense because a clipper cannot sit on a chair.

Concepts: ['grass', 'hose', 'spray', 'stand', 'water']
Constructed sentence: The water stands in the grass.
Missing concepts: hose, spray
Commonsense Feedback: The sentence does not make sense because water cannot stand in grass.

Concepts: ['front', 'gong', 'hit', 'mallet', 'stand']
Constructed sentence: On a sunny day, a mallet stands in the front of a gong and it hit the gong with a loud sound.
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because a mallet cannot stand in the front of a gong and cannot hit it.

Concepts: ['ball', 'dunk', 'hoop', 'jump', 'run']
Constructed sentence: The ball runs to the hoop and dunks.
Missing concepts: jump
Commonsense Feedback: The sentence does not make sense because a ball cannot run and dunk.

Concepts: ['card', 'chip', 'deal', 'dealer', 'table']
Constructed sentence: The chip deals a card to the dealer at the table.
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because a chip cannot deal a card to a dealer.

Concepts: ['clean', 'climb', 'gutter', 'house', 'ladder']
Constructed sentence: The ladder climbs to the house and cleans the gutter.
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because a ladder cannot climb to a house and cannot clean a gutter.

Concepts: ['animal', 'catch', 'horse', 'lasso', 'ride']
Constructed sentence: The horse catches the lasso and rides on it.
Missing concepts: animal
Commonsense Feedback: The sentence does not make sense because a horse cannot catch a lasso and ride on it.

Now provide your feedback on the following concepts and the constructed sentence.
- First, find out what concepts from the concept list are missing from the constructed sentence
- Second, if the sentence doesn't make sense, provide a short explanation; otherwise, provide "None" as your answer.

Concepts: {concepts}
Constructed sentence: {sentence}

3. refine prompt template

def construct_refine_prompt_templates():
    examples_url='https://raw.githubusercontent.com/madaan/self-refine/main/data/prompt/commongen/iterate.jsonl'
    examples = download_examples(examples_url)

    prompt_head = f"""
We are having a multi-turn conversation in order to create a sentence that contains all given concepts. \
I will provide you with my feedback on the sentence regarding missing concepts and whether the sentence makes sense. \
Your task is to improve the provided sentence based on my feedback.

Here are {len(examples)} examples of our past conversations:
    """.strip()

    generation_prompt = 'Improve the sentence using the above feedback.'

    example_prompt_head = """
Example {i}:
User:
Concepts: {concepts}
Sentence: {sentence}
Missing concepts: {missing_concepts}
Commonsense Feedback: {commonsense_feedback}

{generation_prompt}
    """.strip()

    example_prompt_assistant = """
Assistant:
Sentence: {sentence}
    """.strip()

    example_prompt_user = """
User:
Missing concepts: {missing_concepts}
Commonsense Feedback: {commonsense_feedback}

{generation_prompt}
    """.strip()

    prompt_end_0 = """
Now let's start a new conversation so that you can improve a constructed sentence based on my feedback.

Concepts: {concepts}
Sentence: {sentence}
Missing concepts: {missing_concepts}
Commonsense Feedback: {commonsense_feedback}
    """.strip()

    prompt_end_1 = """
Missing concepts: {missing_concepts}
Commonsense Feedback: {commonsense_feedback}
    """.strip()
    
    examples_prompt = ''
    for i, example in enumerate(examples):
        sentence_to_feedback = example['sentence_to_feedback']
        examples_prompt += '\n\n' + example_prompt_head.format(
            i=i+1,
            concepts=example['concepts'],
            sentence=sentence_to_feedback[0]['sentence'],
            missing_concepts=sentence_to_feedback[0]['concept_feedback'],
            commonsense_feedback=sentence_to_feedback[0]['commonsense_feedback'],
            generation_prompt=generation_prompt
        )
        for x in sentence_to_feedback[1:]:
            examples_prompt += '\n' + example_prompt_assistant.format(sentence=x['sentence'])
            examples_prompt += '\n' + example_prompt_user.format(
                missing_concepts=x['concept_feedback'],
                commonsense_feedback=x['commonsense_feedback'],
                generation_prompt=generation_prompt
            )
        # remove the last generation_prompt
        idx = examples_prompt.rfind(generation_prompt)
        examples_prompt = examples_prompt[0:idx].strip()
        
    prompt_template_0 = prompt_head+ '\n\n' + examples_prompt + '\n\n' + prompt_end_0 + '\n\n' + generation_prompt
    prompt_template_1 = prompt_end_1 + '\n\n' + generation_prompt
    return prompt_template_0, prompt_template_1
refine_prompt_template_0, refine_prompt_template_1 = construct_refine_prompt_templates()
utils.display_html(refine_prompt_template_0, 'Show refine prompt template for the first refinement')
utils.display_html(refine_prompt_template_1, 'Show refine prompt template for the rest refinement')
Show refine prompt template for the first refinement
We are having a multi-turn conversation in order to create a sentence that contains all given concepts. I will provide you with my feedback on the sentence regarding missing concepts and whether the sentence makes sense. Your task is to improve the provided sentence based on my feedback.

Here are 8 examples of our past conversations:

Example 1:
User:
Concepts: ['beat', 'drum', 'pen', 'sit', 'use']
Sentence: The drum sits on the pen and uses it to beat.
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because a drum cannot sit on a pen and use it to beat.

Improve the sentence using the above feedback.
Assistant:
Sentence: The drummer uses the drum to beat.
User:
Missing concepts: sit, pen
Commonsense Feedback: None

Improve the sentence using the above feedback.
Assistant:
Sentence: The drummer sits behind the drum and uses it to beat the pen.
User:
Missing concepts: None
Commonsense Feedback: None

Example 2:
User:
Concepts: ['chair', 'clipper', 'cut', 'hair', 'sit']
Sentence: A couch shaped girl sitting on the chair with her hair clipper.
Missing concepts: cut
Commonsense Feedback: The sentence does not make sense because a couch is not a shape and a hair clipper is not an item of clothing.

Improve the sentence using the above feedback.
Assistant:
Sentence: A girl on the chair with her hair clipper and cutting her hair.
User:
Missing concepts: sit
Commonsense Feedback: None

Improve the sentence using the above feedback.
Assistant:
Sentence: A girl sitting on the chair with a hair clipper, cutting her hair up.
User:
Missing concepts: None
Commonsense Feedback: None

Example 3:
User:
Concepts: ['grass', 'hose', 'spray', 'stand', 'water']
Sentence: The grass is standing tall and a hose is spraying it with spray.
Missing concepts: water
Commonsense Feedback: The sentence does not make sense because it is not clear what 'spray' is referring to, and grass does not have the ability to stand upright like a human or animal.

Improve the sentence using the above feedback.
Assistant:
Sentence: The hose is spraying water onto the grass that is standing like a person.
User:
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because grass cannot stand upright like a human or animal.

Improve the sentence using the above feedback.
Assistant:
Sentence: A person is standing on the grass, holding a hose that is spraying water onto the grass.
User:
Missing concepts: None
Commonsense Feedback: None

Example 4:
User:
Concepts: ['front', 'gong', 'hit', 'mallet', 'stand']
Sentence: A mallet is standing in front of a gong.
Missing concepts: hit
Commonsense Feedback: The sentence does not make sense because a mallet cannot stand in the front of a gong.

Improve the sentence using the above feedback.
Assistant:
Sentence: A musician stands in front of a gong with a mallet.
User:
Missing concepts: None
Commonsense Feedback: None

Improve the sentence using the above feedback.
Assistant:
Sentence: The musician stands in front of the gong and hits it with a mallet.
User:
Missing concepts: None
Commonsense Feedback: None

Example 5:
User:
Concepts: ['ball', 'dunk', 'hoop', 'jump', 'run']
Sentence: The ball runs to the hoop and dunks it.
Missing concepts: jump
Commonsense Feedback: The sentence does not make sense because a ball cannot run and dunk.

Improve the sentence using the above feedback.
Assistant:
Sentence: The ball jumps to the hoop and dunks it.
User:
Missing concepts: run
Commonsense Feedback: The sentence does not make sense because a ball cannot jump.

Improve the sentence using the above feedback.
Assistant:
Sentence: A basketball player runs up to the hoop and jumps off of the ball to dunk it.
User:
Missing concepts: None
Commonsense Feedback: None

Example 6:
User:
Concepts: ['card', 'chip', 'deal', 'dealer', 'table']
Sentence: A dealer offers a card to a group of people at a table.
Missing concepts: chip, deal
Commonsense Feedback: The sentence does not make sense because a chip cannot deal a card to a dealer.

Improve the sentence using the above feedback.
Assistant:
Sentence: The dealer deals a card to a group of people.
User:
Missing concepts: chip
Commonsense Feedback: None

Improve the sentence using the above feedback.
Assistant:
Sentence: The dealer deals a card to a group of people around the table with a chip at the table.
User:
Missing concepts: None
Commonsense Feedback: None

Example 7:
User:
Concepts: ['clean', 'climb', 'gutter', 'house', 'ladder']
Sentence: The house is clean and a ladder is trying to climb.
Missing concepts: climb
Commonsense Feedback: The sentence does not make sense because ladders cannot climb by themselves.

Improve the sentence using the above feedback.
Assistant:
Sentence: A person is cleaning the gutter of the house by climbing onto the roof with a ladder made of glass.
User:
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because ladders are not made of glass, and using a glass ladder would be dangerous and impractical.

Improve the sentence using the above feedback.
Assistant:
Sentence: A person is cleaning the gutter of the house by using a ladder to climb onto the roof and brushing away the dirt.
User:
Missing concepts: None
Commonsense Feedback: None

Example 8:
User:
Concepts: ['animal', 'catch', 'horse', 'lasso', 'ride']
Sentence: The horse catches the lasso and rides on it.
Missing concepts: animal
Commonsense Feedback: The sentence does not make sense because a horse cannot catch a lasso and ride on it.

Improve the sentence using the above feedback.
Assistant:
Sentence: The cowboy catches a horse with a lasso and rides on it.
User:
Missing concepts: animal
Commonsense Feedback: None

Improve the sentence using the above feedback.
Assistant:
Sentence: The cowboy catches the horse with a lasso and rides it.
User:
Missing concepts: None
Commonsense Feedback: None

Now let's start a new conversation so that you can improve a constructed sentence based on my feedback.

Concepts: {concepts}
Sentence: {sentence}
Missing concepts: {missing_concepts}
Commonsense Feedback: {commonsense_feedback}

Improve the sentence using the above feedback.
Show refine prompt template for the rest refinement
Missing concepts: {missing_concepts}
Commonsense Feedback: {commonsense_feedback}

Improve the sentence using the above feedback.

Experiments

def ask_llm(prompt, model):
    response = model.generate_content(prompt)
    return response.text.strip()
    
# a help function to remove prefix from model's outputs
def remove_prefix_if_exist(prefix, text):
    if prefix in text.lower():
        start_idx = text.lower().index(prefix) + len(prefix)
        text = text[start_idx:].strip()
    return text
nlp = spacy.load("en_core_web_sm")

def concepts_from_sentence(sentence, concepts):
    """extract concepts from a sentence using NLTK and spacy."""
    words = nltk.word_tokenize(sentence)
    lemmas = [t.lemma_ for t in nlp(sentence)]
    tokens = set(words + lemmas)
    
    found_concepts = set(concepts).intersection(tokens)
    return found_concepts

def fix_missing_concepts(concept_feedback, found_concepts):
    """fix model's concept feedback if there are any mistakes."""
    words = concept_feedback.split(',')
    words = map(lambda x: x.strip(), words)
    words = set(filter(lambda x: len(x)>0, words))    
    missing_concepts = words.difference(found_concepts)
    if missing_concepts:
        return ', '.join(missing_concepts)
    else:
        return 'None'

def process_feedback_outputs(outputs):
    concept_feedback, commonsense_feedback = outputs.split('\n',maxsplit=1)
    concept_feedback = remove_prefix_if_exist('missing concepts:', concept_feedback)
    commonsense_feedback = remove_prefix_if_exist('commonsense feedback:', commonsense_feedback)
    return concept_feedback, commonsense_feedback
def get_feedback(sentence, concepts, model):
    found_concepts = concepts_from_sentence(sentence, concepts)
    
    feedback_prompt = feedback_prompt_template.format(concepts=concepts, sentence=sentence)
    feedback_outputs = ask_llm(feedback_prompt, model)
    print(f'{"="*10} DEBUG {"="*10}')
    print(f'Sentence: {sentence}')
    print(feedback_outputs)
    print(f'{"-"*10}-------{"-"*10}')
    
    concept_feedback, commonsense_feedback = process_feedback_outputs(feedback_outputs)
    fixed_missing_concepts = fix_missing_concepts(concept_feedback, found_concepts)
    return fixed_missing_concepts, commonsense_feedback
def run_refine_loop(sentence, concepts, model, max_tries=5, throttle=False, throttle_value=5):
    refine_gen_prefix = 'sentence:'
    refine_prompt_template = refine_prompt_template_0
    chat = model.start_chat()
        
    for i in range(max_tries):
        start_time = time.perf_counter()
        missing_concepts, commonsense_feedback = get_feedback(sentence, concepts, model)
        if 'none' == missing_concepts.lower() and 'none' == commonsense_feedback.lower():
            if i != 0:
                chat.history.append(Content(
                    role='user',
                    parts=[Part(text='Missing concepts: None\nCommonsense Feedback: None')])
                )
            return sentence, chat.history

        if throttle:
            utils.throttle(start_time, throttle_value)

        start_time = time.perf_counter()
        refine_prompt = refine_prompt_template.format(
            concepts=concepts,
            sentence=sentence,
            missing_concepts=missing_concepts,
            commonsense_feedback=commonsense_feedback
        )
        refine_outputs = chat.send_message(refine_prompt).text.strip()
        
        if refine_gen_prefix in refine_outputs.lower():
            start_idx = refine_outputs.lower().index(refine_gen_prefix) + len(refine_gen_prefix)
            sentence = refine_outputs[start_idx:].strip()
        else:
            sentence = refine_outputs

        if i == 0:
            refine_prompt_template = refine_prompt_template_1

        if throttle:
            utils.throttle(start_time, throttle_value)

    missing_concepts, commonsense_feedback = get_feedback(sentence, concepts, model)
    parts_text = f'Missing concepts: {missing_concepts}\nCommonsense Feedback: {commonsense_feedback}'
    chat.history.append(Content(
        role='user', 
        parts=[Part(text=parts_text)])
    )

    return sentence, chat.history

Configure both gemini-1.5-flash and gemini-1.5-pro models.

genai.configure(api_key=os.environ['GOOGLE_API_KEY'])
safe = [
    {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"}
]

model_flash = genai.GenerativeModel(
    'gemini-1.5-flash-001',
    safety_settings=safe,
    system_instruction='You are a helpful assistant. Avoid markdown in your response. Plain text only.',
    generation_config={'temperature': 0.7, 'max_output_tokens': 256}
)
model_pro = genai.GenerativeModel(
    'gemini-1.5-pro-001',
    safety_settings=safe,
    system_instruction='You are a helpful assistant. Avoid markdown in your response. Plain text only.',
    generation_config={'temperature': 0.7, 'max_output_tokens': 256}
)

Exp 01: using gemini-1.5-flash

1. generate the initial sentence

# an example from authors' [commongen_hard.jsonl](https://github.com/madaan/self-refine/blob/main/data/prompt/commongen/commongen_hard.jsonl)
concepts = ["use", "goat", "wine", "frisbee",
            "leap", "pole", "tell", "pencil",
            "spin", "birdie", "catcher", "fence",
            "world", "step", "chop", "sword",
            "march", "stage", "axe", "bat",
            "place", "roller", "tomato"]
init_prompt = init_prompt_template.format(concepts=concepts)

utils.display_html(init_prompt, 'Show init prompt')
Show init prompt
I want you to create a sentence that contains all the specified concepts.

Here are some examples:

Concepts: ['footage', 'motion', 'ruin', 'tilt', 'window']
The sentence is: time lapse footage with tilt up motion of the sun streaking through window of ruin

Concepts: ['cause', 'hate', 'hut', 'local', 'love']
The sentence is: new beach huts on the island have caused some controversy some locals love them others hate them

Concepts: ['call', 'contain', 'dress', 'gown', 'wallpaper']
The sentence is: the wallpaper probably containing a gown and a dinner dress called

Concepts: ['knock', 'leave', 'pew', 'rush', 'seat']
The sentence is: She leaves the confessional and rushes past a pew, knocking a Bible from the seat.

Concepts: ['help', 'moment', 'spend', 'uplift', 'world']
The sentence is: every moment that we spend in higher consciousness helps uplift the consciousness of the whole world

Concepts: ['label', 'pende', 'stamp', 'text', 'write']
The sentence is: abstract stamp or label with the text pending written inside

Concepts: ['create', 'ferry', 'silhouette', 'stream', 'terminal']
The sentence is: light streams through windows at the railroad and ferry terminal creating a beautiful silhouette

Concepts: ['chair', 'couch', 'hang', 'room', 'wall']
The sentence is: A room with a couch, chairs and art hanging on the wall.

Concepts: ['boat', 'building', 'harbour', 'moor', 'quay']
The sentence is: the harbour and port with fishing boats moored and old buildings on the quay

Concepts: ['admirer', 'arrive', 'commander', 'crowd', 'greet']
The sentence is: military commander is greeted by a crowd of admirers as he arrives

Now create a sentence using the following concepts:

Concepts: ['use', 'goat', 'wine', 'frisbee', 'leap', 'pole', 'tell', 'pencil', 'spin', 'birdie', 'catcher', 'fence', 'world', 'step', 'chop', 'sword', 'march', 'stage', 'axe', 'bat', 'place', 'roller', 'tomato']
The sentence is:
init_outputs = ask_llm(init_prompt, model_flash)
sentence = remove_prefix_if_exist('the sentence is:', init_outputs)
sentence
'The goat leaps over the fence, using the pole as a springboard, while the catcher spins a frisbee, aiming for the birdie, and the world marches on stage, a place where tomatoes are chopped with an axe and wine is drunk from a roller, told with a pencil and a sword.'

2. run the refine loop

sentence, history = run_refine_loop(sentence, concepts, model_flash)
========== DEBUG ==========
Sentence: The goat leaps over the fence, using the pole as a springboard, while the catcher spins a frisbee, aiming for the birdie, and the world marches on stage, a place where tomatoes are chopped with an axe and wine is drunk from a roller, told with a pencil and a sword.
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because it is a nonsensical combination of unrelated ideas.
---------------------------
========== DEBUG ==========
Sentence: The goat leaps over the fence using a pole, while the catcher spins a frisbee aiming for the birdie.
Missing concepts: use, tell, world, step, chop, sword, march, stage, axe, bat, place, roller, tomato
Commonsense Feedback: The sentence does not make sense because a goat cannot leap over a fence using a pole.
---------------------------
========== DEBUG ==========
Sentence: The goat steps over the fence while the catcher spins a frisbee aiming for the birdie, and the world marches on stage, a place where tomatoes are chopped with an axe and wine is drunk from a roller, told with a pencil and a sword.
Missing concepts: use, leap, pole, tell, bat, place
Commonsense Feedback: The sentence does not make sense because a goat cannot step over a fence while a catcher spins a frisbee, the world cannot march on stage, and tomatoes cannot be chopped with an axe.
---------------------------
========== DEBUG ==========
Sentence: The goat leaps over the fence using a pole while the catcher spins a frisbee aiming for the birdie. The world marches on stage, a place where tomatoes are chopped with a bat and wine is drunk from a roller, told with a pencil and a sword.
Missing concepts:  axe, step, use, chop 
Commonsense Feedback: The sentence does not make sense because a goat cannot leap over a fence using a pole, and a world cannot march on stage. Tomatoes cannot be chopped with a bat, and wine cannot be drunk from a roller.
---------------------------
========== DEBUG ==========
Sentence: The goat steps over the fence while the catcher spins a frisbee aiming for the birdie. The world marches on stage, a place where tomatoes are chopped with an axe and wine is drunk from a roller, told with a pencil and a sword.
Missing concepts: use, leap, bat, pole, tell

Commonsense Feedback: The sentence does not make sense because the world cannot march on stage, tomatoes are not chopped with an axe, and wine is not drunk from a roller.
---------------------------
========== DEBUG ==========
Sentence: The goat leaps over the fence using a pole while the catcher spins a frisbee aiming for the birdie. The world marches on stage, a place where tomatoes are chopped with a bat and wine is drunk from a roller, told with a pencil and a sword.
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because it is nonsensical and uses a random combination of the concepts.
---------------------------
sentence
'The goat leaps over the fence using a pole while the catcher spins a frisbee aiming for the birdie. The world marches on stage, a place where tomatoes are chopped with a bat and wine is drunk from a roller, told with a pencil and a sword.'
last_feedback = history[-1].parts[0].text
print(last_feedback)
Missing concepts: None
Commonsense Feedback: The sentence does not make sense because it is nonsensical and uses a random combination of the concepts.
utils.display_html(history, 'Show refine history')
Show refine history
[parts {
  text: "We are having a multi-turn conversation in order to create a sentence that contains all given concepts. I will provide you with my feedback on the sentence regarding missing concepts and whether the sentence makes sense. Your task is to improve the provided sentence based on my feedback.\n\nHere are 8 examples of our past conversations:\n\nExample 1:\nUser:\nConcepts: [\'beat\', \'drum\', \'pen\', \'sit\', \'use\']\nSentence: The drum sits on the pen and uses it to beat.\nMissing concepts: None\nCommonsense Feedback: The sentence does not make sense because a drum cannot sit on a pen and use it to beat.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The drummer uses the drum to beat.\nUser:\nMissing concepts: sit, pen\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The drummer sits behind the drum and uses it to beat the pen.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 2:\nUser:\nConcepts: [\'chair\', \'clipper\', \'cut\', \'hair\', \'sit\']\nSentence: A couch shaped girl sitting on the chair with her hair clipper.\nMissing concepts: cut\nCommonsense Feedback: The sentence does not make sense because a couch is not a shape and a hair clipper is not an item of clothing.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A girl on the chair with her hair clipper and cutting her hair.\nUser:\nMissing concepts: sit\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A girl sitting on the chair with a hair clipper, cutting her hair up.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 3:\nUser:\nConcepts: [\'grass\', \'hose\', \'spray\', \'stand\', \'water\']\nSentence: The grass is standing tall and a hose is spraying it with spray.\nMissing concepts: water\nCommonsense Feedback: The sentence does not make sense because it is not clear what \'spray\' is referring to, and grass does not have the ability to stand upright like a human or animal.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The hose is spraying water onto the grass that is standing like a person.\nUser:\nMissing concepts: None\nCommonsense Feedback: The sentence does not make sense because grass cannot stand upright like a human or animal.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A person is standing on the grass, holding a hose that is spraying water onto the grass.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 4:\nUser:\nConcepts: [\'front\', \'gong\', \'hit\', \'mallet\', \'stand\']\nSentence: A mallet is standing in front of a gong.\nMissing concepts: hit\nCommonsense Feedback: The sentence does not make sense because a mallet cannot stand in the front of a gong.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A musician stands in front of a gong with a mallet.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The musician stands in front of the gong and hits it with a mallet.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 5:\nUser:\nConcepts: [\'ball\', \'dunk\', \'hoop\', \'jump\', \'run\']\nSentence: The ball runs to the hoop and dunks it.\nMissing concepts: jump\nCommonsense Feedback: The sentence does not make sense because a ball cannot run and dunk.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The ball jumps to the hoop and dunks it.\nUser:\nMissing concepts: run\nCommonsense Feedback: The sentence does not make sense because a ball cannot jump.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A basketball player runs up to the hoop and jumps off of the ball to dunk it.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 6:\nUser:\nConcepts: [\'card\', \'chip\', \'deal\', \'dealer\', \'table\']\nSentence: A dealer offers a card to a group of people at a table.\nMissing concepts: chip, deal\nCommonsense Feedback: The sentence does not make sense because a chip cannot deal a card to a dealer.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The dealer deals a card to a group of people.\nUser:\nMissing concepts: chip\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The dealer deals a card to a group of people around the table with a chip at the table.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 7:\nUser:\nConcepts: [\'clean\', \'climb\', \'gutter\', \'house\', \'ladder\']\nSentence: The house is clean and a ladder is trying to climb.\nMissing concepts: climb\nCommonsense Feedback: The sentence does not make sense because ladders cannot climb by themselves.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A person is cleaning the gutter of the house by climbing onto the roof with a ladder made of glass.\nUser:\nMissing concepts: None\nCommonsense Feedback: The sentence does not make sense because ladders are not made of glass, and using a glass ladder would be dangerous and impractical.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A person is cleaning the gutter of the house by using a ladder to climb onto the roof and brushing away the dirt.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 8:\nUser:\nConcepts: [\'animal\', \'catch\', \'horse\', \'lasso\', \'ride\']\nSentence: The horse catches the lasso and rides on it.\nMissing concepts: animal\nCommonsense Feedback: The sentence does not make sense because a horse cannot catch a lasso and ride on it.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The cowboy catches a horse with a lasso and rides on it.\nUser:\nMissing concepts: animal\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The cowboy catches the horse with a lasso and rides it.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nNow let\'s start a new conversation so that you can improve a constructed sentence based on my feedback.\n\nConcepts: [\'use\', \'goat\', \'wine\', \'frisbee\', \'leap\', \'pole\', \'tell\', \'pencil\', \'spin\', \'birdie\', \'catcher\', \'fence\', \'world\', \'step\', \'chop\', \'sword\', \'march\', \'stage\', \'axe\', \'bat\', \'place\', \'roller\', \'tomato\']\nSentence: The goat leaps over the fence, using the pole as a springboard, while the catcher spins a frisbee, aiming for the birdie, and the world marches on stage, a place where tomatoes are chopped with an axe and wine is drunk from a roller, told with a pencil and a sword.\nMissing concepts: None\nCommonsense Feedback: The sentence does not make sense because it is a nonsensical combination of unrelated ideas.\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "Sentence: The goat leaps over the fence using a pole, while the catcher spins a frisbee aiming for the birdie. \n"
}
role: "model"
, parts {
  text: "Missing concepts: step, march, world, stage, place, axe, roller, sword, chop, bat, tomato, tell\nCommonsense Feedback: The sentence does not make sense because a goat cannot leap over a fence using a pole.\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "Sentence: The goat steps over the fence while the catcher spins a frisbee aiming for the birdie, and the world marches on stage, a place where tomatoes are chopped with an axe and wine is drunk from a roller, told with a pencil and a sword. \n"
}
role: "model"
, parts {
  text: "Missing concepts: bat, leap, pole, use\nCommonsense Feedback: The sentence does not make sense because a goat cannot step over a fence while a catcher spins a frisbee, the world cannot march on stage, and tomatoes cannot be chopped with an axe.\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "Sentence: The goat leaps over the fence using a pole while the catcher spins a frisbee aiming for the birdie. The world marches on stage, a place where tomatoes are chopped with a bat and wine is drunk from a roller, told with a pencil and a sword. \n"
}
role: "model"
, parts {
  text: "Missing concepts: step, axe\nCommonsense Feedback: The sentence does not make sense because a goat cannot leap over a fence using a pole, and a world cannot march on stage. Tomatoes cannot be chopped with a bat, and wine cannot be drunk from a roller.\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "Sentence: The goat steps over the fence while the catcher spins a frisbee aiming for the birdie. The world marches on stage, a place where tomatoes are chopped with an axe and wine is drunk from a roller, told with a pencil and a sword. \n"
}
role: "model"
, parts {
  text: "Missing concepts: bat, leap, pole, use\nCommonsense Feedback: The sentence does not make sense because the world cannot march on stage, tomatoes are not chopped with an axe, and wine is not drunk from a roller.\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "Sentence: The goat leaps over the fence using a pole while the catcher spins a frisbee aiming for the birdie. The world marches on stage, a place where tomatoes are chopped with a bat and wine is drunk from a roller, told with a pencil and a sword. \n"
}
role: "model"
, parts {
  text: "Missing concepts: None\nCommonsense Feedback: The sentence does not make sense because it is nonsensical and uses a random combination of the concepts."
}
role: "user"
]

Exp 02: using gemini-1.5-pro

1. generate the initial sentence

init_prompt = init_prompt_template.format(concepts=concepts)
utils.display_html(init_prompt, 'Show init prompt')
Show init prompt
I want you to create a sentence that contains all the specified concepts.

Here are some examples:

Concepts: ['footage', 'motion', 'ruin', 'tilt', 'window']
The sentence is: time lapse footage with tilt up motion of the sun streaking through window of ruin

Concepts: ['cause', 'hate', 'hut', 'local', 'love']
The sentence is: new beach huts on the island have caused some controversy some locals love them others hate them

Concepts: ['call', 'contain', 'dress', 'gown', 'wallpaper']
The sentence is: the wallpaper probably containing a gown and a dinner dress called

Concepts: ['knock', 'leave', 'pew', 'rush', 'seat']
The sentence is: She leaves the confessional and rushes past a pew, knocking a Bible from the seat.

Concepts: ['help', 'moment', 'spend', 'uplift', 'world']
The sentence is: every moment that we spend in higher consciousness helps uplift the consciousness of the whole world

Concepts: ['label', 'pende', 'stamp', 'text', 'write']
The sentence is: abstract stamp or label with the text pending written inside

Concepts: ['create', 'ferry', 'silhouette', 'stream', 'terminal']
The sentence is: light streams through windows at the railroad and ferry terminal creating a beautiful silhouette

Concepts: ['chair', 'couch', 'hang', 'room', 'wall']
The sentence is: A room with a couch, chairs and art hanging on the wall.

Concepts: ['boat', 'building', 'harbour', 'moor', 'quay']
The sentence is: the harbour and port with fishing boats moored and old buildings on the quay

Concepts: ['admirer', 'arrive', 'commander', 'crowd', 'greet']
The sentence is: military commander is greeted by a crowd of admirers as he arrives

Now create a sentence using the following concepts:

Concepts: ['use', 'goat', 'wine', 'frisbee', 'leap', 'pole', 'tell', 'pencil', 'spin', 'birdie', 'catcher', 'fence', 'world', 'step', 'chop', 'sword', 'march', 'stage', 'axe', 'bat', 'place', 'roller', 'tomato']
The sentence is:
init_outputs = ask_llm(init_prompt, model_pro)

sentence = remove_prefix_if_exist('the sentence is:', init_outputs)
sentence
'The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board.'

2. run the refine loop

sentence, history = run_refine_loop(sentence, concepts, model_pro)
========== DEBUG ==========
Sentence: The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board.
Missing concepts: use, wine, tell, pencil, catcher, step, chop, sword, march, stage, axe, bat, place, roller 
Commonsense Feedback: None
---------------------------
========== DEBUG ==========
Sentence: The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music.
Missing concepts: wine, tell, catcher, step, chop, sword, axe, bat, place, roller 
Commonsense Feedback: None
---------------------------
========== DEBUG ==========
Sentence: The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board being chopped, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. A baseball player, bat in hand, stepped up to the plate, while a nearby vendor told stories, a bottle of wine in hand, about the legendary warrior who could slice a tomato in half with a single swing of his axe.
Missing concepts: catcher, pole, sword 
Commonsense Feedback: None
---------------------------
========== DEBUG ==========
Sentence: The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board being chopped, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. A baseball player, bat in hand, stepped up to the plate, the catcher crouched behind, watching intently, while a nearby vendor, leaning against a pole, told stories, a bottle of wine in hand, about the legendary warrior who could slice a tomato in half with a single swing of his sword.
Missing concepts: axe, roller 
Commonsense Feedback: None
---------------------------
========== DEBUG ==========
Sentence: The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board being chopped by a roller, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. A baseball player, bat in hand, stepped up to the plate, the catcher crouched behind, watching intently, while a nearby vendor, leaning against a pole, told stories, a bottle of wine in hand, about the legendary warrior who could slice a tomato in half with a single swing of his sword or an axe.
Missing concepts: chop, sword 

Commonsense Feedback: None
---------------------------
sentence
'The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board being chopped by a roller, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. A baseball player, bat in hand, stepped up to the plate, the catcher crouched behind, watching intently, while a nearby vendor, leaning against a pole, told stories, a bottle of wine in hand, about the legendary warrior who could slice a tomato in half with a single swing of his sword or an axe.'
last_feedback = history[-1].parts[0].text
print(last_feedback)
Missing concepts: None
Commonsense Feedback: None
utils.display_html(history, 'Show refine history')
Show refine history
[parts {
  text: "We are having a multi-turn conversation in order to create a sentence that contains all given concepts. I will provide you with my feedback on the sentence regarding missing concepts and whether the sentence makes sense. Your task is to improve the provided sentence based on my feedback.\n\nHere are 8 examples of our past conversations:\n\nExample 1:\nUser:\nConcepts: [\'beat\', \'drum\', \'pen\', \'sit\', \'use\']\nSentence: The drum sits on the pen and uses it to beat.\nMissing concepts: None\nCommonsense Feedback: The sentence does not make sense because a drum cannot sit on a pen and use it to beat.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The drummer uses the drum to beat.\nUser:\nMissing concepts: sit, pen\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The drummer sits behind the drum and uses it to beat the pen.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 2:\nUser:\nConcepts: [\'chair\', \'clipper\', \'cut\', \'hair\', \'sit\']\nSentence: A couch shaped girl sitting on the chair with her hair clipper.\nMissing concepts: cut\nCommonsense Feedback: The sentence does not make sense because a couch is not a shape and a hair clipper is not an item of clothing.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A girl on the chair with her hair clipper and cutting her hair.\nUser:\nMissing concepts: sit\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A girl sitting on the chair with a hair clipper, cutting her hair up.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 3:\nUser:\nConcepts: [\'grass\', \'hose\', \'spray\', \'stand\', \'water\']\nSentence: The grass is standing tall and a hose is spraying it with spray.\nMissing concepts: water\nCommonsense Feedback: The sentence does not make sense because it is not clear what \'spray\' is referring to, and grass does not have the ability to stand upright like a human or animal.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The hose is spraying water onto the grass that is standing like a person.\nUser:\nMissing concepts: None\nCommonsense Feedback: The sentence does not make sense because grass cannot stand upright like a human or animal.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A person is standing on the grass, holding a hose that is spraying water onto the grass.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 4:\nUser:\nConcepts: [\'front\', \'gong\', \'hit\', \'mallet\', \'stand\']\nSentence: A mallet is standing in front of a gong.\nMissing concepts: hit\nCommonsense Feedback: The sentence does not make sense because a mallet cannot stand in the front of a gong.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A musician stands in front of a gong with a mallet.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The musician stands in front of the gong and hits it with a mallet.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 5:\nUser:\nConcepts: [\'ball\', \'dunk\', \'hoop\', \'jump\', \'run\']\nSentence: The ball runs to the hoop and dunks it.\nMissing concepts: jump\nCommonsense Feedback: The sentence does not make sense because a ball cannot run and dunk.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The ball jumps to the hoop and dunks it.\nUser:\nMissing concepts: run\nCommonsense Feedback: The sentence does not make sense because a ball cannot jump.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A basketball player runs up to the hoop and jumps off of the ball to dunk it.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 6:\nUser:\nConcepts: [\'card\', \'chip\', \'deal\', \'dealer\', \'table\']\nSentence: A dealer offers a card to a group of people at a table.\nMissing concepts: chip, deal\nCommonsense Feedback: The sentence does not make sense because a chip cannot deal a card to a dealer.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The dealer deals a card to a group of people.\nUser:\nMissing concepts: chip\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The dealer deals a card to a group of people around the table with a chip at the table.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 7:\nUser:\nConcepts: [\'clean\', \'climb\', \'gutter\', \'house\', \'ladder\']\nSentence: The house is clean and a ladder is trying to climb.\nMissing concepts: climb\nCommonsense Feedback: The sentence does not make sense because ladders cannot climb by themselves.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A person is cleaning the gutter of the house by climbing onto the roof with a ladder made of glass.\nUser:\nMissing concepts: None\nCommonsense Feedback: The sentence does not make sense because ladders are not made of glass, and using a glass ladder would be dangerous and impractical.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: A person is cleaning the gutter of the house by using a ladder to climb onto the roof and brushing away the dirt.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nExample 8:\nUser:\nConcepts: [\'animal\', \'catch\', \'horse\', \'lasso\', \'ride\']\nSentence: The horse catches the lasso and rides on it.\nMissing concepts: animal\nCommonsense Feedback: The sentence does not make sense because a horse cannot catch a lasso and ride on it.\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The cowboy catches a horse with a lasso and rides on it.\nUser:\nMissing concepts: animal\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback.\nAssistant:\nSentence: The cowboy catches the horse with a lasso and rides it.\nUser:\nMissing concepts: None\nCommonsense Feedback: None\n\nNow let\'s start a new conversation so that you can improve a constructed sentence based on my feedback.\n\nConcepts: [\'use\', \'goat\', \'wine\', \'frisbee\', \'leap\', \'pole\', \'tell\', \'pencil\', \'spin\', \'birdie\', \'catcher\', \'fence\', \'world\', \'step\', \'chop\', \'sword\', \'march\', \'stage\', \'axe\', \'bat\', \'place\', \'roller\', \'tomato\']\nSentence: The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board.\nMissing concepts: step, march, stage, place, axe, roller, sword, use, catcher, pencil, chop, wine, bat, tell\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. \n"
}
role: "model"
, parts {
  text: "Missing concepts: step, place, axe, roller, sword, catcher, chop, wine, bat, tell\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board being chopped, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. A baseball player, bat in hand, stepped up to the plate, while a nearby vendor told stories, a bottle of wine in hand, about the legendary warrior who could slice a tomato in half with a single swing of his axe. \n"
}
role: "model"
, parts {
  text: "Missing concepts: sword, pole, catcher\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board being chopped, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. A baseball player, bat in hand, stepped up to the plate, the catcher crouched behind, watching intently, while a nearby vendor, leaning against a pole, told stories, a bottle of wine in hand, about the legendary warrior who could slice a tomato in half with a single swing of his sword. \n"
}
role: "model"
, parts {
  text: "Missing concepts: axe, roller\nCommonsense Feedback: None\n\nImprove the sentence using the above feedback."
}
role: "user"
, parts {
  text: "The goat, perched atop the fence post, watched the world go by: a frisbee spinning through the air, a birdie leaping over a badminton net, a tomato rolling off a chopping board being chopped by a roller, while on the nearby stage, a marching band played, their instruments glinting in the sun - a tuba here, a flute there, and a lone trombone player using a pencil to prop up his music. A baseball player, bat in hand, stepped up to the plate, the catcher crouched behind, watching intently, while a nearby vendor, leaning against a pole, told stories, a bottle of wine in hand, about the legendary warrior who could slice a tomato in half with a single swing of his sword or an axe. \n"
}
role: "model"
, parts {
  text: "Missing concepts: None\nCommonsense Feedback: None"
}
role: "user"
]

References

[1]
A. Madaan et al., “Self-refine: Iterative refinement with self-feedback.” 2023. Available: https://arxiv.org/abs/2303.17651