1 of 133

Lavanya.ai

AI • Growth • Startups • Building

PROMPT ENGINEERING

2 of 133

Prompt Engineering

GenAI Enterprise Accelerator Master Class

LAVANYA.AI

3 of 133

Industry leading partnerships

Streamlined End-to-End ML & LLM Workflow

Technology

AI Developer Platform

​

Customers

1000+ Enterprises & AI Leaders

​

Leadership

Community & Ecosystem

Ecosystem >50,000 repo & framework integrations

​

​

​

Investors

Weights & Biases

Mission: Build the best tools for AI developers

Series C: $250m in funding

W&B Models

W&B Weave

W&B Core

4 of 133

Are you using GenAI today personally?

LAVANYA.AI

5 of 133

Are you exploring GenAI as a company?

LAVANYA.AI

6 of 133

Are you using GenAI in production?

LAVANYA.AI

7 of 133

Prototype To Production

Nov 4

Foundations of Prompting, RAG systems, Agents

Nov 25

Evaluate and Productionize AI Systems

Dec 16

Build and deploy a GenAI app end-to-end

LAVANYA.AI

8 of 133

Community

8

LAVANYA.AI

9 of 133

Ask Qs!

???

9

LAVANYA.AI

10 of 133

GenAI Accelerator was transformational for our team. Weights & Biases' depth of knowledge on GenAI is unmatched—it's clear why nearly every foundation model is built on their platform. Highly recommended for anyone serious about leveraging GenAI in their business.”

We will help you train your teams on GenAI best practices

James Cham

Partner, Bloomberg Beta

11 of 133

We will help you build production quality applications

The support we’ve received from Weights & Biases has been exceptional. They have been invaluable as thought partners and guides throughout our journey. Their deep expertise not only allowed us to anticipate potential roadblocks well in advance but also equipped us with well-considered solutions. Thanks to their guidance, we were able to bring the product to market more swiftly and with fewer challenges.”

Weave

Deliver GenAI with confidence

Monitor

Collaborate

Evaluate

Build

David Rogier

CEO, MasterClass

12 of 133

Prompt Engineering

1

Agenda

PE – Play

2

RAG

3

RAG – Play

4

Feedback

5

LAVANYA.AI

13 of 133

AI

Machine Learning

Deep Learning

LLMs

GenAI

Foundation Models

LAVANYA.AI

14 of 133

What’s so exciting?

LAVANYA.AI

15 of 133

LLMs massively expedite the ability for anyone to quickly build useful applications

LAVANYA.AI

16 of 133

Getting great results from LLMs doesn’t require knowledge of deep learning models, programming, math or statistics.

LAVANYA.AI

17 of 133

Democratization of AI

Foundation

Model Builder

ML

Engineer

Software

Developer

1000s

100,000s

10,000,000s

LAVANYA.AI

18 of 133

Your IP is all the things you tried along the way

LAVANYA.AI

19 of 133

These models are like zip files

compressing the knowledge of the entire internet

LAVANYA.AI

20 of 133

Transformers 🤿

LAVANYA.AI

21 of 133

2017

LAVANYA.AI

22 of 133

Self Attention

LAVANYA.AI

23 of 133

Multi-Headed Attention

LAVANYA.AI

24 of 133

Tokenization

LAVANYA.AI

25 of 133

Tokenizers

25

LAVANYA.AI

26 of 133

How much information can be included in a prompt depends on the model’s context length.

Context is memory

CONTEXT WINDOW

LENGTH

TOKEN

LAVANYA.AI

27 of 133

How much information can be included in a prompt depends on the model’s context length.

Context is memory

LAVANYA.AI

28 of 133

Fine-Tuning

​

Updating the weights of some or all layers of the pre-trained model to adapt it to the new task

Prompt Engineering

​

Prompt engineering is temporary learning during inference.

​

It lets us communicate with an LLM to steer its behavior without updating the model weights

RAG

​

For tasks that require latest knowledge after the model pretraining time cutoff or access to private knowledge base

​

LAVANYA.AI

29 of 133

Zero Shot & Few Shot Learning

LAVANYA.AI

