Lesson ยท 10 min
What a prompt is
The text that the model gets
A prompt is the text that you send to a model. In a program, it has two parts. The system message has your instructions, and they are the same for each call. The user message has the data of one call, such as the comment of a rider.
The model has nothing but this text. It does not know your product, your users, or what you think is a good answer. A small change in the text can change many answers. So the prompt is a part of your program, and you work on it as you work on code.
The parts of a good prompt
| Part | Example |
|---|---|
| The task | Classify the comment. |
| The allowed answers | as one of: praise, complaint, question, other |
| Rules for the hard cases | A comment that asks something is a question. |
| Examples | A comment, and the label that you want for it. |
| The form of the answer | Answer with one word. |
Lesson 2 of the course Model APIs used the first two parts and the last part. This course adds the rules and the examples, and it shows how to test each change.
Measure, change, measure
Many people change a prompt, look at one answer, and think that the prompt is better now. That is a guess. This course uses a method.
- Measure the prompt on comments that have a known label.
- Read the wrong answers, and find their cause.
- Change one thing in the prompt.
- Measure again. Keep the change when the result is better.
The model in this course
The lessons run in your browser, so the model is simulated. It is the file sim_model.py in the tab next to main.py. You call it in the same way as in the course Model APIs.
The small model of this simulation is weak on purpose. Then you can see how a better prompt changes the answers. It reads a rule in your prompt by the key words of the rule, so use the sentences that the lessons give you. A real model reads the meaning of a sentence. The method of this course is the same for a real model.
zip(answers, expected) gives pairs to a for loop: the first answer with the first label, the second answer with the second label, and so on.
Your turn
main.py has four comments, and the label that a person gave to each. Do the tasks in order.
Tasks
4 to do
Task 1, not checked yet. Make a variable
PROMPTwith these instructions:Classify the comment as one of: praise, complaint, question, other. Answer with one word.Task 2, not checked yet. Write a function
classify(prompt, comment). It calls the model with two messages: a system message with the prompt, and a user message with the comment. It returns the text of the answer.Task 3, not checked yet. Make a list
answerswith the result ofclassify(PROMPT, comment)for each comment incomments. Print it.Task 4, not checked yet. Make a variable
wrongwith the number of answers that are not equal to the label inexpectedat the same position.
Task 1 of 4
Make a variable PROMPT with these instructions: Classify the comment as one of: praise, complaint, question, other. Answer with one word.