0% found this document useful (0 votes)
43 views

Lesson 03 Prompt Engineering

Uploaded by

nanda.yugandhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Lesson 03 Prompt Engineering

Uploaded by

nanda.yugandhar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Essentials of Generative AI, Prompt

Engineering, and ChatGPT


Prompt Engineering
Learning Objectives

By the end of this lesson, you will be able to:

Recognize the role of prompt design in optimizing ChatGPT's performance

Explain the elements of a structured prompt

Apply basic prompt engineering techniques for desired responses

Utilize task-specific prompt strategies for accurate outputs


Prompt Engineering and Its Importance
Prompt Engineering

Prompt engineering refers to the process of crafting and designing effective prompts or instructions to
guide language models, such as ChatGPT, in generating desired outputs.

It involves formulating clear and specific instructions,


providing relevant context, structuring examples, and
leveraging system messages to influence the behavior and
response quality of the model.
Prompt Engineering

The goal of prompt engineering is to optimize the performance of language models.

• It refines language model outcomes with careful prompt


construction.
• It enhances accuracy, relevance, and coherence, extending benefits
to tasks like summarizing and answering questions.
• It requires understanding prompt architecture, guiding model
behavior, and continuous refinement of prompts.
Importance of Prompt Engineering

Prompt engineering plays a critical role in optimizing the performance of language models, leading to
several key advantages:

Improved user
experience
Bias
mitigation
Task-specific
optimization
Control and
customization
Accuracy and
relevance
Prompt Engineering: Example

Prompt:

What are the symptoms and treatment options for COVID-19?

Prompt response:

The model generates accurate and comprehensive information about


COVID-19 symptoms and treatment, providing valuable insights for
Answering questions
users.
Prompt Engineering: Example

Prompt:

Concisely summarize the article on renewable energy sources

Prompt response:

The model generates a concise and coherent summary that captures


the article’s key points, making it easier for users to grasp the main
ideas quickly. Summarizing content
Prompt Engineering: Example

Prompt:
Translate the following English text into French: The cat is sitting on
the mat.

Prompt response:

The model accurately translates the English text into French, ensuring
an effective and reliable communication tool for users.
Language translation
Basic Architecture and Components of a Prompt
Basic Architecture and Components of a Prompt

The basic architecture of a prompt consists of several key components that work together to guide the
behavior and output of a language model.
Basic Architecture and Components of a Prompt

Here are the main components:

Context:
• The context provides background information or preceding dialogue that helps
set the stage for the model's response.
• It helps the model understand the conversation or the specific task at hand,
ensuring continuity and coherence in the generated output.

Instructions:
• Instructions are explicit guidelines or directives given to the model to guide its
behavior.
• They specify the desired outcome, format, or constraints for the response.
• Clear and specific instructions help shape the model's understanding and generate
more relevant and accurate outputs.
Basic Architecture and Components of a Prompt

Here are the main components:

System messages: Examples:


• Utilize additional texts or prompts as • Utilize specific instances as
intermediary instructions or clarifications demonstrations for the model to emulate
• Offer context, guidance, or information to • Provide concrete references to guide the
the model, without significantly influencing model toward desired patterns or
the final response behaviors
Importance of Clear And Specific Instructions

Clear instructions lead


to the desired output

Specific instructions Specific instructions stipulate


provide clarity and help the writing style to receive the
to focus on tasks intended response

Clear instructions help Clear instructions mitigate


eliminate ambiguity biases in models

Specific instructions ensure


consistency with the model
Basic Prompt Engineering with ChatGPT
Strategies for Formulating Effective Prompts

Formulating effective prompts is essential for guiding language models to generate accurate
and relevant responses.

Here are some strategies to consider when crafting prompts:

Be clear and specific Provide context

Communicate desired Set the context by


output or task to the providing relevant
model information or
preceding dialogue
Strategies for Formulating Effective Prompts

Use examples Consider length and detail Control style and tone

Include specific Determine the Provide explicit


examples or desired length and instructions to the
demonstrations of level of detail for the model when specific
the desired output response requirements exist
for style, tone, or
level of formality
Strategies for Formulating Effective Prompts

Anticipate limitations Iterative refinement Test and validate

Consider the limitations Engage in prompt Evaluate the model's


of the language model engineering through an responses against the
and anticipate potential iterative process of expectations and
pitfalls or challenges refinement, validate the
experimenting with effectiveness of the
different variations of prompts by analyzing
prompts, analyzing the the quality, accuracy,
model's responses, and and relevance of the
adjusting accordingly generated output
Generating Prompts

