The most important rules when prompting
September 9, 2024
After looking at the different types of AI in the first part of our series, taking a closer look at generative AI and its special features in the second part, looking at the different models in the third part, and finding out which properties of language models we need to consider when prompting in the fourth part, this part is all about the practice of prompting.
Prompting is both easy and difficult. Easy because we 'only' have to say what we want. Difficult because we have to say exactly what we want. And sometimes that is more complicated than you think.
When you ask, always remember that you are dealing with a brilliant person who doesn't know you, your habits, your way of communicating, or your expertise. To bring out the brilliance, it is important to tell the language model exactly what you want.
The five rules of prompting
But what does precise mean in this case? There are a few essential rules that will guide you to a good prompt:
- Be clear, direct, and detailed:
- Provide contextual information, such as why you need the answer, who the answer is relevant to, or the overall goal of your question.
- Indicate the form you expect the answer to take, whether it is a text, a numbered list, a table, or some other format.
- Structure your question to indicate how the task you are giving the language model is to be completed.
- Few-shot prompting: What sounds complicated and technical is quickly explained. By using examples, you help the language model to understand your expectations. They help you to avoid possible misinterpretations of your instructions, to specify a particular response structure or style, and to solve more complex tasks. Your examples should be as closely related as possible to your current question or task. If you know what misinterpretations your prompt might cause, you can avoid them by providing an example.
- Chain of thought: Get the language model to 'think', i.e. to analyse a task and complete it in several small steps. This technique is particularly useful for research, analysis, and tasks involving mathematics or logical thinking. You can directly ask the language model to complete a task step by step. You will get even better results if you specify the steps yourself, for example by describing which steps there are and how they should be completed.
- Give the language model a role: You have probably read this many times, and it is often the first thing to do is to assign a role to the language model. This is only necessary if the role does not follow automatically from the question. For example, if you want to imitate someone's writing style, or if you want the language model to answer from the point of view of a particular specialist, then give it a role.
- Structure your prompt: A prompt is a text and should be structured as such. Divide your prompt into different sections and indicate what is in each section. Whereas in a normal text you would use headings, in a prompt one term is sufficient. If you want to provide the language model with examples, preface them with 'Example 1:', 'Example 2:', etc.
If you follow these rules when prompting, and keep in mind how best to avoid hallucinations, you will quickly achieve success.
And if the language model doesn't deliver what you expect, it also helps to send the same prompt again. We have learned that generative AI is not deterministic. We can use that to our advantage in prompting.