KEMBAR78
Types of Prompting Slides | PDF | Artificial Intelligence | Intelligence (AI) & Semantics
0% found this document useful (0 votes)
35 views9 pages

Types of Prompting Slides

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views9 pages

Types of Prompting Slides

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Prompting :

1. System Messages:

These messages are used to configure or control the behavior of the


assistant. They often contain instructions or context that are not directly
part of the conversation between the human and AI.

Example: A system message might say: "You are a helpful assistant."

In your case, such messages can include information about settings or


model behavior (e.g., "You are an English-Spanish translator").

2. Human Messages:

These messages are input from the user or person interacting with the
assistant. They represent the questions, commands, or conversation
topics that the human wants the AI to respond to.

Example: A human message might say: "What is the capital of France?"

3. AI Messages:

These messages are generated by the assistant in response to the


human’s input. The AI’s reply is based on its programming, training, and
available knowledge.

Example: An AI message might say: "The capital of France is Paris."

Example:

System: You are a helpful assistant.


Human: What is 2 + 2?
AI: 4

System Message: "You are a helpful assistant." (Configuring the AI's role or
behavior)

Prompting : 1
Human Message: "What is 2 + 2?" (User asking a question)

AI Message: "4" (AI’s response to the human’s query)

1. Zero-Shot Prompting
Definition: The AI is asked to perform a task without any prior example.

Use Case: Simple and general queries where the task is straightforward.

Example:

Prompt:"Explain the difference between machine learning and deep


learning."Response:"Machine learning involves algorithms that learn patterns
from data, while deep learning is a subset of machine learning that uses
neural networks with multiple layers to model complex patterns."

2. One-Shot Prompting
Definition: A single example is provided to guide the AI in generating the
response.

Use Case: When a specific structure or format is needed, and one example is
sufficient.

Example:

Prompt:"Here’s how to introduce yourself in an interview:Example: 'Hi, I’m


John. I specialize in data analysis and have 5 years of experience in Python
and SQL.'Now, introduce yourself."Response:"Hi, I’m Sarah. I specialize in
machine learning and have 3 years of experience in Python and TensorFlow."

3. Few-Shot Prompting
Definition: The AI is provided with multiple examples to learn the task before
generating the output.

Use Case: When a complex or nuanced task needs more guidance.

Prompting : 2
Example:

Prompt:Response:"Bonjour."

vbnet
Copy code
Example 1:
Input: Translate 'Hello' to French.
Output: Bonjour.

Example 2:
Input: Translate 'Thank you' to French.
Output: Merci.

Now, translate 'Good morning' to French.

4. Chain-of-Thought Prompting
Definition: Encourages the model to reason step-by-step to arrive at a
solution.

Use Case: Useful for complex reasoning or problem-solving tasks.

Example:

Prompt:"Solve this problem: There are 10 apples. You gave away 3, and then
bought 5 more. How many apples do you have now? Explain step-by-
step."Response:"Step 1: Start with 10 apples.Step 2: Subtract 3 apples you
gave away. That leaves 7 apples.Step 3: Add 5 apples you bought. 7 + 5 =
12.Final Answer: You now have 12 apples."

5. Role-Based Prompting
Definition: The AI is assigned a specific "role" to act as while responding.

Use Case: When specialized or domain-specific knowledge is needed.

Prompting : 3
Example:

Prompt:"You are a software engineer. Explain the concept of multithreading to


a beginner."Response:"Multithreading allows a program to run multiple
threads simultaneously, making better use of system resources and improving
efficiency."

6. Instruction-Based Prompting
Definition: Explicit instructions are provided about how to perform the task.

Use Case: When tasks require step-by-step or detailed execution.

Example:Prompt:"Write a Python function to calculate the factorial of a


number. Include comments explaining each step."Response:

def factorial(n):
# Initialize result to 1
result = 1
# Multiply result by each number up to n
for i in range(1, n + 1):
result *= i
return result

7. Constraint-Based Prompting
Definition: Constraints are added to guide the model on length, tone, style, or
format.

Use Case: When the output needs to adhere to specific rules.

Example:

Prompt:"Summarize the advantages of AI in 50 words."Response:"AI


improves efficiency, enhances decision-making, automates repetitive tasks,
and enables personalized experiences. It also excels in data analysis, supports

Prompting : 4
healthcare diagnostics, and advances autonomous technology, offering
solutions to complex problems across various industries."

8. Interactive Prompting
Definition: The AI is guided through multiple follow-ups or refinements for
better results.

