How to write a few-shot prompt

Ready to get a little more advanced? Here's how to level up your GPT-3 prompt craft with few-shot learning.

Previously, on Writehacks:

If your GPT-3 prompts mainly go like this: Β Write an X about Y , you've been playing in the zero-shot sandbox.

Zero-shot learning means the prompt only describes the final output you want the AI to write. It's quick and easy, but it tends to produce generic and uninspiring answers.

And that's because you're basically telling the AI to take a wild stab in the dark.

To start getting more detailed or specific stuff right from the first generation, you'll want to upgrade your prompts with few-shot learning.

Few-shot means your prompt is expanded to also contain several examples of the kind of output you're looking for.

It's the AI equivalent of going from first principles to thinking by analogy. Us fleshy humans are basically the same. It's much easier to come up with a tagline for a running shoe when you know Nike's "Just do it" is out there.

So let's give writing a few-shot prompt a go. Here are the steps:

1. Add your prompt

  • Log in to OpenAI’s Playground.
  • For this exercise, let's make GPT-3 come up with a company tagline in the same ballpark as other well-known business taglines.
  • Copy and paste the following prompt text in your Playground Editor πŸ‘‡
You're GPT-3, the world's best AI-powered copywriter and brand strategist. Write an inspiring tagline for a company that [insert what the company does here], based on the examples provided below.

Example: Organize the world's information and make it universally accessible.
Example: Build an economy in which everyone wins.
Example: Empower anyone to design anything.
Example: Think Different.
Example: Grow the GDP of the Internet.
Example: Build trust in society and solve its most complex problems.
Example: The Spirit of Australia.
Example: THINK.

(Bonus points if you can identify the company behind each tagline)

2. Tweak the settings

  • Swap out the [insert what the company does here] with a few words about what your fictional (or real!) company does.
  • It could be anything: manufacturing sausage casings, selling propane and propane accessories, being a mid-sized paper sales firm located in Scranton, whatever.
  • Once you've described your fledgling company, look to the righthand panel. Move the Temperature from 0.7 to 0.85-1. This will make the results more random (and, arguably, creative).
  • You should also reduce the maximum length from 256 to 60-80 or so, to keep things punchy.
  • We're ready to generate! Smash that Submit button.
  • Et voila! GPT-3 should've generated you a short, snappy tagline next to the 'Tagline:' part of the prompt.

3. Refining and iterating

  • As with all things GPT-3, the quality of the first outputs may be iffy (though I've noticed it has a high amount of 'Beginners luck'). So if you want it to have another go, select πŸ”„ Regenerate.
  • Continue Regenerating until it spits out something usable.
  • If it becomes obsessed with one particular output, it can help to add it the other examples in the prompt to shut it up. To do this, just rename 'Tagline:' to 'Example', then add another 'Tagline:' below it (this should also remove the green highlighting to show it's no longer AI-generated). You can then Submit again.
  • If nothing good comes up, try lowering or raising the Temperature, or feeding it different examples to train on using the method above.
  • Eventually, hopefully, something kinda cool will get spun out that you wouldn't have thought of otherwise. That will make it official: you're now a bona fide AI writer of the few-shot learning persuasion. Yay! πŸš€