The choice of prompt generation depends on:

Specific requirements Available resources Desired level of


of the task computation

• Manual prompt crafting enables control and customization, while automated


techniques ensure efficiency and scalability.
• A combination of these techniques is used to leverage the strengths of each
and achieve optimal prompt design.
Techniques for Generating Prompts

Generating effective prompts is a critical aspect of prompt engineering.

Various techniques that can be employed to create prompts that guide model
behavior are:

Manual prompt Template-based Rule-based


crafting generation systems
Manual Prompt Crafting

Manual prompt crafting involves the manual creation of prompts by domain experts or researchers.

It requires a deep understanding of the task and the


desired model behavior.

Prompt design carefully considers the task requirements,


desired output, and potential model biases.

This technique allows for fine-tuning based on specific


variations and user feedback.

It offers high-level control and customization over the


prompt design process.
Manual Prompt Crafting: Example

An example of a manual prompt is given below:


Template-Based Generation

Template-based generation involves defining prompt templates with placeholders


for task-specific information.

Templates may incorporate specific instructions, context, or sample


inputs.

Prompt generation fills placeholders with relevant content, such as


task-specific keywords or data samples.

Design of templates can utilize patterns observed in the task, input-


output structures, or user preferences.

Automation of prompt generation, while still allowing flexibility and


customization, is made possible by this technique.
Template-Based Generation: Example

An example of a template-based prompt is given below:


Rule-Based Systems

Rule-based systems utilize predefined rules or heuristics to generate prompts.

The rules can be based on linguistic patterns, semantic relationships, or


statistical analysis of the data.

The system applies the rules to generate prompts based on certain criteria or
guidelines.

The rule-based prompt generation guarantees consistency and systematic


creation of prompts.

This technique is particularly useful when prompt variations need to adhere to


specific rules or guidelines.
Rule-Based Systems: Example

• In this example, rule-based prompt generation relies on predefined rules or criteria for
prompt structure based on input text characteristics.
• A rule is set to determine the appropriate prompt structure based on word count.
• If input text exceeds a specific word count (in this case, 100 words), key sentences are
extracted for the summary.
• For shorter texts, the main points are condensed into a concise paragraph for the summary.
Prompting ChatGPT
Prompting ChatGPT: Q&A

The following provides instructions for how to prompt ChatGPT in a Q&A format:

Explicitly state the Provide necessary Format the prompt as


1 2 3
question context a conversation

Restrict the answer Ask for reasoning or


4 5 Fine-tune the prompt 6
length an explanation

7 Iterate and evaluate


Prompting ChatGPT: Q&A

Example: Accurate prompts

User: Can you explain the concept of gravitational force?

Assistant: Sure! The concept of gravitational force is a fundamental concept in


physics.

User: What are the main factors influencing climate change?

Assistant: The main factors influencing climate change include many reasons.
Prompting ChatGPT: Q&A

Suppose one wants to know about Neuroscience

Inaccurate prompt

User: What can you tell me about science?

Science is a systematic approach to understanding the


Assistant: natural world, involving observation, hypothesis
formulation, and experimental verification.
Prompting ChatGPT: Summarize

Here are a few guidelines on how to engage ChatGPT in summarization tasks:

Clarity

Focus on the main


Conciseness
ideas

Maintain accuracy Logical coherence

Reflect the original Avoid personal


context opinions
Prompting ChatGPT: Summarize

Clarity:
Maintain clarity in the summary by using simple, direct language

Conciseness:

Keep the summary concise by capturing the principal ideas or crucial information succinctly

Logical coherence:

Structure the summary logically, ensuring a smooth flow and easy comprehension for the reader

Avoid personal opinions:


Preserve objectivity in the summary, avoiding the inclusion of personal opinions or interpretations
unless explicitly required
Prompting ChatGPT: Summarize

Reflect the original context:

• Capture the essence and context of the original content in the summary
• Preserve the overall meaning and purpose during the condensation of information

Maintain accuracy:

• Retain the accuracy and integrity of the original content when condensing
• Avoid distortion or misrepresentation of facts or ideas

Focus on the main ideas:

• Identify and prioritize the most crucial concepts, events, or arguments in the summary.
• Exclude minor details or peripheral information
Prompting ChatGPT: Summarize

Accurate prompts Inaccurate prompt

