Shot Prompting

Shot Prompting

Few Shot and Zero Shot Prompting

Few-Shot Prompting

‘Few-Shot Prompting’ is a concept in the field of artificial intelligence (AI), specifically in the domain of generative AI models. It refers to the ability of these models to generate coherent and contextually relevant outputs based on just a few examples or prompts provided by a user.

In the context of generative AI models, prompts are specific instructions or input examples that guide the system in generating desired outputs. Rather than relying solely on the initial prompt, few-shot prompting allows users to iteratively refine or specify the desired output by modifying or extending the prompt. By carefully crafting or manipulating prompts, users can guide the model towards generating outputs that meet their specific requirements.

The following example demonstrates a few-shot learning approach in prompt engineering, where the model is provided with a couple of examples to understand the desired task and format. Instead of explicitly stating the task, the LLM is given a context in which it should operate.

  • Contextual Setup: The “Child” and “Grandparent” dialog sets up a context. The model is implicitly being taught that it should generate responses in the style of a wise grandparent answering a child’s questions.

  • Example Provided: The first complete interaction (about patience) serves as a shot or example, guiding the model on how it should structure its response.

  • Task Indication: The second interaction (about unity) is incomplete, indicating the task the model needs to perform. The goal is to get the model to continue the pattern and provide a similarly styled, profound answer to the child’s new question.

The model’s generated completion is then printed, providing insight into its understanding and continuation of the provided examples.

In summary, by using a few-shot learning approach, the model is guided to understand and emulate the style of the conversation without explicitly being told the exact format or context. This method leverages the model’s ability to generalize from a few examples and produce consistent and contextually relevant outputs.

Model Selection

Make sure to select the desired model before running each prompt. This is required for each new prompt.

Note: Missing this step will lead to error:


Try it out!

Copy the following text into the prompt editor and click Run.

Code Snippet
123456789101112
Your task is to answer in a consistent style. Child: Teach me about patience. Grandparent: The river that carves the deepest valley flows from a modest spring; the grandest symphony originates from a single note; the most intricate tapestry begins with a solitary thread. Child: Teach me about unity. Grandparent:

The key advantage of few-shot prompting is that it allows users to achieve more control over the generative AI model’s output without requiring extensive retraining. With just a few iterations of modifying the prompts, users can shape the model’s responses according to their requirements, making it a versatile and useful tool in various applications such as content generation, chatbots, creative writing, and more.

Zero-Shot Prompting

Zero-shot prompting is a concept that enables a model to provide responses or generate text about topics it has not been explicitly trained on. Unlike few-shot prompting where models are fine-tuned or explicitly trained on specific prompts to generate relevant responses, with zero-shot prompting models can generalize their knowledge and reasoning abilities to novel prompts without explicit training.

For instance, in a conversational AI context, a zero-shot capable model can respond to prompts or questions about topics it hasn’t been trained on. If the AI has been trained on various topics like science, history, or literature, it can generate plausible responses without specific training for each topic.

Zero-shot prompting relies on the representation learning capabilities of AI models to understand the patterns and relationships within data. These models can encode the knowledge they have acquired during training and utilize it to generate contextually relevant responses.

The following example showcases an advanced application of prompt engineering that encapsulates a multi-step task for the LLM.

  • Role Emulation: The initial statement sets the stage by instructing the LLM to assume the role of a customer service AI assistant. This prepares the model to respond in a specific, customer-service oriented manner.

  • Multi-step Instruction: The prompt is divided into two distinct steps, each guiding the model to perform a specific action:

    • Step 1: Sentiment Analysis - The model is directed to discern the sentiment of a provided customer review. This sentiment could be positive, negative, or neutral.

    • Step 2: Contextual Reply - Based on the extracted sentiment, the model must generate an appropriate email reply. The instructions are clear:

      • Positive or Neutral Sentiment: Express gratitude.
      • Negative Sentiment: Offer an apology and provide an avenue for further assistance. The model is also guided to incorporate details from the review to ensure the response feels tailored and specific to the customer’s concerns.
  • Tone and Format: The instructions emphasize writing in a concise and professional tone. Moreover, the model is guided to sign off the email as “AI customer agent”, reinforcing the context and ensuring the generated response follows a proper email format.

  • Multi-step Continuation: This prompt is an excellent example of multi-step continuation. The LLM first determines the sentiment of the review and then uses that sentiment to guide its next action, which is generating a contextually appropriate email reply.

In summary, from a prompt engineering standpoint, this example effectively leverages a structured, multi-step instruction set to guide the LLM through a complex task. The clarity and specificity of the instructions, combined with the defined role and context, aim to elicit a precise and contextually relevant response from the model.

Copy the following text into the prompt editor and click Run.

Code Snippet
123456789101112
You are a customer service AI assistant. Given the customer email, perform the following steps: Step 1: Extract the sentiment of the customer review as positive, negative and neutral. Step 2: Now, Your task is to send an email reply to a valued customer. Generate a reply to thank the customer for their review. If the sentiment is positive or neutral, thank them for their review. If the sentiment is negative, apologize and suggest that they can reach out to customer service. Make sure to use specific details from the review. Write in a concise and professional tone. Sign the email as 'AI customer agent'. Customer review: So, they still had the 17 piece system on seasonal sale for around $49 in the month of November, about half off, but for some reason (call it price gouging) around the second week of December the prices all went up to about anywhere from between $70-$89 for the same system. And the 11 piece system went up around $10 or so in price also from the earlier sale price of $29. So it looks okay, but if you look at the base, the part where the blade locks into place doesn't look as good as in previous editions from a few years ago, but I plan to be very gentle with it (example, I crush very hard items like beans, ice, rice, etc. in the blender first then pulverize them in the serving size I want in the blender then switch to the whipping blade for a finer flour, and use the cross cutting blade first when making smoothies, then use the flat blade if I need them finer/less pulpy). Special tip when making smoothies, finely cut and freeze the fruits and vegetables (if using spinach-lightly stew soften the spinach then freeze until ready for use-and if making sorbet, use a small to medium sized food processor) that you plan to use that way you can avoid adding so much ice if at all-when making your smoothie. After about a year, the motor was making a funny noise. I called customer service, but the warranty expired already, so I had to buy another one. FYI: The overall quality has gone done in these types of products, so they are kind of counting on brand recognition and consumer loyalty to maintain sales. Got it in about two days.

In summary, zero-shot prompting enables AI models to generalize their knowledge and reasoning abilities beyond the explicitly-trained data, empowering them to respond to prompts or generate text about topics they haven’t been trained on.

Log in to track your progress & complete quizzes