INTRODUCTION TO PROMPT ENGINEERING
"From Questions to Clarity: Introduction to Prompt Engineering."
Prepared by : Bhupen
WHAT IS PROMPT ENGINEERING
Prompt engineering refers to
goal of prompt engineering is
the process of designing and
to ensure high quality
refining prompts or
responses from the AI models
instructions given to artificial
by providing explicit or implicit
intelligence (AI) models to elicit
cues to guide their behavior.
specific desired outputs.
2
AN E X A MPL E ( CHATG PT) me ChatGPT
What's 1 + 1? 1 + 1 equals 2.
Answer formats vary 1 + 1 equals to 2.
(as LLMs are non-deterministic) The sum of 1 + 1 is 2.
1 + 1 still equals 2. This
mathematical equation
remains the same
regardless of how many
times it is asked.
3
me ChatGPT
What's 1+1 stated as an integer? 1 + 1 stated as an integer is simply 2. In integer
notation, we don't include any decimal or
fractional parts, so the result remains 2.
(a narrative answer)
What's 1+1? Only return the numeric answer. 2
(desirable output)
ENGINEERING THE QUESTION
4
ANOTHER EXAMPLE
Given the following text, what is the file size
for Q2 2022?
File
Format
Size
2023 Q1
ZIP
53.11 MB
2022 Q4
ZIP
45.91 MB
2022 Q3
ZIP
45.16 MB
2022 Q2
ZIP
48.79 MB
2022 Q1
ZIP
52.61 MB
15-10-2024 Copyright © 2023 GROKKERS [prepared by bhupen] 5
WHY PROMPTS IN LLMS
LLMs can be overly
accurate (i.e., too much art of asking the right
information), inaccurate, question, or prompt
or far too variable for many engineering
commercial applications.
6
ENGINEERING THE QUESTION
me ChatGPT
Given the following text, what is the file size for Q2 2022? The file size for Q2 2022 is 48.79 MB.
Given the following text, what is the Q2 file size? Only return 48.79 MB
the answer.
Given the following text, what is the Q2 file size in MB, don't 48.79
include any text in the reply?
15-10-2024 Copyright © 2023 GROKKERS [prepared by bhupen] 7
WHY PROMPTS ARE IMPORTANT IN LARGE LANGUAGE MODELS (LLMS)
Prompts are essential in working with Large Language A prompt is the input given to an LLM, guiding it to
Models (LLMs) like OpenAI's GPT-3, GPT-4, and other generate a response or perform a specific task.
transformer-based models.
15-10-2024 Copyright © 2023 GROKKERS [prepared by bhupen] 8
Prompts guide LLMs : generalized models trained on
massive datasets; they rely on prompts to understand
what task to perform. The same model can:
• Generate text.
• Answer questions.
• Perform translations.
STEERING • Summarize content, and more.
MODEL Example:
BEHAVIOR • Prompt 1: Write a story about a brave knight.
• Prompt 2: Explain the concept of quantum
computing.
• Both elicit completely different behaviors from the
same model.
9
Context
• Prompts establish context for the model, helping it
disambiguate the user’s intent. They help the LLM
understand the subject, tone, and format required
for the response.
• If a task is complex, the prompt can specify step-by-
step instructions or set boundaries for the
CONTEXT response.
SETTING AND Example:
C L A R I F I C AT I O N
• Prompt 1: Summarize the following paragraph in
simple language.
• Prompt 2: Summarize the following paragraph for a
scientific audience.
10
By crafting varied prompts, you can make an LLM perform
numerous tasks without retraining or fine-tuning the
model. This makes prompts a powerful interface for task
generalization.
Instead of training multiple models for specific tasks, a
single LLM can be guided through different prompts to:
• Generate creative content.
FLEXIBILITY • Answer technical questions.
WITHOUT
• Provide conversational responses, etc.
FINE-
TUNING • Example:
• Prompt 1: Translate this sentence into French.
• Prompt 2: What is the capital of Japan?
• These two prompts trigger entirely different abilities in
the model without needing any fine-tuning.
11
• Prompts allow users to interact with LLMs using
natural language, making these models accessible to
non-experts. You don't need programming or
machine learning expertise to get useful results.
• A user can phrase a request in everyday language,
and the LLM will interpret it and return the desired
output.
N AT U R A L
L A N G UA G E • Example:
I N T E R FA C I N G
• You can simply type "Generate a list of 5 healthy
dinner recipes" and get a valid, meaningful
response from the LLM.
12
• Prompts give control over
• Length of the response (by specifying token
limits).
• Creativity of the response (using parameters
like temperature, which controls
randomness).
CONTROL • Structure of the response (providing formats
OVER like bullet points, lists, or paragraphs).
OUTPUT • Example:
• Prompt 1: Generate a 2-paragraph summary of this
document.
• Prompt 2: Generate 5 bullet points summarizing
the key takeaways from this document.
13
In many NLP tasks like question answering,
summarization, or information retrieval, the prompt
acts as the query that helps extract relevant
information from the model’s vast knowledge base.
PROMPT
• Example:
AS A
QUERY IN • Prompt: What are the benefits of renewable
energy?
NLP
• The model responds by retrieving relevant
information related to the query.
14
Prompts enable dynamic adaptation, where users can
refine and adjust them iteratively to improve the
output.
DYNAMIC This trial-and-error process helps optimize the
interaction for better responses.
AND
• Example:
ADAPTIVE
RESPONSES • Start with: "Explain the theory of relativity."
• Refine it to: "Explain the theory of relativity in simple
terms for a 10-year-old."
15
LLMs exhibit emergent capabilities that can be
achieved by varying prompt complexity and specificity.
Complex reasoning, code generation, and advanced
comprehension emerge when the model is prompted
with more detailed instructions.
EMERGENCE • Example:
OF NEW
C A PA B I L I T I ES • Simple Prompt: Translate this sentence.
• Complex Prompt: Translate this sentence, preserving
the tone and formal register of the original text.
16
• Text Generation
• Prompt: "Write a news headline about
[topic].“
• By providing a specific topic in the prompt, the
AI model can generate a news headline that is
focused and relevant to the given topic.
USE CASE
• Creative Writing
• Prompt: "Write a short story about a
[character] who embarks on a quest to find
[object] in a [setting].“
• This prompt guides the AI model to generate a
creative story with specific characters, objects,
and settings.
Copyright © 2023 GROKKERS [prepared by bhupen] 17
• Product Descriptions
• Prompt: "Describe the features and
benefits of the [product].“
• By specifying the product in the prompt,
the AI model can generate a descriptive
USE CASE text highlighting the unique features and
advantages of the given product.
Copyright © 2023 GROKKERS [prepared by bhupen] 18
USE CASE
• Question-Answering:
• Prompt: "What is the capital of [country]?“
• By replacing [country] with the name of a
specific country, the AI model can generate the
corresponding capital as the answer.
Copyright © 2023 GROKKERS [prepared by bhupen] 19
• Simple Prompt Engg with Open AI LLM
15-10-2024 Copyright © 2023 GROKKERS [prepared by bhupen] 20
HAPPY LEARNING
Copyright © 2023 GROKKERS [prepared by bhupen] 21