30 of 133

Steer Behavior With Prompts

30

Q: Are whales fish?

A:

​

Model Output: No, whales are not fish. Whales are mammals. Here are some key differences between whales (mammals) and fish:

​

Breathing: Whales breathe air through lungs and must come to the surface to breathe. Fish, on the other hand, extract oxygen from water through their gills.

​

Body Temperature: Whales are warm-blooded, meaning they can regulate their body temperature internally. Fish are cold-blooded and their body temperature varies with the environment.

​

Reproduction: Whales give birth to live young and nurse them with milk. Most fish lay eggs, although there are some fish that give birth to live young.

​

Skin: Whales have smooth skin with a layer of blubber underneath for insulation. Fish have scales covering their bodies.

​

Movement: Whales move their tails up and down when swimming, while fish move their tails side to side.

​

These distinctions categorize whales as mammals and not fish.

31 of 133

Steer Behavior With Prompts

Q: Are whales fish?

A: No

Q: Are pig-nosed turtle mammals?

A:

​

Model Output: No

LAVANYA.AI

32 of 133

Steer Behavior With Prompts

Q: Are whales fish?

A: No, they're mammals.

Q: Are pig-nosed turtle mammals?

A:

​

​

Model Output: No, they're reptiles

Q: Are whales fish?

A: No

Q: Are pig-nosed turtle mammals?

A:

​

​

Model Output: No

LAVANYA.AI

33 of 133

Few-Shot Prompting

33

Classify the text delimited by triple backticks into one of the following classes.

Classes: {desired_tags}

​

Text: ```{ticket_text1}```

Class: question

​

Text: ```{ticket_text2}```

Class: type_bug

<...more examples here>

​

Text: ```{ticket_text}```

Class:

LAVANYA.AI

34 of 133

Each example in the prompt is a shot.

​

More powerful models

...need fewer examples

...to have better performance

LAVANYA.AI

Prompting with examples = better performance

35 of 133

Is prompting

useful on its own?

35

2. Clean the data – sheet

3. Ask questions – ChatGPT

1. Get the data – docs

LAVANYA.AI

Let’s try it!

36 of 133

Prompt

Structure

LAVANYA.AI

37 of 133

LAVANYA.AI

System &

User Prompts

SYSTEM

The system role sets the behavior of the assistant

ASSISTANT

ChatGPT (LLM) receives the prompt and returns the completions

USER

The user (You) sends the prompts and receives the completions

System

User

Assistant

context

prompt

response

38 of 133

LAVANYA.AI

System prompt

= task description

​

User prompt

= the task

39 of 133

LAVANYA.AI

System prompt = task description

User prompt = task

40 of 133

LAVANYA.AI

Is all context equal?

41 of 133

Temperature adjusts how adventurous the model is with its word choices by reshaping the probability landscape

​

High ~ Chatbots: Makes responses more varied and human-like, enhancing engagement

Low ~ Code Generation: Produces more predictable and stable outputs, reducing errors.

LAVANYA.AI

Temperature

42 of 133

nat.dev

42

43 of 133

Best

Practices

LAVANYA.AI

44 of 133

LAVNYA.AI

Write clear and explicit instructions

45 of 133

LAVANYA.AI

Use delimiters to clearly indicate distinct parts of the input

46 of 133

Specify the Output Format

LAVANYA.AI

47 of 133

Ask the model to adopt a persona

LAVANYA.AI

48 of 133

Provide examples

LAVANYA.AI

49 of 133

Bring your own texts as context

LAVANYA.AI

50 of 133

Ask the model if it missed anything on previous passes

LAVANYA.AI

51 of 133

Break complex tasks into simpler subtasks

LAVANYA.AI

52 of 133

Give the model time to think

❌

✅

LAVANYA.AI

53 of 133

Few-Shot

​

Show it reasoning examples

Chain of Thought

LAVANYA.AI

54 of 133

o1 from OpenAI

LAVANYA.AI

55 of 133

Project

LAVANYA.AI

56 of 133

Project

56

Data analysis with ChatGPT

LAVANYA.AI

57 of 133

Challenge

