Prompt Engineering
Sudalai Rajkumar @ SRK
Agenda
● Large Language Models (LLMs)
● What is Prompt Engineering?
● Types of Prompting
● Use Cases
● Prompting Techniques
● LLM Model Parameters
● Injections, Limitations & References
What is your favorite programming language?
What is your favorite programming language?
Large Language Models
Evolution of Language Models
Courtesy : Analytics Vidhya
Large Language Models
Language models (mostly transformer architecture based ones) trained on vast amount
of text data to generate human-like text
The Illustrated Transformers by Jay Alammar Courtesy : Cohere
Large Language Models - Comparison
Courtesy : Deus.ai
Coming next - GPT4 :)
Courtesy : Twitter
What is Prompt Engineering?
What is Prompt Engineering?
Prompt engineering is a NLP concept that involves discovering inputs that yield
desirable or useful results
Credits: Cohere
What is Prompt Engineering?
Prompt engineering is a NLP concept that involves discovering inputs that yield
desirable or useful results
(or)
How to talk to AI to get it to do what you want
What is Prompt Engineering?
Credits: humanloop
What is Prompt Engineering?
Credits: humanloop
What is Prompt Engineering?
● Prompt is at the heart of working with LLMs
● Prompts can be simple text to very complex instructions
● Coming up with good prompt is a combination of art and science
What is Prompt Engineering?
● Prompt is at the heart of working with LLMs
● Prompts can be simple text to very complex instructions
● Coming up with good prompt is a combination of art and science
Types of Prompting
Prompting by Instruction
Credits: cohere
Prompting by Instruction
Prompting by Example
Credits: cohere
Prompting by Example
Use Cases
Use Case - Text Generation
Use Case - Text Classification
Use Case - Language Translation
Use Case - Question Answering
Use Case - Text Summarization
Use Case - Image Generation
Models / Tools
● Dall-E
● Midjourney
● Stable Diffusion
Use Case - Image Generation
Prompting Techniques
Prompting Technique - Length Control
● We can specify a desired word count or character count as part of the
prompt
Prompting Technique - Length Control
● We can specify a desired word count or character count as part of the
prompt
Prompting Technique - Tone Control
● To control the tone of the generated text, the prompt can use specific words or
phrases that indicate the desired tone
Prompting Technique - Tone Control
● To control the tone of the generated text, the prompt can use specific words or
phrases that indicate the desired tone
Prompting Technique - Style Control
● To control the style of the generated text, the prompt can specify the desired
writing style.
Prompting Technique - Style Control
Prompting Technique - Audience Control
● To control the target audience of the generated text, the prompt can specify
the desired audience.
Prompting Technique - Audience Control
● To control the target audience of the generated text, the prompt can specify
the desired audience.
Prompting Technique - Context Control
● To control the context of the generated text, the prompt can provide specific
information about the context
Prompting Technique - Context Control
● To control the context of the generated text, the prompt can provide specific
information about the context
Prompting Technique - Keyword Based Guiding
● To guide the model towards specific outputs, the prompt can include
keywords that are relevant to the desired output
Prompting Technique - Keyword Based Guiding
● To guide the model towards specific outputs, the prompt can include
keywords that are relevant to the desired output
Prompting Technique - Keyword Based Guiding
● To guide the model towards specific outputs, the prompt can include
keywords that are relevant to the desired output
Prompting Technique - Scenario based guiding
● The prompt can describe a specific scenario to guide the model towards
generating text that fits that scenario.
Prompting Technique - Scenario based guiding
● The prompt can describe a specific scenario to guide the model towards
generating text that fits that scenario.
Prompting Technique - Scenario based guiding
● The prompt can describe a specific scenario to guide the model towards
generating text that fits that scenario.
Prompting Technique - Avoiding Unwanted Outputs
● Blacklisting words:
○ Ex - Write a summary about banks but avoid using the word loans
● Topic Constraints:
○ Ex - Write a review on iphone without covering the price aspect
● Output type constraints:
○ Ex - Write a poem about nature but avoid using rhyming words
Chain of Thought Prompting
● This prompting technique provides a “chain of thought” process that
showcases how the correct answer to a question should be reached
Chain of Thought Prompting
● This prompting technique provides a “chain of thought” process that
showcases how the correct answer to a question should be reached
Chain of Thought Prompting
LLM Model Parameters
LLM Model Parameters to Control
● Stopping criteria
○ Number of tokens - maximum number of tokens to generate
○ Stop sequences - character or the sequence used to separate the
training examples
● Repetition Reduction
○ Frequency penalty - penalizes based on the frequency of the word in the
preceding text
○ Presence penalty - penalizes based on the presence of the word
LLM Model Parameters to Control
● Next Token Prediction
○ Temperature - High temperature is very creative and vice versa
○ Top-k - Top K tokens to choose the next word from
○ Top-p - Top probability of tokens to choose the next word from
Credits: cohere
Prompt Injections &
Limitations
Prompt Injections
● Similar to SQL Injections
● Prompting to trick the LLMs to do something undesirable
Prompt Injections
● Similar to SQL Injections
● Prompting to trick the LLM to do something undesirable
Prompt Engineering - Limitations
● Size of the language models
○ GPT index - https://github.com/jerryjliu/gpt_index
○ A set of data structures designed to make it easier to use large external
knowledge bases with LLMs
● Memory & sequence of calls
○ LangChain - https://github.com/hwchase17/langchain
● Correctness of the output
References:
● Dair.ai - https://github.com/dair-ai/Prompt-Engineering-Guide
● Cohere - https://txt.cohere.ai/generative-ai-part-1/
● ChatGPT - https://chat.openai.com/
● GPT3 - https://platform.openai.com/login/
● Humanloop - https://humanloop.com/blog/prompt-engineering-101
● Twitter - https://twitter.com/goodside
● Promptify - https://github.com/promptslab/Promptify
Thank you!
Questions?!