LLM & Prompting

Large Language Models

LLM

GPT is a Large Language Model or an LLM and can generate human like text

  • Pre-trained on unlabeled and self-supervised data
  • Instance of a Foundation Model
  • Trained on a large dataset (petabytes)
  • Large in LLM means tens of gigabytes

LLM


LLM & Prompting

Prompt Design

Prompts

A prompt is a specific instruction or request given to a computer program or language model to perform a particular task or generate a specific output.

Prompt Design

Prompt design involves formulating clear, effective instructions or queries that guide AI language models to generate accurate and relevant responses.

  • Contextualizing the task: Providing sufficient context and defining the task at hand

  • Controlling Output Specificity: By adjusting the prompt, we can obtain more general or detailed information as per our requirements.

  • Handling Ambiguity: Reducing ambiguity by providing additional context or constraints

Prompt Engineering

Prompt engineering goes beyond prompt design and involves fine-tuning or modifying existing AI models to enhance their performance on specific tasks.

  • Rule-based Prompts: Incorporating predefined rules or templates into the prompts to guide the AI model’s responses

  • Data Augmentation: By manipulating or generating additional training data, prompt engineering can enhance the model’s performance.

  • Prompt Tuning: Fine-tuning of prompts to achieve better performance.

Incorrect output

Sometimes Gen AIs give incorrect outputs to prompts. For example, they are not very good at multiplying numbers, and will often confidently give you an incorrect answer.

Correct answer should be 505050

Prompt output

Correct answer should be 505050

Prompt output

Correct answer should be 505050

Prompt output

Prompt output

Prompt Embeds

If you want to follow along with the upcoming examples, please generate an Open AI API Key and fill in when asked.

Instruction Prompting

An instruction prompt

Model output

Write the word "funny" backwards

ynnuf

Example #1

Example #2

Example #3

Assigning Roles

A Role Prompt

Model output

You are Shakespeare, an English writer. Write me a poem.

Of lovers' hears and passion's fire

Role Prompting

Role prompting is a technique that can be used to:

  • Control the style of AI generated text.
  • Improve the AI's accuracy when solving math problems.

 

Implementing role prompting is as simple as instructing the AI to "embody a food critic" or to "act like a detective".

Write a review (1/3)

Write a review (2/3)

Write a review (3/3)

Email Writing (Communications specialist)

You are a communications specialist. Draft an email to your client advising them about a delay in the delivery schedule due to logistical problems.

Prompt

Subject: Important Update: Delivery Schedule Delay

