Skip to Content

PART 4: The art of prompt crafting – context window and prompting techniques

Jeroen Egelmeers
Feb 12, 2024

In the first three blogs, we walked through an introduction to Prompt Engineering, the Crafting AI Prompts Framework, and interactive prompting/custom acting roles. In this blog, we’ll dive into “context windows” and prompt engineering techniques, which can highly impact your prompts.

Context Window

The term “context window” refers to the “current memory” of a language model like GPT, indicating how much of our ongoing conversation it can remember. It represents the volume of text that the model can use when formulating responses. Essentially, it’s the working memory of the model, crucial for keeping the dialogue or text generation coherent and relevant to the context. In other words, the context window measures the amount of information a language model can access and consider for its response. A token, which is the smallest unit of text the model processes, could be a word or punctuation mark. Therefore, it’s important to always check the context window of the model you’re using to ensure you don’t exceed it at any steps of your prompting. This context window encompasses both your input and the model’s generated output.

Prompt engineering techniques

Even though prompt engineering might sound like something super new there are already lots of techniques that can be used to enhance your output. In this blog, I want to dive deeper into one special prompt engineering technique: “Shot prompting”.

And to be complete: understanding the nuances of Zero, Single, and Few-Shot Prompting is crucial for effective communication. These concepts, central to the way we interact with AI models, define how much task-specific information is provided to the model for generating responses.

Zero-Shot prompting: The basics

Zero-shot prompting is when the AI model makes predictions or performs tasks without any prior specific examples or context related to the task. It relies entirely on its pre-existing training and knowledge. In this approach, the user presents a query or task directly, and the AI, based on its training, attempts to respond appropriately. Zero-shot prompting is akin to asking a knowledgeable friend a question without giving them any context or background information.

Example: Asking ChatGPT, “Explain the theory of relativity,” without providing any context or specific angle for explanation.

Single-shot prompting: A step further

Single-shot prompting takes it a notch higher by providing the AI with a limited amount of task-specific information or a single example. This single example serves as a guide, helping the model understand the task’s context or the response’s desired format. Single-shot prompting is like giving a brief hint or clue before asking the question, guiding the AI in the right direction.

Example: Providing ChatGPT with a specific problem statement and asking for a solution, like “Write a complaint letter about a recent online shopping experience where the product arrived damaged.”

Few-shot prompting: Enhanced contextualization

Few-shot prompting involves giving the AI model a small number of examples or pieces of context. Unlike single-shot, which uses one example, few-shot provides several, helping the model better understand and generalize the task. This method is particularly useful when dealing with more complex tasks where a single example might not be enough to convey the full scope.

Example: Asking ChatGPT to generate marketing slogans, and providing it with three or four different examples of slogans that align with the desired tone and style.

Importance in AI communication

Understanding these prompting techniques is essential for several reasons:

  1. Efficiency: Zero-shot prompting is quick and straightforward but may not always yield the most accurate or tailored responses. Single and few-shot prompting, while requiring more input, can produce more precise and relevant results.
  2. Customization: Single and few-shot prompting enable customization of the model’s behavior for specific tasks, allowing for more tailored AI assistance.
  3. Data availability: Depending on the availability of specific examples or context, users can choose the most suitable prompting approach to get the best results from their AI interactions.

Conclusion

The context window is essential to understand to make sure you keep within the “memory” of the model and thus get the best output. Zero, Single, and Few-shot prompting are key methodologies in the realm of prompt engineering, determining how models like ChatGPT interpret and respond to user inputs. Each method has its place, with zero-shot being suitable for general inquiries and creativity, single-shot for tasks requiring a bit of guidance, and few-shot for complex tasks needing multiple examples. By mastering these techniques, users can significantly enhance their interaction with GenAI, ensuring more accurate, relevant, and efficient responses tailored to their specific needs and contexts.

Featured Photo by Growtika on Unsplash

About the author

Prompt Engineering Advocate & Trainer | Netherlands
Jeroen Egelmeers is a Prompt Engineering Advocate at Sogeti Netherlands. Jeroen also serves as a Software Engineer Trainer. 

Leave a Reply

Your email address will not be published. Required fields are marked *

Slide to submit