Prompting

How do you write a good prompt for GPT-3?

· By Robert Scales · 4 min read

Short answer

A good GPT-3 prompt sets up a clear pattern for the model to continue: a short description of the task, a few worked examples in a consistent format, and an open slot where the answer should go. GPT-3 only predicts what text comes next, so the prompt has to make the right continuation the most likely one.

Since OpenAI opened its API private beta in June, the developers and researchers admitted so far have been getting their first look at GPT-3, and a lesson comes quickly: the wording of the prompt matters enormously. Two prompts that look alike to a person can produce very different results. The good news is that a few habits make prompts far more reliable, and they all follow from one fact about how the model works.

GPT-3 is a language model. It was trained to predict the next piece of text, nothing more. It does not take orders the way a person does; it reads your prompt as the beginning of a document and writes what would most plausibly come next. Writing a prompt, then, is less like giving a command and more like starting a page that can only reasonably end one way.

Think "document", not "question"

Imagine where text like yours would appear on the web. A bare question such as "Best way to learn Spanish?" could be the start of a forum thread, a list of other questions, or an advertisement, and GPT-3 may continue it as any of those. If you frame it as a page where an answer clearly comes next, the model has much less room to wander.

Prompt
The following is an answer from an experienced language teacher to a student's question.

Student: What is the best way to start learning Spanish as an adult?
Teacher:

The first line says what kind of text this is. The labels "Student:" and "Teacher:" show who speaks. The empty slot after "Teacher:" tells the model exactly where to write.

Four parts of a reliable prompt

Most strong prompts contain the same building blocks:

PartWhat it doesExample
Task lineNames the job in plain words"Classify each review as positive or negative."
ExamplesShow the exact input and output formatTwo or three solved reviews
Consistent labelsMark where inputs and outputs start"Review:" and "Sentiment:"
Open slotLeaves room for one answer"Sentiment:" with nothing after it

Consistency is the quiet hero here. If one example says "Positive" and another says "pos.", the model has to guess which style you want. Use identical labels, punctuation and spacing every time.

Common problems and simple fixes

  • The model rambles on after the answer. Your format may not signal where an answer ends. Keep each example's answer short and follow it with a blank line, so the model learns that pattern.
  • The model invents things. GPT-3 writes what sounds likely, not what is checked. The GPT-3 paper notes that long outputs can drift or contradict themselves. Ask for short answers and verify facts yourself.
  • Answers swing in tone or quality. Your examples are probably mixed. Choose examples that look like the inputs you really expect.
  • It just doesn't do the task. Make the task easier to recognize: add one more example, or split a big job into two smaller prompts.

OpenAI's own announcement says success depends on how complex the task is, so start with something narrow before trying anything ambitious.

Try it: Take a prompt that gave you a poor result. Rewrite it with a task line, two consistent examples and an open slot, then compare the two outputs side by side. Note which change made the biggest difference.

Why do examples in the prompt help so much?

Examples help because they remove guesswork. A task description in words can be read several ways; an example shows exactly one. The GPT-3 paper makes this point with a simple case: asked to "make a table of world records for the 200m dash" with no example, even a person might not know which columns or format to use. One demonstration settles it.

The paper tests this directly in three settings. With zero-shot, the model gets only an instruction. With one-shot, it also sees one solved example. With few-shot, it sees several, typically 10 to 100, as many as fit in its 2,048-token window (a token is a word or part of a word). Across many tasks, accuracy rises as examples are added, and the largest model gains the most from them. None of this changes the model itself; it simply reads the examples and continues the pattern.

Here is the idea applied to a small classification job:

Prompt
Classify each review as Positive or Negative.

Review: The pages arrived bent and the cover was torn.
Sentiment: Negative

Review: My daughter has read it three times already.
Sentiment: Positive

Review: Clear explanations, but the print is far too small.
Sentiment:

The last review is mixed on purpose. Without examples, the model might write a paragraph about it. With them, it knows it should answer with a single word from a short list, and the only open question is which word.

There is a limit, of course. Examples take up space, and 2,048 tokens fill quickly. A practical rule is to start with two or three short, varied examples, measure the results on a dozen test cases, and add more only when the numbers say you need them.

Sources

  1. Language Models are Few-Shot Learners — OpenAI (arXiv), May 28, 2020
  2. OpenAI API — OpenAI, June 11, 2020

Get the free Guide to Artificial Intelligence

Sign up for the weekly newsletter and receive the free guide: what changed in AI this week, one lesson, one prompt to try. Unsubscribe in one click.

How we handle your address

Back to top

Display

Your choices are saved in this browser only. No data is sent.

Text size
100%
Colours
Reading
More settings
Accessibility statement