(10 mins)

57

2. Go to ChatGPT

​

  1. Paste in data
  2. Ask questions
  3. Get insights

1. Get the data wandb.me/class-data

  • Plot a distribution of Scores
  • Make a correlation matrix of features
  • Amazon Reviews Dataset
    • what types of products get mostly good and bad reviews?
    • which products have generally good and bad reviews
    • which reviewers give generally good and bad reviews
  • Wines Dataset
    • is wine price correlated to score?
    • what types of wines get the best scores?
    • which regions have the best wines?
    • are some reviewers harsher at rating than others?

Question Ideas

Gumption

LAVANYA.AI

58 of 133

Limited Context

We can’t feed it all our data

How do we judge if it’s right?

Rigorous evaluations for all expected use cases

How did it get better?

Save prompts, models

LAVANYA.AI

Challenges

59 of 133

RAG

LAVANYA.AI

60 of 133

Thank You

Learn more at lavanya.ai

2 Prompt Engineering

61 of 133

62 of 133

​

​

GenAI Enterprise Accelerator Master Class

Prompt Engineering

63 of 133

Industry leading partnerships

Streamlined End-to-End ML & LLM Workflow

​

Technology

AI Developer Platform

​

​

Customers

1000+ Enterprises & AI Leaders

​

Leadership

Community & Ecosystem

Ecosystem >50,000 repo & framework integrations

​

​

​

Investors

Weights & Biases

Mission: Build the best tools for AI developers

Series C: $250m in funding

W&B Models

W&B Weave

W&B Core

64 of 133

Are you using GenAI today personally?

64

65 of 133

Are you exploring GenAI as a company?

65

66 of 133

Are you using GenAI

in production?

66

67 of 133

Prototype To Production

Nov 4

Foundations of Prompting, RAG systems, Agents

Nov 25

Evaluate and Productionize AI Systems

Dec 16

Build and deploy a GenAI app end-to-end

68 of 133

Community

68

wandb.me/discord

ACCELERATOR.CC

69 of 133

Ask Qs!

69

70 of 133

GenAI Accelerator was transformational for our team. Weights & Biases' depth of knowledge on GenAI is unmatched—it's clear why nearly every foundation model is built on their platform. Highly recommended for anyone serious about leveraging GenAI in their business.”

We will help you train your teams on GenAI best practices

James Cham

Partner, Bloomberg Beta

71 of 133

We will help you build production quality applications

The support we’ve received from Weights & Biases has been exceptional. They have been invaluable as thought partners and guides throughout our journey. Their deep expertise not only allowed us to anticipate potential roadblocks well in advance but also equipped us with well-considered solutions. Thanks to their guidance, we were able to bring the product to market more swiftly and with fewer challenges.”

Weave

Deliver GenAI with confidence

Monitor

Collaborate

Evaluate

Build

David Rogier

CEO, MasterClass

72 of 133

Prompt Engineering

1

Agenda

PE – Play

2

RAG

3

RAG – Play

4

Feedback

5

GENAI ACCELERATOR

73 of 133

73

AI

Machine Learning

Deep Learning

LLMs

GenAI

Foundation Models

74 of 133

ACCELERATOR.CC

What’s so exciting?

75 of 133

LLMs massively expedite the ability for anyone to quickly build useful applications.

ACCELERATOR.CC

76 of 133

Getting great results from LLMs doesn’t require knowledge of deep learning models, programming, math or statistics.

ACCELERATOR.CC

77 of 133

Democratization of AI

Foundation

Model Builder

ML

Engineer

Software

Developer

1000s

100,000s

10,000,000s

ACCELERATOR.CC

78 of 133

Your IP is all the things you tried along the way

ACCELERATOR.CC

79 of 133

These models are like zip files

​

compressing the knowledge of the entire internet

ACCELERATOR.CC

80 of 133

ACCELERATOR.CC

Transformers 🤿

81 of 133

2017

ACCELERATOR.CC

82 of 133

Self Attention

ACCELERATOR.CC

83 of 133

Multi-Headed Attention

84 of 133

Tokenization

ACCELERATOR.CC

