Today I Learned
Day 26 - Prompting Techniques - System Prompting
System, contextual, and role prompting
System, contextual and role prompting are all techniques used to guide how LLMs generate text, but they focus on different aspects:
- System prompting sets the overall context and purpose for the language model. It defines the ‘big picture’ of what the model should be doing, like translating a language, classifying a review etc.
- Contextual prompting provides specific details or background information relevant to the current conversation or task. It helps the model to understand the nuances of what’s being asked and tailor the response accordingly.
- Role prompting assigns a specific character or identity for the language model to adopt. This helps the model generate responses that are consistent with the assigned role and its associated knowledge and behavior.
However, each type of prompt serves a slightly different primary purpose:
- System prompt: Defines the model’s fundamental capabilities and overarching purpose.
- Contextual prompt: Provides immediate, task-specific information to guide the response. It’s highly specific to the current task or input, which is dynamic.
- Role prompt: Frames the model’s output style and voice. It adds a layer of specificity and personality.
Example of System Prompting
- Goal: Classify movie reviews as positive, neutral, or negative.
- Model: gemini-pro
- Temperature: 1
- Token Limit: 5
- Top-K: 40
- Top-P: 0.8
- Prompt:
Classify movie reviews as positive, neutral or negative. Only
return the label in uppercase.
Review: "Her" is a disturbing study revealing the direction
humanity is headed if AI is allowed to keep evolving,
unchecked. It's so disturbing I couldn't watch it.
Sentiment:- Output: NEGATIVE
The name ‘system prompt’ actually stands for ‘providing an additional task to the system’. For example, you could use a system prompt to generate a code snippet that is compatible with a specific programming language, or you could use a system prompt to return a certain structure.
- Goal: Classify movie reviews as positive, neutral, or negative, return JSON
- Model: gemini-pro
- Temperature: 1
- Token Limit: 1024
- Top-K: 40
- Top-P: 0.8
- Prompt:
Classify movie reviews as positive, neutral or negative. Return
valid JSON:
Review: "Her" is a disturbing study revealing the direction
humanity is headed if AI is allowed to keep evolving,
unchecked. It's so disturbing I couldn't watch it.
Schema:
MOVIE:
{
"sentiment": String "POSITIVE" | "NEGATIVE" | "NEUTRAL",
"name": String
}
MOVIE REVIEWS:
{
"movie_reviews": [MOVIE]
}
JSON Response:- Output:
{
"movie_reviews": [
{
"sentiment": "NEGATIVE",
"name": "Her"
}
]
}TIPS
System prompts can also be really useful for safety and toxicity. To control the output, simply add an additional line to your prompt like: ‘You should be respectful in your answer.’.