Prompting & Completion
Generally speaking, our models attempt to find the best continuation for a given input. This is referred to as a completion in the world of Natural Language Processing (NLP). To find the best completion, we have to write good prompts, which are your input to the model. Our models continue the given prompt by choosing the most likely continuation from a probability distribution. Practically, this means that the model first recognizes the style of the prompt and then attempts to continue it accordingly. Depending on the task at hand, the structure and content of the prompt are essential to generating completions that match the input task.
Zero-shot Learning
For certain tasks, simply providing a natural language instruction to the model may be sufficient to have it complete a task. Completing a task like this is called zero-shot learning. Let’s illustrate this using an example.
Provide a short description of AI: AI is a set of techniques that use machine learning to make computer programs learn from data.
This worked well! However, the model’s best continuation is not necessarily aligned with your desired continuation. Therefore, it may not be enough to simply give the model natural language instructions for its task.
Few-shot Learning
Especially for more complicated tasks, or those that require a specific format, you may have to explicitly show how to properly continue your prompt – by providing one or more examples. This is called few-shot learning (or one-shot learning in the case of just a single example). Let’s have a look at how this plays out in practice.
You’re thinking about where to go for your next vacation. Therefore, you’d like to have a list of possible travel destinations. You may ask the model to assist you in this matter. Before, it has proven effective to simply tell the model what to do. Let’s first try this zero-shot approach yet again:
I want to travel to a location where I can enjoy sun, sports and landscapes. Where could I go?
Think about how you would answer this query. You may get the gist and list a few possible locations that satisfy the given constraints. On the other hand, you could reply with a lengthy report of that one beautiful place you once visited. You could also say “I don’t know”. Anyhow, there are a dozen different ways in which you could answer this question, none of which are strictly right or wrong. Accordingly, the model could output:
I’ve been to the Caribbean, and I’ve been to the Mediterranean, but I’ve never been to California.
Well, that’s not quite what we were hoping for. Let’s try to improve this prompt. To maximize our chances that the model outputs a list with cool vacation destinations, we must show examples of how to perform this task, i.e. use few-shot learning.
Recommend a travel destination based on the keywords.
###
Keywords: Historic City, Scenic Views, Castle
Travel Destination: Heidelberg, Germany. Heidelberg is one of the most beautiful cities in Germany, with a historic "Altstadt" and a castle.
###
Keywords: Lake, Forrest, Fishing
Travel Destination: Lake Tahoe, California. This famous lake in the Sierra Nevada mountains offers an amazing variety of outdoor activities.
###
Keywords: Museums, Food, History
Travel Destination: Rome, Italy. Rome is a city full of museums, historic sites and excellent restaurants.
###
Keywords: Beaches, Party, Hiking
Travel Destination: Mallorca, Spain. This island is famous for its sandy beaches, hilly landscape and vibrant nightlife.
###
Keywords: Sun, Sports, Landscapes
Travel Destination: Phuket, Thailand. This island in the Andaman Sea is known for its pristine beaches and wide variety of outdoor activities.
This is much better because the model understood the underlying structure of your task. To write good prompts use either instructions, examples or both to convey what you wish to do. Find the Jumpstart section for more detailed prompting advice for specific tasks.
Let’s go over some more tips and tricks for prompt design. In this case, we use a Q&A example to illustrate them. However, they are just as useful for all other kinds of prompting.
- Structure your prompt. For example, instead of asking:
Try:How many people live in New York City? How many people live in the United States?
In case you are using few-shot learning, try to clearly separate the examples by using separators such as "###":Q: How many people live in New York City? A: There are about 8.5 million people in the city.
Q: How long is the river Nile? A: It's roughly 6650 kilometers long. ### Q: How many people live in New York City? A: About 8.5 million people.
- You should not end your prompt on a space character. The model will most likely return nonsense.
Q: How many people live in New York City? A: B: C: D: E: F: G:
- Check your prompts for mistakes. Spelling mistakes, grammatical errors or even double spaces may adversely affect your results.
In this example, the model did not recognize the word "city" correctly, thus it returned “state of New York” accompanied with the number of inhabitants of New York City. Thus, our answer is now wrong.Q: How many people live in New York Cty? A: There are about 8.5 million people in the state of New York.
Zero-shot Learning with Luminous-supreme-control
Our steerable model Luminous-supreme-control has been optimized to work well with zero-shot instructions. This means that they do not necessarily need a set of examples like in few-shot learning. To give you a better understanding of this, let's look at the following few-shot prompt, which identifies topics in a text.
Identify the topic of each text.
###
Text: After initially making significant recovery gains, the most important indices turned into the red later in the day. The downward trend was particularly steep in the last few minutes of trading.
Topic: Finance
###
Text: The wizard rose from his chair and gazed across the room. Finally, his blue eyes settled on a stocky man. In a surprisingly swift manner, the old wizard waved his wand and the man turned into a large frog.
Topic: Fantasy
###
Text: Flowering plants grow fruits to spread their seeds. Edible fruits function symbiotically. Animals obtain nourishment from consuming the fruit and the animal's movement helps spread the seed.
Topic: Biology
With Luminous-supreme-control we can (but do not have to) omit the few-shot examples and just provide a statement that tells the model what to do.
Task: Identify the topic of the text.
Text: Flowering plants grow fruits to spread their seeds. Edible fruits function symbiotically. Animals obtain nourishment from consuming the fruit and the animal's movement helps spread the seed.
Topic: Fruit
Prompting Luminous-supreme control is a bit different compared to our other models. Therefore, we would like to share some best practices with you.
1.) The best way to structure your prompt is to give a task and a context with it. Be as descriptive and specific as possible when defining the task. For example, if you want the model to return that it cannot answer a question to a text, you should state that in the task.
Task: Answer to a given question. If the answer is not in the context, reply with "Unanswerable".
Context: Flowering plants grow fruits to spread their seeds. Edible fruits function symbiotically. Animals obtain nourishment from consuming the fruit and the animal's movement helps spread the seed.
Question: Do cars help to spread the seed of flowering plants?
Answer: Unanswerable
2.) You should be consistent with line breaks. That means instead of desiging a prompt like this:
Task: Identify the topic of the text.
Text:
Flowering plants grow fruits to spread their seeds. Edible fruits function symbiotically. Animals obtain nourishment from consuming the fruit and the animal's movement helps spread the seed.
Topic:
Fruit
Try:
Task: Identify the topic of the text.
Text: Flowering plants grow fruits to spread their seeds. Edible fruits function symbiotically. Animals obtain nourishment from consuming the fruit and the animal's movement helps spread the seed.
Topic: Fruit
3.) Currently, Luminous-supreme-control tends to begin with one or more linebreaks. You could manually strip it, by using completion.strip()
in Python. In the future we will provide a more elegant solution to this.