85 of 133

Tokenizers

​

​

wandb.me/tokenizer

85

ACCELERATOR.CC

86 of 133

How much information can be included in a prompt depends on the model’s context length.

ACCELERATOR.CC

Context is memory

Context Window

Length

Token

87 of 133

How much information can be included in a prompt depends on the model’s context length.

ACCELERATOR.CC

Context is memory

88 of 133

ACCELERATOR.CC

Fine-Tuning

​

Updating the weights of some or all layers of the pre-trained model to adapt it to the new task

Prompt Engineering

​

Prompt engineering is temporary learning during inference.

​

It lets us communicate with an LLM to steer its behavior without updating the model weights

RAG

​

For tasks that require latest knowledge after the model pretraining time cutoff or access to private knowledge base

​

89 of 133

ACCELERATOR.CC

Zero Shot & Few Shot

Learning

90 of 133

Steer Behavior With Prompts

90

Q: Are whales fish?

A:

​

Model Output: No, whales are not fish. Whales are mammals. Here are some key differences between whales (mammals) and fish:

​

Breathing: Whales breathe air through lungs and must come to the surface to breathe. Fish, on the other hand, extract oxygen from water through their gills.

​

Body Temperature: Whales are warm-blooded, meaning they can regulate their body temperature internally. Fish are cold-blooded and their body temperature varies with the environment.

​

Reproduction: Whales give birth to live young and nurse them with milk. Most fish lay eggs, although there are some fish that give birth to live young.

​

Skin: Whales have smooth skin with a layer of blubber underneath for insulation. Fish have scales covering their bodies.

​

Movement: Whales move their tails up and down when swimming, while fish move their tails side to side.

​

These distinctions categorize whales as mammals and not fish.

91 of 133

Steer Behavior With Prompts

Q: Are whales fish?

A: No

Q: Are pig-nosed turtle mammals?

A:

​

​

Model Output: No

ACCELERATOR.CC

92 of 133

Steer Behavior With Prompts

Q: Are whales fish?

A: No, they're mammals.

Q: Are pig-nosed turtle mammals?

A:

​

​

Model Output: No, they're reptiles

Q: Are whales fish?

A: No

Q: Are pig-nosed turtle mammals?

A:

​

​

Model Output: No

ACCELERATOR.CC

93 of 133

Few-Shot Prompting

93

Classify the text delimited by triple backticks into one of the following classes.

Classes: {desired_tags}

​

Text: ```{ticket_text1}```

Class: question

​

Text: ```{ticket_text2}```

Class: type_bug

<...more examples here>

​

Text: ```{ticket_text}```

Class:

ACCELERATOR.CC

94 of 133

Each example in the prompt is a shot.

​

More powerful models

...need fewer examples

...to have better performance

ACCELERATOR.CC

Prompting with examples = better performance

95 of 133

Is prompting

useful on its own?

95

2. Clean the data – sheet

3. Ask questions – ChatGPT

1. Get the data – docs

ACCELERATOR.CC

Let’s try it!

96 of 133

ACCELERATOR.CC

Prompt Structure

97 of 133

ACCELERATOR.CC

System &

User Prompts

System

The system role sets the behavior of the assistant

Assistant

ChatGPT (LLM) receives the prompt and returns the completions

User

The user (You) sends the prompts and receives the completions

System

User

Assistant

context

prompt

response

98 of 133

ACCELERATOR.CC

System prompt

= task description

​

User prompt

= the task

99 of 133

ACCELERATOR.CC

System prompt = task description

User prompt = task

100 of 133

ACCELERATOR.CC

Is all context equal?

101 of 133

Temperature adjusts how adventurous the model is with its word choices by reshaping the probability landscape

​

High ~ Chatbots: Makes responses more varied and human-like, enhancing engagement

Low ~ Code Generation: Produces more predictable and stable outputs, reducing errors.

ACCELERATOR.CC

Temperature

102 of 133

nat.dev

102

103 of 133

ACCELERATOR.CC

Best Practices

104 of 133

ACCELERATOR.CC

Write clear and explicit instructions

105 of 133

ACCELERATOR.CC