Prompt: Can you provide a brief summary of


the plot of the movie Inception?

Prompt: Please summarize the main events Prompt: Please summarize the entire field of
of the American Revolutionary War. quantum physics in one sentence.

Prompt: In a few sentences, summarize the


key features of the latest iPhone model.
Prompting ChatGPT: Explain

Here are a few guidelines on how to engage ChatGPT in explanation tasks:

Structure Context

• Present information logically


Provide relevant context or
and in sequential order
background information to set
• Use headings or bullet points
the stage for the explanation
for key aspects

Clarity Use examples

Illustrate the concept or idea


Ensure that the explanation is
with examples to make it more
clear and easy to understand
tangible and relatable
Prompting ChatGPT: Explain

Avoid assumptions Accuracy

Start from a foundational level and build Verify information from reliable sources
up the explanation, ensuring the and double-check technical details or
coverage of all essential information factual claims before the presentation

Answer potential
Provide depth
questions
Tailor the depth of the explanation to Anticipate common questions or points
the intended audience or context, of confusion and proactively address
avoiding unnecessary complexity or them in the explanation, clarifying
oversimplification potential areas of uncertainty
Prompting ChatGPT: Explain

Prompt: Can you explain the concept of artificial intelligence?

Accurate Prompt: Please provide an explanation of the process of cellular respiration.


prompts
Prompt: In a few sentences, explain the principles of supply and demand in
economics.

Inaccurate
Prompt: Please explain the entire field of mathematics in one sentence.
prompt
Prompting ChatGPT: Completion

Here are a few guidelines on how to engage ChatGPT in completion tasks:

Prompt Style or
length tone

Indicate the desired length or Direct the model to maintain a


format, whether a word, specific style, tone, or voice for
sentence, or paragraph consistency
Prompting ChatGPT: Completion

Iterative
Constraints
prompts
Supply ample context for
completion tasks, incorporating
necessary information or
• Use iterative prompts for preceding text Define constraints or
desired outcomes requirements clearly,
• Adjust prompt wording or instructing the model on
context, as necessary topics, themes, or narrative
Context direction
Prompting ChatGPT: Completion

The right prompt precisely conveys what needs to be done, while the wrong prompt tends to be
generalized and fails to provide proper instruction.

Prompt: Complete the following sentence: In a galaxy far, far away,


__________.
Accurate prompt
Prompt: Please provide the continuation for the sentence: In a galaxy
far, far away, __________.

Inaccurate prompt Prompt: Write a novel about a detective solving a mysterious crime.
Prompting ChatGPT: Translation

Here are a few guidelines on how to engage ChatGPT in translation tasks:

Prioritize conveying the original meaning, mindful of linguistic and cultural


1 Language pair
nuances

2 Clarity Include all relevant context and information to facilitate the translation process

3 Context Ensure translations are clear, fluent, and grammatically correct

4 Accuracy Specify both the source language and the target language clearly
Prompting ChatGPT: Translation

Prompt: Translate the following sentence into Spanish: I love to travel


and explore new cultures.
Accurate prompt:
Prompt: Please translate the sentence I love to travel and explore new
cultures into Spanish.

Inaccurate prompt: Prompt: Please translate the entire document from English to French.
Best Practices, Considerations, and Limitations
Best Practices and Considerations

Best practices and considerations for using ChatGPT effectively:

Clearly define the goal Be mindful of bias

Determine the purpose of Carefully review and evaluate


using ChatGPT and clearly the outputs to ensure fairness
define your objective and mitigate potential biases

Iterate and refine

Experiment with different


prompts and iterate on them
to achieve the desired results
Best Practices and Considerations

Use system messages


strategically Responsible use
System messages can offer When using ChatGPT, be mindful of
additional context or instructions ethical considerations
to guide the model's behavior

Verify information
independently
Always verify critical information
from reliable sources even though
ChatGPT provides useful insights
Limitations of ChatGPT

It is important to be aware of the limitations and exercise critical thinking and caution when
interpreting and relying on ChatGPT's responses.

• It may generate responses that sound plausible but are factually incorrect
or lack common sense reasoning.
Lack of common
sense • It does not possess inherent knowledge or understanding beyond what it
has been trained on.

• The way a prompt is phrased can significantly influence the model's


Sensitivity to response.
input phrasing • Minor changes in wording can lead to different outputs, making it
important to carefully craft prompts to achieve desired results.
Limitations of ChatGPT

