News and Insights
Guide to Prompt Engineering
January 18, 2024
This guide helps users of Generative AI hone their skills in prompt engineering and improve the quality and relevance of their requested outputs.
WHAT IS PROMPT ENGINEERING?
Prompt engineering is the process of writing, refining, and optimizing inputs, or “prompts”, to encourage Generative AI systems to create specific, high-quality outputs.
Prompt engineering is important because it allows users to interact with AI models using natural language, without requiring coding skills or deep knowledge of the models’ inner workings. Prompt engineering can help users leverage the full potential of AI models, by guiding them to produce more accurate, relevant, and creative results. It can also help AI engineers ‘fine-tune’ models’ behaviors and mitigate potential biases, errors, or attacks. also
Examples of prompt engineering include:
- Asking a language model a direct question (i.e., ‘who is the author of Pride and Prejudice?’)
- Giving a language model a command (i.e., ‘write a poem about leaves falling’)
- Providing a language model with a few examples (i.e., ‘casa → house, gatto → cat, cane → ?’)
- Describing a desired output to a text-to-image or text-to-audio model (i.e., ‘a high-quality photo of an astronaut riding a horse’ or ‘slow BPM electro chill with organic samples’)
To learn more about prompt engineering, visit:
- Prompt Engineering for Generative AI
- Prompt engineering
- What is prompt engineering?
- What is Prompt Engineering: The AI Revolution
- What Is Prompt Engineering? Definition and Examples
PROMPTING TECHNIQUES
Prompting techniques can vary in terms of the amount and type of information they provide, the level of difficulty they pose, and the degree of guidance they offer. Examples of prompting techniques include:
Zero-shot prompting
A prompting technique that involves providing a natural language query to a language model without any additional context or examples. The language model is expected to generate a relevant and coherent answer based on its pre-trained knowledge.
For example: Q: Who is the author of Pride and Prejudice? / A: Jane Austen
Few-shot prompting
This prompting technique involves providing a natural language query along with a few examples of input/output pairs to a language model. The language model is expected to infer the general pattern or task from the examples and apply it to the query. Followed are some examples of few-shot prompting:
- Q: Translate “Hello” to Italian / A: Ciao
- Q: Translate “Goodbye” to Italian / A: Arrivaderci
- Q: Translate “Thank you” to Italian / A: Grazie
Chain-of-thought prompting
This prompting technique involves providing a sequence of natural language queries and answers to a language model, where each query is related to the previous answer. The language model is expected to follow the chain of thought and generate a consistent and logical answer to the final query. For example:
- Q: What is the capital of Italy? / A: Rome
- Q: What is the most famous landmark in Rome? / The Colosseum
- Q: How old is the Colosseum? / A: 1,937 years old
Self-consistency generated knowledge prompting
This technique involves providing a natural language query and a partial answer to a language model. The language model is expected to complete the answer by generating additional information that is consistent with the given answer. For example:
- Q: Who was the 16th President of the United States? / A: Abraham Lincoln, who was elected in / A: 1860 and took office in November of that year.
Prompting candidates in oral assessment contexts
This prompting technique involves providing different types of prompts to human learners in oral assessment situations, such as language tests or interviews. The prompts can range from presenting the task, to repeating information, clarifying questions, and probing/leading questions. The purpose of these prompts is to elicit more (or better) responses from the learners, while maintaining the validity and reliability of the assessment.
For the purposes of illustration, let’s assume the task was to describe one’s favorite hobby, video games:
- Q: What do you like to do in your free time? / A: I like to play video games
- Q: How often do you play video games? / A: I play video games every day
- Q: Who do you play video games with? / A: I play video games with my friends or online
- Q: What are the benefits of playing video games? A: Playing video games improves my concentration, memory, and problem-solving skills
To learn more about prompting techniques, visit:
- 7 Different Prompting Techniques
- A Journey into Prompt Engineering Techniques
- Hallucination Mitigation Techniques in Large Language Models
- Prompting Candidates in Oral Assessment Contexts
IMPROVING YOUR PROMPTS
When using Generative AI tools, the key to producing high-quality outputs lies in the crafting of an effective prompt. These can help you get the most out of the tool you’re using and guide it to produce results that are more creative, accurate, and relevant.
Followed some tips and tricks, best practices, and tactics for crafting effective Generative AI prompts:
Provide context
Include details in your query to help the AI system understand your goal, audience, and domain. For example, instead of asking “Write a poem”, ask “Write a haiku about winter”.
Be specific
Use clear and concise language to instruct the AI system on what to do and how to format the output. For example, instead of asking “Write a summary”, you can ask “Write a one-sentence summary of the main idea”.
Include examples
Provide a few examples of input-output pairs to demonstrate the desired behavior and pattern for the AI system. For example, instead of asking “Translate to Italian”, you can ask “Translate to Italian: casa -> house, gatto -> cat, cane -> ?”.
Use cues
Symbols, words, or phrases can be used to indicate the start and end of the output, or to provide hints or suggestions for the AI system. For example, instead of asking “Write a product description”, you can ask “Write a product description: [Product: Midjourney, a Generative AI tool] [Description: …]”.
Share analogies
Descriptive language or comparisons help AI systems understand your desired outcome or style. For example, instead of asking “Write a catchy slogan”, you can ask “Write a catchy slogan like ‘Just do it’ or ‘I’m lovin’ it’”.
Specify length
Indicate the desired length of the output, either by using words, numbers, or symbols. For example, instead of asking “Write a short story”, you can ask “Write a short story in 500 words or less” or “Write a short story: === Begin Story === … === End Story ===”.
Experiment with different prompts
Try different ways of phrasing or formatting your prompt to see how the AI system responds. You may find that some prompts work better than others for your desired task or domain. For example, instead of asking “Write a poem about love”, you can ask “Write a sonnet about love” or “Write a love poem in the style of Shakespeare”.
Evaluate the output
Use various methods and tools to measure and assess the quality and usefulness of outputs produced by Generative AI systems. Use metrics to quantify similarities, diversity, or coherence of outputs combined with human feedback to qualitatively judge for accuracy, fluency, or creativity.
Improve the output
Use various techniques and tools to optimize and refine the output generated by the AI system. You can use methods, such as fine-tuning, reinforcement learning, or self-consistency prompting, to adjust the parameters or behavior of the AI system according to your goals or preferences. You can also use tools, such as grammar checkers, spell checkers, or plagiarism detectors, to correct or enhance the output.
Develop templates
Predefined and/or custom templates can help you structure your prompts and output. They can also help you save time, ensure consistency, and avoid errors. For example, you can use templates to generate blog posts, social media content, or emails by ‘filling in the blanks’ with natural language inputs or data.
Use keywords
Keywords or phrases to guide the AI system to generate outputs that match your desired topic, genre, or style. Keywords can help you narrow down the scope, increase the relevance, and add some creativity to the output. For example, you can use keywords to generate stories, songs, or jokes by specifying the theme, mood, or genre.
Apply constraints
Constraints are rules that limit or regulate the output generated by an AI system. Constraints can help you avoid unwanted or inappropriate outputs, such as plagiarism, profanity, or misinformation. For example, you can use constraints to generate facts, trivia, or quizzes by specifying the source, difficulty, or format.