Use Case: For refining outputs or iterating complex tasks.

Example:

Prompt 1: "Summarize the history of AI."

Response: "AI began in the 1950s with research on problem-solving and


reasoning. It evolved into machine learning and neural networks, leading
to breakthroughs in various fields."

Follow-up: "Expand this summary to include key milestones."

Updated Response: "AI began in the 1950s with early research into
reasoning. Key milestones include the development of expert systems in
the 1970s, machine learning in the 1990s, and advancements in deep
learning in the 2010s, leading to innovations like autonomous vehicles and
generative AI."

9. Contrastive Prompting
Definition: Asks the model to compare or contrast two or more items.

Use Case: When comparisons or differentiations are required.

Example:Prompt:"Compare supervised learning and unsupervised learning


with examples."Response:"Supervised learning uses labeled data to train
models (e.g., spam email detection). Unsupervised learning uses unlabeled
data to find patterns (e.g., customer segmentation)."

10. Multi-Part Prompting


Definition: Divides a task into multiple parts or sections for detailed answers.

Use Case: For large, structured responses.

Prompting : 5
Example:Prompt:"Part 1: Explain what an API is.Part 2: Describe REST API with
an example."Response:

Part 1: "An API (Application Programming Interface) allows communication


between different software applications."

Part 2: "A REST API uses HTTP methods like GET and POST to perform
actions. Example: Fetching user data from a server using an endpoint like
/users ."

11. Visualization-Based Prompting


Definition: Instruct the AI to generate visual aids like charts, code for graphs,
or descriptive outputs.

Use Case: For visual tasks or outputs.

Example:Prompt:"Write Python code to generate a bar chart showing sales


data for

12. Reverse Prompting


Definition: AI is asked to generate the input for a specific output or scenario.

Use Case: For creative or reverse-engineering tasks.

Example:Prompt:"Generate a question that matches this answer: 'Neural


networks are inspired by the structure of the human brain.'"Response:"What
are neural networks inspired by?"

Prompt Template
Definition:

A prompt template is a reusable framework or predefined structure that allows


dynamic inputs to be inserted for repeated tasks or varied responses.

Characteristics:

Pre-designed structure with placeholders for variables or inputs.

Prompting : 6
Enables automation and scalability for repetitive tasks.

Promotes consistency across multiple prompts.

Can be parameterized to handle diverse contexts.

Key Differences
Aspect Prompting Prompt Template

A reusable structure with


Definition Direct input for a single task.
placeholders.

Predefined but adaptable with


Flexibility Ad-hoc and task-specific.
dynamic inputs.

Not reusable; needs to be rewritten


Reusability Highly reusable for similar tasks.
for each task.

More structured and often


Complexity Simple and straightforward.
parameterized.

Repeated tasks with varying


Use Case Quick, one-time tasks or queries.
inputs.

Chains:
SimpleSequentialChain:

Structure: Executes a linear sequence where each step has a single input and
a single output.

Data Flow: The output of one step is automatically passed as the input to the
next step without explicit variable mapping.

Use Case: Ideal for straightforward pipelines where each step directly builds
on the previous one.

SequentialChain:

Prompting : 7
Structure: Handles more complex sequences with multiple inputs and outputs
per step.

Data Flow: Allows explicit mapping of variables between steps, providing


greater flexibility and control over the workflow.

Use Case: Suitable for intricate workflows requiring detailed management of


data flow between components.

Key Differences:

Flexibility: SequentialChain offers greater flexibility with explicit variable


mapping, while SimpleSequentialChain is more straightforward with implicit data
passing.

Complexity: SequentialChain can manage complex workflows with multiple


inputs and outputs, whereas SimpleSequentialChain is designed for simpler, linear
processes.

Advantages of LCEL over Traditional Chains:

1. Concise Syntax: LCEL allows for the creation of complex chains using a
streamlined, pipe-like syntax, enhancing readability and reducing boilerplate
code.

Example:

python
Copy code
chain = prompt | llm | output_parser

This line succinctly represents a sequence where the prompt feeds into the
llm , and its output is processed by the output_parser .

2. Enhanced Flexibility: LCEL enables dynamic composition of chains, allowing


developers to easily modify or extend workflows without restructuring the
entire setup.

Prompting : 8
3. Improved Integration: With LCEL, components are more modular and
interchangeable, facilitating seamless integration with tools like LangSmith.
LangChain Blog

4. Explicit Data Flow: LCEL provides clear visibility into the data flow between
components, making it easier to debug and understand complex workflows.

Prompting : 9

You might also like