Use delimiters to clearly indicate distinct parts of the input

106 of 133

ACCELERATOR.CC

Specify the Output Format

107 of 133

ACCELERATOR.CC

Ask the model to adopt a persona

108 of 133

ACCELERATOR.CC

Provide examples

109 of 133

ACCELERATOR.CC

Bring your own texts as context

110 of 133

ACCELERATOR.CC

Ask the model if it missed anything on previous passes

111 of 133

ACCELERATOR.CC

Break complex tasks into simpler subtasks

112 of 133

ACCELERATOR.CC

Give the model time to think

❌

✅

113 of 133

Few-Shot

​

  • Show it reasoning examples�

Chain of Thought

ACCELERATOR.CC

114 of 133

o1 from OpenAI

ACCELERATOR.CC

115 of 133

ACCELERATOR.CC

Project

116 of 133

116

​

​

Data Analysis with ChatGPT

PROJECT

117 of 133

Challenge

(10 mins)

117

1. Get the data wandb.me/class-data

2. Go to ChatGPT

​

  • Paste in data
  • Ask questions
  • Get insights
  • Plot a distribution of Scores
  • Make a correlation matrix of features
  • Amazon Reviews Dataset
    • what types of products get mostly good and bad reviews?
    • which products have generally good and bad reviews
    • which reviewers give generally good and bad reviews
  • Wines Dataset
    • is wine price correlated to score?
    • what types of wines get the best scores?
    • which regions have the best wines?
    • are some reviewers harsher at rating than others?

Question Ideas

Gumption

118 of 133

ACCELERATOR.CC

Challenges

Limited Context

We can’t feed it all our data

How do we judge if it’s right?

Rigorous evaluations for all expected use cases

How did it get better?

Save prompts, models

119 of 133

​

​

RAG

120 of 133

Community

120

wandb.me/discord

ACCELERATOR.CC

121 of 133

Keep the learning going!

​

@lavanyaai

lavanya@wandb.com

121

ACCELERATOR.CC

122 of 133

​

​

Thank You

lavanya@wandb.com

123 of 133

​

​

Resources

124 of 133

ACCELERATOR.CC

Prompt Engineering

Prompt engineering is temporary learning during inference.

It lets us communicate with an LLM to steer its behavior without updating the model weights.

Language models can learn the desirable behavior from examples in the prompt, even if this desirable behavior is different from what the model was originally trained to do.

In-context learning allows a model to update its behaviors with new information without retraining.

This significantly reduces the rate of a model going stale.

125 of 133

Prompting Techniques

ACCELERATOR.CC

126 of 133

Many model providers claim that well-crafted system prompts can improve performance.

​

But why would system prompts boost performance compared to user prompts?

​

The model pays attention to the system prompt more because:

  • The system prompt comes first in the final prompt, and the model might just be better at processing instructions that come first.
  • The model might have been post-trained to pay more attention to the system prompt.

ACCELERATOR.CC

System prompts >> User prompts

127 of 133

ACCELERATOR.CC

Prompt Engineering

    • Prompt engineering is about crafting an instruction that gets a model to do what you want.
      • For prompting to work, the model has to be able to follow instructions. If a model is bad at it, it doesn’t matter how good your prompt is, the model won’t be able to follow it.
    • The problem is not with prompt engineering. It’s a real and useful skill to have. The problem is when prompt engineering is the only thing people know.

128 of 133

ACCELERATOR.CC

Contexts & Prompts

129 of 133

How much information can be included in a prompt depends on the model’s context length limit.

ACCELERATOR.CC

Context is memory

130 of 133

ACCELERATOR.CC

Best Practices

Explain, without ambiguity, what you want the model to do

Ask the model to adopt a persona

Provide examples

Specify the output format

131 of 133

ACCELERATOR.CC

Tactics for RAG

Prompting to make RAG efficient

132 of 133

ACCELERATOR.CC

Use inner monologue or a sequence of queries to hide the model’s reasoning process

Use inner monologue

133 of 133

ACCELERATOR.CC

Instruct the model to work out its own solution before rushing to a conclusion

Give the model time to think