Advanced Prompt Design for GPT-3: How to make a prompt 20x more efficient

TL;DR: GPT-3 is much more capable than people realize when you utilize advanced prompt design that shows it what you want performed in a task then show it how to perform this task with a list of inputs.

One of my favorite prompts in our OpenAI documentation is an example showing how to get GPT-3 to perform a task on a list of items. I want to expand on that because I don’t think enough developers are really paying attention to the implications of it.

GPT-3 can perform a wide variety of tasks like classification, summarization and chat from a simple prompt (the text we send to GPT-3.) However, simple prompts only hint at what GPT-3 is actually capable of doing. 

GPT-3 has a number of capabilities: 

  • Understanding language
  • Knowledge about the world
  • Knowing how to do things 
  • Following instructions

Most prompts only focus on one of those capabilities. If you combine one task with another GPT-3 can be used to do more things and do them more efficiently.

If I wanted to have GPT-3 classify text sentiment with an emoji, a simple prompt would look like this: I’d give the model a few examples of the text to classify and how to classify it and then provide it with an incomplete example for GPT-3 to finish by following the previous pattern.

Text: This is great!
Emoji: 🤗
Text: So I went out with my friends.
Emoji: 👯
Text: In the end, I just shrugged it off.
Emoji:

GPT-3 is able to read the text and complete it with an appropriate emoji:

Emoji: 🤷‍♀️

In a real-time application a developer might use a prompt like this to perform the task because they only need to classify one sentence at a time, but in other applications where you’re trying process large amounts of text or have the ability to group them in batches, there’s a much more efficient way to perform this task.

As I mentioned before, one of GPT-3’s capabilities is its ability to follow instructions (OpenAI even has a version of GPT-3 that is even more focused on this.) If you tell it to make a list, it can make a list. If you tell it to read instructions, it will read instructions. As long as GPT-3 clearly understands what’s a task and what’s content, it can switch back and forth between these capabilities.

Keeping this in mind, we can make a more complex prompt that can process multiple user inputs by clearly teaching GPT-3 how to perform a task, the content to perform it on and what to do.

We start by first showing GPT-3 what we want done. In this case it’s converting text to emoji. We can use our previous example for this. I’ll also throw in a title to help prime it for the task:

Text to Emoji

Text: This is great!
Emoji: 🤗
Text: So I went out with my friends.
Emoji: 👯
Text: In the end, I just shrugged it off.
Emoji: 🤷‍♀️

Next we’ll add a separator, write the word “Text” and give GPT-3 a list of numbered sentences followed by the word “Emoji” and the number 1 to start a list.

Text to Emoji

Text: This is great!
Emoji: 🤗
Text: So I went out with my friends.
Emoji: 👯
Text: In the end, I just shrugged it off.
Emoji: 🤷‍♀️

###

Text:

1. "I loved Godzilla vs. Kong!"
2. "My old laptop is too slow"
3. "Breakfast was okay"
4. "That YouTube video blew my mind"
5. "I can’t wait for dessert"
6. "My cat wants socks for Christmas"
7. "Do you want ice cream?"
8. "I spent to much money at the mall"
9. "It's raining."
10. "Let's go to the beach tomorrow"

Emoji:
1.

When we ask for a completion, GPT-3 is able to understand the task from the previous example and then apply it to our list of sentences:

Emoji:
1. 🤗
2. 😭
3. 😐
4. 😱
5. 😋
6. 😕
7. 🍦
8. 💸
9. 🌧
10. 🌊

As you can see, GPT-3 was able to apply what it learned from the first example to a list of ten sentences without the need to provide extra descriptive text or make multiple API calls. In this example we only had it create ten responses, but it’s capable of doing many more.

Let’s break this down: We taught it how to perform a task using a descriptive method of defining what was input (the text) and what was the goal (an emoji) and then showed it how to apply it to a list so we didn’t have to keep sending the prompt to API for every item.

When you need to process large batches of data, this approach can help do that more efficiently. I’ve tested it with key points extractions, word tagging and summarization, among other tasks.

Cover photo by Rodolfo Clix from Pexels