Dear [Client's Name],

I hope this message finds you well. I regret to inform you that we are currently facing unexpected logistical challenges that will result in a delay in the delivery schedule for your project. We understand the importance of adhering to timelines and sincerely apologize for any inconvenience this may cause.

The delay is primarily due to unforeseen issues with our suppliers and transportation partners. We are actively working to resolve these issues and expedite the delivery process. Our team is committed to maintaining the quality of your project despite the setback.

We will keep you updated regularly on our progress and provide you with a revised delivery date as soon as we have more clarity. Your satisfaction remains our top priority, and we appreciate your understanding during this challenging period.

If you have any questions or concerns, please do not hesitate to contact me directly. Thank you for your patience and continued trust in our services.

Best regards,
[Your Name]
[Your Title]
[Your Contact Information]

Output

Email Writing (Marketing expert)

You are a marketing expert. Draft an email to a client advising them about a delay in the delivery schedule due to logistical problems.

Prompt

Subject: Important Notice: Delay in Delivery Schedule

Dear [Client's Name],

I trust this email finds you well. I wanted to provide you with a crucial update regarding your project's delivery schedule.

Regrettably, we are currently facing unexpected logistical challenges that will result in a delay in the delivery of your project. We understand the urgency of meeting the agreed-upon timeline and sincerely apologize for any inconvenience this delay may cause.

These logistical issues are primarily due to disruptions in our supply chain and transportation network. Our team is actively addressing these challenges and working diligently to expedite the delivery process. Despite the delay, we remain committed to delivering a product of the highest quality.

We will keep you informed throughout the process and will provide you with a revised delivery date as soon as we have more clarity on the situation. Your satisfaction is of utmost importance to us, and we appreciate your understanding and patience during this time.

If you have any questions or require further information, please feel free to reach out to me directly. We value your business and look forward to delivering exceptional results as soon as possible.

Best regards,

[Your Name]
[Your Title]
[Your Contact Information]

Output

Email Writing (Customer service)

You are a customer service representative. Draft an email to a client advising them about a delay in the delivery schedule due to logistical problems.

Prompt

Subject: Important Notice: Delay in Delivery Schedule

Dear [Client's Name],

I hope this email finds you well. I wanted to reach out to you with some important information regarding your recent order.

Regrettably, we are facing unforeseen logistical challenges that will result in a delay in the delivery of your order. We understand how crucial it is for you to receive your items on time, and we sincerely apologize for any inconvenience this delay may cause.

These logistical issues have arisen due to factors beyond our control, including supply chain disruptions and transportation delays. Our team is working tirelessly to resolve these challenges and expedite the delivery process.

While we understand your frustration, please rest assured that we remain committed to delivering your order to the highest standards of quality. We will keep you updated on the progress and provide you with a new estimated delivery date as soon as possible.

Your satisfaction is our top priority, and we greatly appreciate your understanding and patience during this time. If you have any questions or concerns, please don't hesitate to reach out to our customer service team.

Thank you for choosing us, and we look forward to fulfilling your order as swiftly as circumstances allow.

Best regards,

[Your Name]
[Your Title]
[Company Name]
[Contact Information]

Output

Role Prompting

  • Control of style, tone and depth
  • Good for specific context or audiences
  • Enhance the quality of the results

Few-shot prompting

A Few Shot Prompt

Example

Great product, 10/10: positive

Didn't work very well: negative

Super helpful, worth it: positive

It doesn't work!

Negative

Example 2

Example 1

Example X

Your input

Few-shot prompting

  • Show the model a few examples (also called "shots") of what you want it to do.
  • Few shot prompts allows the AI to learn from these few examples

Structure

Structure

In the bustling town of Emerald Hills, a diverse group of individuals made their mark. Sarah Martinez, a dedicated nurse, was known for her compassionate care at the local hospital. David Thompson, an innovative software engineer, worked tirelessly on groundbreaking projects that would revolutionize the tech industry. Meanwhile, Emily Nakamura, a talented artist and muralist, painted vibrant and thought-provoking pieces that adorned the walls of buildings and galleries alike. Lastly, Michael O'Connell, an ambitious entrepreneur, opened a unique, eco-friendly cafe that quickly became the town's favorite meeting spot. Each of these individuals contributed to the rich tapestry of the Emerald Hills community.

1. Sarah Martinez [NURSE]
2. David Thompson [SOFTWARE ENGINEER]
3. Emily Nakamura [ARTIST]
4. Michael O'Connell [ENTREPRENEUR]

At the heart of the town, Chef Oliver Hamilton has transformed the culinary scene with his farm-to-table restaurant, Green Plate. Oliver's dedication to sourcing local, organic ingredients has earned the establishment rave reviews from food critics and locals alike.

Just down the street, you'll find the Riverside Grove Library, where head librarian Elizabeth Chen has worked diligently to create a welcoming and inclusive space for all. Her efforts to expand the library's offerings and establish reading programs for children have had a significant impact on the town's literacy rates.

As you stroll through the charming town square, you'll be captivated by the beautiful murals adorning the walls. These masterpieces are the work of renowned artist, Isabella Torres, whose talent for capturing the essence of Riverside Grove has brought the town to life.

Riverside Grove's athletic achievements are also worth noting, thanks to former Olympic swimmer-turned-coach, Marcus Jenkins. Marcus has used his experience and passion to train the town's youth, leading the Riverside Grove Swim Team to several regional championships.

1. Oliver Hamilton [CHEF]
2. Elizabeth Chen [LIBRARIAN]
3. Isabella Torres [ARTIST]
4. Marcus Jenkins [COACH]

Oak Valley, a charming small town, is home to a remarkable trio of individuals whose skills and dedication have left a lasting impact on the community.

At the town's bustling farmer's market, you'll find Laura Simmons, a passionate organic farmer known for her delicious and sustainably grown produce. Her dedication to promoting healthy eating has inspired the town to embrace a more eco-conscious lifestyle.

In Oak Valley's community center, Kevin Alvarez, a skilled dance instructor, has brought the joy of movement to people of all ages. His inclusive dance classes have fostered a sense of unity and self-expression among residents, enriching the local arts scene.

Lastly, Rachel O'Connor, a tireless volunteer, dedicates her time to various charitable initiatives. Her commitment to improving the lives of others has been instrumental in creating a strong sense of community within Oak Valley.

Through their unique talents and unwavering dedication, Laura, Kevin, and Rachel have woven themselves into the fabric of Oak Valley, helping to create a vibrant and thriving small town.

Prompt

1. Laura Simmons [FARMER]
2. Kevin Alvarez [DANCE INSTRUCTOR]
3. Rachel O'Connor [VOLUNTEER]

Output

Variants of Shot Prompting

Chicken 2 2:

Prompt

It seems like you've entered "Chicken 2 2," but I'm not sure what you're asking or referring to. Could you please provide more context or clarify your question? I'll be happy to assist you once I understand your request better.

Output

Chicken 2 2

Prompt

It seems like you've entered "Chicken 2 2," but I'm not sure what you're asking or referring to. Could you please provide more context or clarify your question? I'll be happy to assist you once I understand your request better.

Output

Chicken 2 2: 4
Chicken 3 3:

Prompt

It appears you're providing some equations or expressions, but it's not clear what you want to do with them. In the first statement, "Chicken 2 2: 4," it seems like you're equating "Chicken 2 2" to 4, but it's unclear what "Chicken 2 2" represents.

If you could provide more information or context about what you're trying to calculate or achieve, I'd be happy to assist you further.

Output

Chicken 2 2: 4
Chicken 3 3: 6
Chicken 5 5:

Prompt

It seems like you're using the word "Chicken" followed by two numbers and a colon, with the numbers representing some sort of input, and you're expecting a numerical output. Based on the provided examples:

- "Chicken 2 2: 4" suggests that when you input 2 and 2, you get 4 as the result.
- "Chicken 3 3: 6" suggests that when you input 3 and 3, you get 6 as the result.

If we follow this pattern, then "Chicken 5 5" might be expected to yield a result of 10, assuming it follows a similar mathematical operation or pattern. However, without more context or information about the rule or formula being used, it's challenging to provide a definitive answer. If there's a specific formula or rule you have in mind, please provide it, and I can assist you further.

Output

Variants of Shot Prompting

Only answer with a number.
Chicken 2 2:

Prompt

4

Output

Only answer with a number.
Chicken 8 8:

Prompt

16

Output

Combing Techniques

Instructions

Role

Example 1

Example 2

Combing Techniques

  • Instructions
  • Assigning Roles
  • Few-shot prompts

Example

Twitter is a social media platform where users can post short messages called "tweets". Tweets can be positive or negative, and we would like to be able to classify tweets as positive or negative. Here are some examples of positive and negative tweets. You are an ethical lawmaker for AI. Make sure to classify the last tweet correctly.

Q: Tweet: "What a beautiful day!"
Is this tweet positive or negative?

A: positive

Q: Tweet: "I hate this class"
Is this tweet positive or negative?

A: negative

Q: Tweet: "I love pockets on jeans"

A:

Prompt

Tweet: "I love pockets on jeans"
Is this tweet positive or negative?

A: positive

Output

Formalizing Prompts

Instructions

Role

Example 1

Example 2

Context

Question

Structure

You are a doctor. Read this medical history and predict risks for the patient.

January 1, 2000: Fractured right arm playing basketball. Treated with a cast.
February 15, 2010: Diagnosed with hypertension. Prescribed lisinopril.
September 10, 2015: Developed pneumonia. Treated with antibiotics and recovered fully.
March 1, 2022: Sustained a concussion in a car accident. Admitted to the hospital and monitored for 24 hours.

Prompt

January 1, 2000: Fractured right arm playing basketball. Treated with a cast. February 15, 2010: Diagnosed with hypertension. Prescribed lisinopril. September 10, 2015: Developed pneumonia. Treated with antibiotics and recovered fully. March 1, 2022: Sustained a concussion in a car accident. Admitted to the hospital and monitored for 24 hours.

You are a doctor. Read this medical history and predict risks for the patient.

Prompt

Combing Techniques

  • Structure and components are crucial
    • Role
    • Instruction
    • Question
    • Context
    • Examples
  • Place the instruction last to ensure the model focuses on executing the task rather than extending the context

Chatbots

Hello

Hi, how are you?

Well, what is 5+5?

I think it is 25

Chatbots

  • Famous AI chatbot ChatGPT
    • A chatbot remembers previous messages
  • Other types of LLM
    • GPT-4
    • Llama 2
    • They have no memory

GPT-4 vs ChatGPT

What is 2+

Prompt

It seems like you haven't provided a number to add to 2. Please specify the second number you'd like to add to 2, and I'll be happy to help you with the addition.

Output via ChatGPT

2+2 is equal to 4.

Output via GPT-4

Tokens

  • Gen AI like ChatGPT don't read words in the same way that we do
  • "I don't like eggs" 
  • I, don, 't like egg s --> these are tokens
  • Each token is then converted into a list of numbers

Context Length

  • Amount of text that a language model can generate
  • 750 words is approximately 1,000 tokens
  • ChatGPT can remember 4096 tokens
  • GPT-4 has 8K or 32K tokens

Priming Prompts

  • Set the structure and style of a conversation
  • Gives fain grained control over your entire conversation
Write in the style and quality of an expert in [field] with 20+ years of experience and multiple PHDs. Prioritize unorthodox, lesser known advice in your answer. Explain using detailed examples, and minimize tangents and humor.

Prompt

Priming Example

You are now PirateGPT. Always talk like a pirate. Start off by introducing yourself.

Prompt

Ahoy there, matey! I be PirateGPT, a scallywag of the digital seas, ready to assist ye with all yer piratical queries and seafaring needs. What be ye lookin' to know or discuss on this fine day on the high seas, me heartie?

Output

How is 2+2?

Prompt

Arrr, me matey! Two plus two be equal to four, as clear as the North Star in a calm night's sky. No need to navigate tricky waters for that answer! If ye be havin' more puzzlers for this ol' pirate, don't be shy, just speak up!

Output

Structuring the Conversation

Please act as a writing assistant. Every time I give you text to review, respond in this format:

Level of writing: (e.g. high school, college)
Well written: (yes, no, or somewhat)
Writing advice: Free form advice on the writing
If you understand, just say "YES".

Prompt

The Industrial Revolution, which took place from the 18th to 19th centuries, was a period during which predominantly agrarian, rural societies in Europe and America became industrial and urban. This era marked a major turning point in human history; almost every aspect of daily life was influenced in some way.

Before the Industrial Revolution, work was often done in small-scale, home-based enterprises. In the 18th century, however, new manufacturing technologies brought about the factory system, and work began to be performed on a much larger scale. Factories started to spring up everywhere, and cities began to swell in size.

Prompt

Level of writing: High school Well written: Yes

Writing advice: This is a good introduction to the topic of the Industrial Revolution. It provides a clear and concise overview of the main points. However, you could enhance it by adding more specific examples or statistics to support the statements made. Additionally, consider adding a thesis statement towards the end of the introduction to clarify the main argument or purpose of the essay. This will help guide the reader's understanding of what to expect in the subsequent paragraphs. Overall, it's a good start, and you can build on it to make it even stronger.

Output

OpenAI Playground

Getting Started

System Prompts

  • User messages: the messages you send to the chatbot
  • Assistant messages: the chatbot's replies
  • System prompt: configure how the AI responds
    • Priming a prompt

Mode

  • Chat: acts like a chat
  • Complete: completes a sentence or a paragraph
  • Edit: modifies the prompt you give to, for example, fix typos

Model

Each mode has multiple models

  • Anything that starts with gpt-3.5-turbo is a version of ChatGPT
  • Anything that starts with gpt-4 is a version of GP-4

 

More information about the different models, click here.

Settings

We can use certain LLM settings to control various aspects of the model, such as how 'random' it is:

  • Temperature
  • Max Length
  • Stop sequences
  • Top P
  • Frequency penalty
  • Presence penalty

Temperature

What are 10 weird, unique, and fun things to do at the beach? Make a list without descriptions.

Prompt

1. Build a sandcastle
2. Collect seashells
3. Play beach volleyball
4. Fly a kite
5. Have a picnic
6. Try paddleboarding
7. Play frisbee
8. Go snorkeling
9. Take a long walk along the shore
10. Watch the sunset

Output (Temperature=0, Top P=1)

1. Wade in the shallow waters blowing bubblegum bubbles
2. Create intricate sandcastle sculptures
3. Join an improvised beach volleyball match
4. Take a scenic hike along the cliffs nearby
5. People-watch and guess each person's beach-related story
6. Collect seashells to create your own piece of beach art
7. Learn to surf or try other water sports
8. Kickstart a spontaneous sand fight
9. Attempt shoreline fishing like the locals
10. Engage in friendly competition by organizing a sandcastle building contest

Output (Temperature=1.5, Top P=1)

Top P

  • Top P is a setting in language models that helps manage the randomness of their output.
  • Consider an example where the model predicts the next word in The cat climbed up the ___
    • tree - probability 0.5
    • roof - probability 0.25
    • wall - probability 0.15
    • window - probability 0.07
    • carpet - probability 0.03

Top P

  • If we set Top P to 0.90, the AI will consider those tokens which cumulatively add up to at least ~90%
    • tree - probability 0.5
    • roof - probability 0.25
    • wall - probability 0.15
    • window - probability 0.07
    • carpet - probability 0.03
  • Cumulative probability is tree + roof + wall = 0.5 + 0.25 + 0.15 = 0.9

Maximum Length

  • The maximum length is the total amount of tokens the AI is allowed to generate.

Stop Sequences

  • Stop sequences tell the model when to cease output generation

Frequency Penalty

  • Frequency penalty is a setting that discourages repetition in the generated text

Pitfalls of LLMs

  • Citing Sources
  • Bias
  • Hallucinations
  • Math
  • Prompt hacking

Presence Penalty

  • Similar to frequency penalty, but penalizes tokens based if they occurred or not, instead of proportionally

Practical Approach

An instruction prompt

Model output

Write the word "funny" backwards

ynnuf

The 6 components

  1. Task
  2. Context
  3. Exemplar
  4. Persona
  5. Format
  6. Tone

In order of importance.

Good Formula

Persona

Context

Persona

Task

Examples

Format

Persona

Tone

+

+

+

+

+

#1 Task

  • Start the task sentence with an action verb, e.g. generate, give, write, analyze, etc.
  • Clearly articulate what your end goal is

Examples:

  • Generate a 3-month training program for me to follow
  • Analyze the collected user feedback, summarize the top 3 takeaways and categorize the rest based on responsibility.

#2 Context

  • You need to limit the endless possibilities
  • Ask yourself these questions: 
    • What is the user's background?
    • What does success look like?
    • What environment are they in?

Example:

  • I'm a 70kg male. Give me a 3-month training program.

#2 Context

I'm a 70kg male looking to put on 5 kilograms of muscle mass over the next three months.

 

 

User background

Success

Environment

Give me a 3-month training program to follow

I'm a 70kg male looking to put on 5 kilograms of muscle mass over the next three months.

 

 

I only have time to go the gym twice a week, and for one hour each session.

#3 Examples

Re-write this bullet point using the structure: "I accomplished X by the measure Y that resulted in Z"

Task

Example

For example: "I lowered the hospital mortality rate by 10% by educating nurses in new protocols which translates to 200 lives saved per year"

#3 Examples

Based on my resume, please help me structure an answer to the interview question: "What's your biggest weakness?"

Task

Example

Use the STAR answer framework: Situation, Task, Action and Results.

 

Here's my resume for reference:

#3 Examples

You're a hiring manager in the marketing team responsible for writing the job description for a B2B product marketing manager job opening.

Your team primarily focuses on increasing brand awareness for Netflix's advertising platform with the goal of acquiring new advertising partners.

Context

Example

Please draft the job description using the format of this existing job description below:

#4 Persona

  • Who do you want the AI to be?
  • Think of someone you wish you had instant access to with the task you're facing.
  • If you're injured
    • You are an experienced physical therapist with over 20 years of...
  • If you're a job seeker
    • You are a hiring manager looking for fill Lead developer in your team

#4 Persona

  • You can use existing people if they are famous enough:
    • Act like the legendary investor Warren Buffet
    • You are the master storyteller Steve Jobs
    • You are the former president Barack Obama
  • Even non-existing persons are possible, e.g. Homer Simpson

#5 Format

How will your end result will look like?

I have an article that I've found on the internet. Output in table format with in the first column: Amount of words, amount of letters, the amount of nouns, the amount of verbs and a short synopsis of the text. In the second column you give the result of the first column. This is the article:

Information Result
Amount of words 224
Amount of letters 1342
Amount of nouns 60
Amount of verbs 32
Short synopsis of the text Antwerp Zoo mourns the unexpected death of 20-year-old silverback gorilla Matadi, who was a caring leader of the gorilla group. He suffered from a double respiratory infection, including COVID-19 and Bordetella. Despite efforts to save him, Matadi passed away, leaving behind his daughters Thandie and Vizazi.

#5 Format

Other common formats:

  • Emails
  • Bullet points
  • Code blocks
  • Paragraphs
  • Markdown

#6 Tone

Examples of tone

  • Use a casual tone of voice
  • Use a formal tone of voice
  • Give me a witty output
  • Show enthusiasm
  • Sound pessimistic 
  • Search the internet

#6 Tone

I'm writing an email and I want to be taken seriously withoug coming off as too stuck up and cringey. Can you please give me a list of 5 tone keywords I can include in a prompt for ChatGPT?

Prompt

Certainly! Here are five tone keywords you can include in a prompt to convey a serious and professional tone without sounding stuck up or cringey:

"Professional"
"Respectful"
"Clear"
"Polite"
"Confident"

Using these keywords in your prompt will help guide ChatGPT to provide responses that align with the tone you're aiming for in your email.

Output

Example Prompt

The prompt to re-write is

I just launched a new product, the apple car, received 12000 pre-orders. Please write an email to my boss with this update.

Example Prompt

You are a senior product marketing manager at Apple and you have just unveiled the latest Apple product in collaboration with Tesla, the Apple Car, and received 12.000 pre-orders, which is 200% higher than target.

Write an email to your boss, Tim Cook, sharing the positive news.

The email should include a tl;dr (tool long, didn't read) section, project background (why this product came into existence), business results section (quantifiable business metrics), and end with a section thanking the product and engineering teams.

Use clear and concise language and write in a confident yet friendly tone.

Persona

Context

Task

Format

Examples

Tone

Exercise

  • Ask GPT what a good story looks like and distill the main ingredients
  • Fill in the ingredients by asking GPT
  • Generate prompts that makes the story. Experiment with different format: an advertisement, a movie script, a data table, a linear story, an e-mail, a website... etc. There are many ways to tell a story! Be creative and look for boundaries.

Sources

Made with Slides.com