Zero-Shot, One-Shot, and Few-Shot Prompting

Learn how to implement zero-shot, one-shot, and few-shot prompts.

N-shot prompting is a technique for guiding the response of a large language model (LLM) by providing it with additional examples.

Zero-shot prompting

This is a technique where the user provides no examples or context to the LLM. This can be useful when the user wants a quick answer without providing additional detail, or when the topic is so general that examples would artificially limit the response.

Let's look at some examples where we use zero-shot prompting:

  • "Write a poem about love."

  • "Generate a list of 10 possible names for my new dog."

  • "Create a marketing campaign for a new product."

One-shot prompting

This is a technique where the user provides a single example or piece of context to the LLM. This can guide the LLM's response and ensure it aligns with the user's intent.

Let's look at some examples where we use one-shot prompting:

  • "Write a poem about love. Here is an example of a love poem: 'Sonnet 116' by William Shakespeare."

  • "Generate a list of 10 possible names for my new dog. Here is an example of a dog name I like: Banana."

  • "Create a marketing campaign for a new product. Here is an example of a marketing campaign for a new product: The "I'm Lovin' It" campaign for McDonald's."

Few-shot prompting

This is a technique where the user provides a few examples or pieces of context to the LLM. This can provide even more guidance to the model and ensure that it generates a response that is very close to what the user wants.

Let's look at some examples where we use few-shot prompting:

  • "Write a poem about love. Here are some examples of love poems: 'Sonnet 116' by William Shakespeare, 'The Road Not Taken' by Robert Frost, and 'I Carry Your Heart with Me' by E.E. Cummings."

  • "Generate a list of 10 possible names for my new dog. Here are some examples of dog names I like: Banana, Kiwi, Pineapple, and Coconut."

  • "Create a marketing campaign for a new product. Here are some examples of marketing campaigns for new products: The "I'm Lovin' It" campaign for McDonald's, the "Just Do It" campaign for Nike, and the "Think Different" campaign for Apple."

Why does it matter?

The choice between zero-shot, one-shot, and few-shot prompting hinges on the specificity of the task and the desired accuracy:

  • Flexibility vs. predictability: Zero-shot offers the most flexibility but can sometimes be unpredictable, while one-shot and few-shot generally provide more predictable and tailored outputs.

  • Training data limitations: For very niche or specialized tasks, few-shot prompting might be more beneficial as the model gets more context to understand the task better.

  • Cost of errors: In situations where the cost of a mistake is high, one-shot or few-shot prompting may be preferable. These approaches, by offering concrete examples or more detailed context, can reduce the likelihood of errors that might occur with zero-shot prompting.

  • User experience: From a user's perspective, the type of prompting can greatly influence the ease of interaction. Zero-shot prompting requires no prior examples, which can be more user-friendly for those unfamiliar with how to structure prompts effectively. Conversely, few-shot prompting might require more effort from the user but can lead to more satisfying and precise outcomes.

Here are some additional things to keep in mind when using these techniques:

  • The more examples or context that the user provides, the better the response that ChatGPT will generate.

  • The examples or context that the user provides should be relevant to the task that they are trying to accomplish.

  • The examples or context should be clear and concise.

  • The user should be patient. It may take some time for ChatGPT to learn how to generate the desired response.

Try it out

Ask ChatGPT to perform an action or to help with something. First provide no examples. Then, provide one example or more to help the model understand what you want. You can try on the ChatGPT simulator or directly on the main site.

Note: This app uses the GPT 3.5 model. If you want to try a different model, visit chat.openai.com.

Get hands-on with 1200+ tech skills courses.