• It tends to produce generic or safe responses, especially when it is


Overuse of generic uncertain about the specific context or lacks sufficient information.
responses
• This can sometimes result in uninformative or evasive answers.

• Language models like ChatGPT can inadvertently reflect biases present in


the training data.
Sensitivity to bias
• It may reinforce biases, stressing the importance of careful prompt
engineering and evaluation.

• ChatGPT lacks the ability to seek clarifications or ask follow-up questions


Inability to ask when the input is ambiguous or requires further context.
clarifying questions
• It may generate responses based on incomplete or misunderstood
information.
Limitations of ChatGPT

• ChatGPT may struggle with abstract concepts or reasoning beyond its


Difficulty in handling training data.
abstractions • It may provide overly simplistic or nonsensical responses when faced with
complex or abstract queries.

• The model's responses can be sensitive to slight changes in the prompt or


Inconsistent the ordering of information.
responses • It may provide different answers for similar queries, leading to
inconsistent behavior.
Limitations of ChatGPT

Limited knowledge • ChatGPT's training data is current up to September 2021.


and outdated • It may lack awareness of recent events or advancements beyond that
information time, potentially providing outdated or inaccurate information.

• The performance of ChatGPT heavily relies on the quality and diversity of


Dependency on the data it has been trained on.
training data • It may struggle with topics or domains that were underrepresented in its
training data.

• ChatGPT lacks emotional understanding or empathy.


Lack of emotional
understanding • It may not respond appropriately to emotionally charged or sensitive
queries, potentially leading to inappropriate or insensitive responses.
Group Activity
Group Activity: Mastering Prompt Engineering

1. Get into your respective breakout rooms.


2. Pick one situation from the following: asking for help from customer service,
getting educational information, or getting help with writing creatively.
3. Draft a prompt that best describes your desired output.
4. Use ChatGPT for this exercise.
5. Analyze the generated output with your group.
6. Come back to the main Zoom room to present your output and the chosen
prompt.
7. Discuss the prompt in class and see how each group’s prompt differs.

Remember: Your aim is to see how your descriptive prompts influence the AI's
visual output.
Key Takeaways

Prompt engineering refers to the process of crafting and designing


effective prompts or instructions to guide language models, such as
ChatGPT, in generating desired outputs.

The right prompt precisely conveys what needs to be done, while the
wrong prompt tends to be generalized and fails to provide proper
instruction.

The basic architecture of a prompt consists of several key components


that work together to guide the behavior and output of a language
model.

It is important to be aware of the limitations and exercise critical thinking


and caution when interpreting and relying on ChatGPT's responses.
Knowledge Check
Knowledge
Check
What is the role of prompt design in prompt engineering?
1

A. Enhancing model performance

B. Controlling model behavior

C. Improving training data quality

D. Adjusting computational resources


Knowledge
Check
What is the role of prompt design in prompt engineering?
1

A. Enhancing model performance

B. Controlling model behavior

C. Improving training data quality

D. Adjusting computational resources

The correct answer is A

Prompt engineering is used to enhance model performance.


Knowledge
Check
Which component is NOT a part of the basic architecture of a prompt-based system?
2

A. Context

B. Instructions

C. Examples

D. Output generation
Knowledge
Check
Which component is NOT a part of the basic architecture of a prompt-based system?
2

A. Context

B. Instructions

C. Examples

D. Output generation

The correct answer is D

Output generation is not a part of the basic architecture of a prompt-based system.


Knowledge
Check
Why are clear and specific instructions important in guiding the model's behavior?
3

A. They prevent biases in responses.

B. They improve model training speed.

C. They ensure faster response times.

D. They help achieve accurate and relevant outputs.


Knowledge
Check
Why are clear and specific instructions important in guiding the model's behavior?
3

A. They prevent biases in responses.

B. They improve model training speed.

C. They ensure faster response times.

D. They help achieve accurate and relevant outputs.

The correct answer is D

Clear and specific instructions help achieve accurate and relevant outputs.
Knowledge
Check
Which task can be accomplished through prompt engineering with ChatGPT?
4

A. Image classification

B. Sentiment analysis

C. Language translation

D. Speech recognition
Knowledge
Check
Which task can be accomplished through prompt engineering with ChatGPT?
4

A. Image classification

B. Sentiment analysis

C. Language translation

D. Speech recognition

The correct answer is C

Prompt engineering with ChatGPT can accomplish language translation.


Thank You!

You might also like