Prompts for large language models can include various parts to guide the model towards the desired outcome. Here’s a breakdown of these parts:
1. Input (Required)
The core element of a prompt, telling the model what to do. A standalone text prompt, lacking additional information. It can be:
- Question Input: Asks the model something, requiring an answer.
What are the healthiest snacks for kids?
- Task Input: Instructs the model to perform a specific action.
Create a short poem about a cat.
- Entity Input: Provides data for the model to analyze or manipulate like summarize or classify.
Summarize the key points of this article (link to article).
- Completion Input: Offers text for the model to finish or extend.
There once was a programmer named Sue...
Gemini
Whose code was a bit askew. She'd debug all night, With logic's sharp light, And find the fix by the morning dew.
The previous section demonstrated open-ended prompts, where the LLM had freedom to select relevant information from its training data. However, we can provide optional context data to guide LLM toward providing better results, like the following example:
“A dog is a domesticated mammal that has been selectively bred for millennia for various breeds and purposes. It is often called man’s best friend and is known for its loyalty, intelligence, and trainability. Dogs vary greatly in size, coat type, and temperament, but they all share some common traits, such as a wagging tail as a sign of happiness and the ability to understand human emotions.” – Summarize This This passage describes dogs, domesticated animals known for their loyalty, intelligence, and trainability. They come in various sizes and coat types, but share some common traits like wagging tails to express happiness and an ability to understand human emotions. The optional context data consists of:
- Context
- Examples
- Cues
- Templates
2. Context (Optional)
Additional information that clarifies the prompt and guides the model’s response, Instruction prompts allow us to be more specific in our requests, leading to better results. Here’s an example:
- Instructions: Specify the desired behavior of the model.
Write a formal email requesting a meeting
- Information: Provides relevant details to assist the model.
You are a travel agent. The customer wants to book a trip to Hawaii in December
The impact of context is evident in the following example:
Prompt without context: “Write a poem about a flower.”
Model response (generic): “A flower blooms, so bright and bold, its petals soft, a story told.”
Prompt with context: “Write a poem about a rose, capturing its beauty and symbolism of love.”
Model response (specific): “The velvet rose, a crimson flame, whispers tales of love and fame. Its petals soft, a fragrant sigh, a symbol true, ’til lovers die.”
By incorporating context into your prompts, you can significantly improve the quality and relevance of responses generated by large language models.
Prompt (Input) Prompt Type Write a short biography of Leonardo da Vinci. A standalone text prompt Write a detailed biography of Leonardo da Vinci. Include key dates and achievements in his various fields of work Prompt with instructions Write a concise biography of Leonardo da Vinci in 1 paragraph. Provide 3 bullet points with key achievements and their fields. Provide 3 more bullet points with examples of his famous works Prompt with instructions and informations 3. Examples (Optional)
This approach lets you “show, don’t tell” the model the desired output format by providing examples. Based on the number of examples given, we have different prompting types:
- Zero-shot: Provides a single example without explicit instructions (e.g., “The Sun is Shining” paired with its Spanish translation).
- One-shot: Offers an example with explicit instructions, then a new example without them (e.g., “The Sun is Shining” translated to Spanish, followed by “It’s a Cold and Windy Day” without explicit translation).
- Few-shot: Presents multiple examples from different domains, allowing the model to infer the pattern (e.g., showing examples of sports actions paired with their respective sport names).
Explicit instructions for the task become unnecessary with more examples.
In zero-shot, we need to explicitly say “Translate to Spanish,” but in few-shot, the pattern is clear from seeing different sports actions and their corresponding sports. With more examples, models can make better inferences without requiring additional guidance.
- Input-Output Pairs: Showcase desired format and content of responses.
Translate the following sentence into Spanish: 'Hello, how are you?
Output
Hola, ¿cómo estás?
- Input-Output Pairs Example (ChatGPT Model)
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "What is the capital of France?" }, { "role": "system", "content": "The capital of France is Paris." }, { "role": "user", "content": "What language is spoken there?" }, { "role": "system", "content": "The primary language spoken in Paris is French." } ]
Finding the Sweet Spot:
The optimal number of examples depends on the specific model and task. Large models like PaLM and Gemini can often grasp patterns with few examples, whereas simpler models like BERT might require more. Experimenting with different numbers is crucial to achieve the desired results.
4. Cues (Optional)
Prompt with a Starting Point: Instead of providing full examples, offer a brief snippet that sets the tone and format for the desired response. This “kickstarts” the model towards the right direction.
Number of CuesPrompt (Input)Completion (Output)0“A dog is a domesticated mammal that has been selectively bred for millennia for various breeds and purposes. It is often called man’s best friend and is known for its loyalty, intelligence, and trainability. Dogs vary greatly in size, coat type, and temperament, but they all share some common traits, such as a wagging tail as a sign of happiness and the ability to understand human emotions.” – Summarize ThisThis passage describes dogs, domesticated animals known for their loyalty, intelligence, and trainability. They come in various sizes and coat types, but share some common traits like wagging tails to express happiness and an ability to understand human emotions.1“The Great Wall of China is a series of fortifications made of stone, brick, wood, and earth. It is one of the most famous landmarks in the world and is considered one of the wonders of the ancient world. The wall’s construction began in the 7th century BC and continued over a period of 2,000 years. The Great Wall was built to protect the Chinese Empire from invaders from the north.” – Summarize This – What we learned is thatThe Great Wall of China, a renowned landmark and ancient wonder, is a series of fortifications built over 2,000 years. Constructed from various materials like stone and wood, it served to protect the Chinese Empire from northern invaders.2“The internet is a global network of interconnected computer networks. It allows people to communicate with each other from all over the world, share information, and access a wide range of resources. The internet has revolutionized the way we live, work, and learn.” – Summarize This – Top 3 Facts We Learned:This text explains the internet, a global network connecting computers worldwide. It enables communication, information sharing, and access to diverse resources, fundamentally transforming how we live, work, and learn. Top 3 Facts We Learned: 1. The internet connects computers globally. 2. It allows communication, information sharing, and resource access. 3. It has significantly impacted our lives, work, and learning. - Beyond Task and Content: Shaping Outputs with Contextual Cues
While crafting prompts, we typically focus on the task description (what to do) and the target content (what to do it with). However, we can add another layer – contextual cues. These cues act as additional information that can influence the model’s response and tailor it to specific user objectives or expectations.
Imagine contextual cues as providing further guidance:
- Tuning parameters: Adjusting settings to control aspects like output length or style.
- Formatting instructions: Specifying the desired presentation format (e.g., bulleted list, table).
- Topic taxonomies: Defining relevant categories (like tags) to guide the model in prioritizing specific aspects of the target content.
Example: Consider a university course catalog with detailed information for each course (name, description, level, tags, instructor, etc.). Here’s how contextual cues can be used:
Task Description: “Summarize the Fall 2023 course catalog.” Target Content: Provide examples of the desired output format. Contextual Cues: Specify the top 5 “tags” of interest.
The model can now generate a summary following the example format. If a course has multiple tags, it can prioritize the 5 specified in the contextual cues, ensuring the summary aligns with your preferences.
This approach allows for more nuanced and user-centric outputs by leveraging additional context beyond the core task and target content.
- Templates – these are repeatable ‘recipes’ for prompts with placeholders (variables) that can be customized with data for specific use cases.
5. Templates (Optional)
Imagine prompts as recipes for guiding large language models (LLMs) to generate the desired output. These “recipes” are called templates, and they include special ingredients:
- Placeholders: These are variable blanks marked with symbols like
{}
or[]
that act as slots for you to fill with specific data. - Instructions: Like the steps in a recipe, these guide the LLM on how to use the provided data and complete the task.
Benefits:
- Efficiency: Reuse existing templates for similar tasks, saving time and effort.
- Consistency: Ensure prompts are structured consistently, leading to predictable and reliable results.
- Clarity: Communicate your instructions to the LLM clearly, leading to more accurate outcomes.
Example:
Template: “Write a news article summarizing the following key points: {point 1}, {point 2}, {point 3}.”
Data:
- point 1: “A new study finds that regular exercise can improve cognitive function in older adults.”
- point 2: “The study involved participants aged 65 and over who engaged in moderate-intensity exercise for six months.”
- point 3: “The findings suggest that exercise may help to delay age-related cognitive decline.”
Generated Output:
A new study has shown that regular exercise can significantly improve cognitive function in older adults. Researchers conducted a study with participants aged 65 and over who engaged in moderate-intensity exercise for a period of six months. The study's findings suggest that regular exercise may help to delay the onset of age-related cognitive decline, potentially offering a valuable tool for maintaining overall cognitive health in later life.
By utilizing templates, you can become a master chef in the world of prompts, crafting clear and consistent instructions to guide LLMs and achieve your desired outcomes effectively.
References