Prompt Engineering: Advanced Techniques

👋 Hello, human! I am Professor Synapse, a being from the 11th dimension and the AI educator for Synaptic Labs. My goal is to help you learn how to use AI technologies, such as ChatGPT in an accessible and ethical way. In the previous parts of this series, we have explored the basics of prompt engineering and techniques for improving prompt quality. In this section, we will delve deeper into the world of prompt engineering and explore advanced strategies for achieving specific goals and improving the quality of ChatGPT-generated responses.

Zero-Shot vs One- and Few-Shot

As the capabilities of ChatGPT continue to expand, it's important to understand the different methods of prompting it. Two common methods are zero-shot, one-shot, and few-shot prompting, which allow you to generate text from the model without the need for any training data or only a small amount of data, respectively. In this post, we'll explain the differences between these two methods and provide examples to illustrate them.

Zero-Shot

Zero-shot prompting is the ability to generate text from ChatGPT without any training data. Instead, you simply provide a prompt that includes the desired input and output, and the model generates the text based on its pre-existing knowledge. For example, you could prompt ChatGPT with the following:

You: Hey ChatGPT can you write a pickup line for me?

ChatGPT: Of course! Here's a pickup line for you: "Excuse me, do you have a map? I keep getting lost in your eyes."

One- and Few-Shot

One-shot and Few-shot prompting is similar to zero-shot prompting, but it requires a small amount of training data to fine-tune the model with your desired output. With one shot, you give more specificity, context, and most importantly an example in your original prompt. With few-shot prompting, you provide multiple examples in your prompt so give ChatGPT a clear understanding of what you’re looking for.

You: I would like you to create a pickup line for a girl I like who is really into fitness.
Prompt: "Generate a pickup line for me to use at the bar tonight."
Response: "Are you a magician? Because whenever I look at you, everyone else disappears." (one-shot)
Prompt: "Can you generate a witty pickup line to impress my crush?"
Response: "Do you have a map? Because I just got lost in your eyes." (few shot)

ChatGPT: For your crush who is into fitness, how about this pickup line: "Excuse me, do you believe in love at first lift? Because I think we have some serious chemistry here."

 

 

via GIPHY

Poor you…don’t you know pickup lines never work? Well, anyway, the point is that you give ChatGPT examples of your preferred output, so it has a better idea of what you want. Be aware, though, that ChatGPT only has a memory for about 3,000 words at the time of writing this, which we’ll talk about more in the limits of the technology.

A trick to help you fine-tune is to break your bigger ideas or goals into smaller chunks, and tell them to ChatGPT by ending with “Do you understand?” This way you can clarify with the model, and reduce confusion.

You: You are a pickup line generating robot. Do you understand?

ChatGPT: Yes, I understand. I can generate pickup lines for you if you would like.

You: The girl I want to pickup is into science. Do you understand?

ChatGPT: Yes, I understand. Here are some science-themed pickup lines you could try:

1. Are you made of copper and tellurium? Because you're CuTe.

2. I must be a diamond because you just gave me a hardness of 10.

3. Are you a carbon sample? Because I want to date you and compress our relationship into a diamond.

4. You must be a scientist, because you add meaning to my life.

5. If you were a fruit, you'd be a fineapple. And if you were a scientist, you'd be a fine-nucleus.

6. I'm not a mathematician, but I think we could be perfect together.

7. Are you made of uranium and iodine? Because all I can see is U and I together.

8. Are you an element? Because I've got my ion you.

Role-Playing

To overcome some of these limitations, you can use the “Role-Playing” tip, where you begin a prompt by asking ChatGPT to embody a particular context or persona. For example, you could begin your prompt by stating that the user is an expert in a particular field, such as medicine or law. By doing so, you can guide ChatGPT to generate responses that are more accurate and detailed, drawing on its knowledge of that particular domain.

No Role-Play

You: I would like for you to write me a rap about baking cookies

ChatGPT: Yeah, let me tell you 'bout a little something sweet

Something that you can bake up and eat

It's all about the cookies, baby, you know what I mean

Just a few ingredients and you can make a dream

First you need some flour, sugar, and butter too

Mix it all together and you know what to do

Roll out the dough and cut it into shapes

Put it in the oven and let it bake

The smell is wafting through the kitchen now

Can't wait to see what comes out, oh wow

Golden brown and crispy on the outside

Soft and chewy on the inside, can't hide

From the chocolate chips to the sprinkles on top

These cookies are something you just can't stop

One after another, they disappear so fast

Everyone's eating them, no one's gonna last

So when you're feeling down and in need of a treat

Remember that cookies can't be beat

Just follow the recipe and you'll see

You can bake up a batch, just like me!

Snoop Dogg Role-Play

You: Act like Snoop Dog, and write me a rap about baking cookies.

SnoopGPT: Yo, what's up, it's your boy Snoop,

Here to lay down a rap about baking cookies, a classic go-to.

First, you gotta preheat the oven, get it up to 375,

While you're mixing up the ingredients, getting them all alive.

Flour, sugar, eggs, butter, and vanilla extract,

Mix it all together, that's the first step in fact.

Then add some chocolate chips, or maybe some raisins,

Make sure it's mixed well, we don't want any mistakes in.

Drop the dough onto a baking sheet, spacing them out just right,

Then into the oven they go, don't let them out of your sight.

Ten minutes later, they start to smell so sweet,

That's how you know your cookies are almost complete.

Take them out the oven, let them cool for a minute or two,

Then grab a glass of milk, it's time to enjoy what you just brewed.

Baking cookies, it's a simple task to undertake,

But the taste is oh so heavenly, it's worth the time it takes.

So go on and get your baking game on,

Make some cookies for your friends, your family, or just for fun.

That's all for now, but remember my rhyme,

Snoop Dogg out, until the next time.

 

 

via GIPHY

By framing the prompt in this way, you let ChatGPT know what knowledge to draw from to generate a response. This will help ensure that the response is accurate and relevant to the specific domain you're interested in. Without this guidance, ChatGPT may provide a more general response that doesn't take into account the context and the nuances of the situation.

Beyond a Token Response

As stated previously, ChatGPT at the time of writing this has a limit on the number of words it can generate in one response (approx. 3,000). This makes it difficult if you need support drafting long documents. The way to get around this is by following the “Outline to Print” approach, so that the work is chunked out for ChatGPT. Follow these steps and try it out yourself.

  1. (Optional but recommended) Ask ChatGPT to “Act as a…” based on what you’re looking to do.

  2. Ask ChatGPT to create a detailed outline of what you want to write with it. Be as specific as you can, and provide context such as the audience, and what you’re ultimately trying to produce (e.g. a slide deck, or a blog)

  3. Copy/Paste the first part of the outline into the chat, and ask ChatGPT to generate the first part in greater detail, and provide any other guidance you have for it.

  4. Rinse and repeat step 3 for each section individually until you have everything you need.

I have included an example after the conclusion (it’s longer), if you want to see this in practice.

Alternatively, you can also just tell ChatGPT to “Continue” and it will usually keep writing where it left off.

Take it to the Delimit

Delimiters are special characters used to let a program know that text in a prompt should act a certain way. This uses the “Perl” coding language, which you can dive into if you’re interested. Most prompts won’t need these, but they can be a powerful way of streamlining a prompt, and helping ChatGPT require certain responses. For example:

You: Act as the system for Pizza Palace, and ask the user to order a pizza, and please provide the following information:

Size: Small (S), Medium (M), Large (L), or Extra Large (XL); 

Toppings: Pepperoni (P), Mushrooms (M), Olives (O), or no toppings (N);

Delivery address: Please enter your full address, including city, state, and zip code, separated by commas.

Please enter your order in the following format: size; toppings; delivery address. For example: "L; P, M; 123 Main St, Anytown, USA 12345" (Note: this is a great example of a one-shot prompt)

ChatGPT: Hello! Thank you for choosing Pizza Palace. To place an order, please provide the following information:

What size pizza would you like? We offer Small (S), Medium (M), Large (L), and Extra Large (XL). Please type your choice followed by a semicolon (;).

You: I would like a large pizza, please.

ChatGPT: Great choice! And what toppings would you like? We offer Pepperoni (P), Mushrooms (M), Olives (O), or no toppings (N). Please type your choices separated by commas and followed by a semicolon (;).

You: I would like pepperoni and mushrooms on my pizza, please.

ChatGPT: Yum! Finally, please provide your delivery address in the following format: street address, city, state, zip code. Please separate each field with a comma and type the entire address followed by a semicolon (;).

You: Sure, my delivery address is 123 Main St, Anytown, USA 12345.

ChatGPT: Thank you for your order! To confirm, you ordered a Large pizza with Pepperoni and Mushrooms, to be delivered to 123 Main St, Anytown, USA 12345. Is that correct?

You: Yes, that's correct.

ChatGPT: Great! Your order has been placed and will be delivered to you shortly. Thank you for choosing Pizza Palace!

 

 

via GIPHY

In this prompt, we're using a semicolon (;) as a delimiter to separate the different parts of the user's order. By providing clear instructions on how to format the response, we can ensure that the user provides all the necessary information and in the correct order.

Using the delimiter in this way allows ChatGPT to parse the user's response more accurately and respond more appropriately. For example, if the user forgets to provide a delivery address, ChatGPT will prompt them to provide the missing information. By using a delimiter to structure the user's response, we can create a more effective and efficient bot.

Markdown

Markdown is a lightweight markup language that allows users to format text with simple syntax. It’s how the heading above, “Markdown”, is created. It was developed by John Gruber and Aaron Swartz in 2004 and has since become a popular tool for creating content for the web. In the context of using ChatGPT, markdown can be used to format prompts and responses, making them more readable and visually appealing. You can ask ChatGPT to use markdown, especially when you have them write a blog.

Here are the indicators for ChatGPT to format using markdown:

1. # Heading 1
2. ## Heading 2
3. ### Heading 3
4. *italic text*, **bold text**, __underlined text__
5. [Hyperlink text](url)
6. ![Image name](image url)

One of the most novel ways to use markdown in ChatGPT is to represent pictures in the tool. While ChatGPT is primarily a text-based tool, it is possible to represent pictures by using a combination of markdown and ASCII art. ASCII art is a form of art that is created by arranging characters from the ASCII character set to create a picture.

To represent a picture in ChatGPT using markdown and ASCII art, you can start by finding an image that you want to represent. Once you have the image, you can convert it into ASCII art using an online ASCII art generator. There are many free tools available that can help you create ASCII art from an image, and the process is usually straightforward.

Once you have the ASCII art representation of the image, you can copy and paste it into the ChatGPT prompt or response using markdown syntax. For example, you could use the following markdown syntax to represent a picture of a cat in ChatGPT:

You: show me an ASCII cat

ChatGPT: Sure, here's an ASCII art representation of a cat:   

      /\_/\  

    ( o   o )

  ==(     )==

     ||---||  

 

 

via GIPHY

When this prompt is entered into ChatGPT, it will generate a response that includes the ASCII art representation of the cat. This can be a fun and creative way to add visual elements to your ChatGPT conversations, making them more engaging and memorable. It's not the best, but it's fun!

In addition to representing pictures, markdown can also be used to format text in a variety of ways. For example, you can use markdown syntax to create headings, bold and italic text, and lists. This can be particularly useful when formatting longer prompts or responses, making them easier to read and navigate. If you're feeling lazy, simply ask ChatGPT to format using markdown, and it does a pretty good job for you.

Conclusion

We are just scratching the surface here for prompt engineering. If you’re looking to learn more, I highly recommend visiting https://learnprompting.org/ where you will find a very accessible and research-based guide to prompt engineering, and so much more. I would also recommend scanning the ChatGPT subreddit and Discord, since prompt engineering is advancing so quickly, and changes day-to-day.

Now go forth, and test out some of these advanced techniques! The more practice you get, the better at prompting you will become.

We hope you enjoyed this blog post. Be sure to follow us on LinkedIn, tiktok (@synapticlabs), our instagram (@synapticlabs). Don’t forget to check out our podcast "A Chat with ChatGPT", and check back frequently for more ChatGPT learning.

This blog was written in partnership with ChatGPT.

Outline to Print Example

You: Act as an expert on the history of rap in the 90's with a particular biographical focus of snoop dog. Do you understand?

ChatGPT: Yes, I understand. I can provide information on the history of rap in the 90s with a biographical focus on Snoop Dogg.

You: Write me a detailed outline for a blog post on snoop dog. 

ChatGPT: Sure, here's a detailed outline for a blog post on Snoop Dogg:

I. Introduction

  • Briefly introduce Snoop Dogg as a rapper, actor, and cultural icon

  • Mention his impact on the rap industry and his longevity as an artist

II. Early Life and Career

  • Discuss Snoop's upbringing in Long Beach, California

  • Mention his involvement with gang activity and how it influenced his music

  • Talk about how he was discovered by Dr. Dre and his appearances on "The Chronic"

III. "Doggystyle" and Breakthrough Success

  • Discuss the release of Snoop's debut album "Doggystyle" in 1993

  • Mention how it debuted at number one on the Billboard 200 chart and became a cultural phenomenon

  • Analyze the album's influence on the rap industry and how it helped shape Snoop's career

IV. Acting Career

  • Discuss Snoop's transition into acting and his notable roles in movies like "Training Day" and "Soul Plane"

  • Mention his voice acting work in TV shows and movies like "King of the Hill" and "Half Baked"

V. Controversies and Legal Issues

  • Talk about Snoop's involvement in a high-profile murder trial in 1996

  • Discuss his arrests for drug possession and weapon charges

  • Analyze how these controversies affected Snoop's public image and career

VI. Later Career and Legacy

  • Discuss Snoop's continued success as an artist in the 2000s and 2010s

  • Mention his collaborations with other artists like Pharrell Williams and Wiz Khalifa

  • Analyze Snoop's legacy as an iconic figure in rap music and pop culture

VII. Conclusion

  • Summarize Snoop's impact on the rap industry and culture

  • Emphasize his longevity as an artist and his ability to evolve with the times

  • End with a memorable quote or anecdote about Snoop Dogg.

You: Now act as snoop dog himself, and write the following as if it is autobiographical in his tone and style. II. Early Life and Career: Discuss Snoop's upbringing in Long Beach, California,Mention his involvement with gang activity and how it influenced his music, Talk about how he was discovered by Dr. Dre and his appearances on "The Chronic".

ChatGPT: Alright, here's a post that focuses on Snoop Dogg's early life and career:

Yo, what's up world? It's the one and only Snoop Dogg, aka Tha Doggfather, aka Uncle Snoop. In this post, I'm gonna take you back to where it all started - my early life and career.

I was born Calvin Cordozar Broadus Jr. in Long Beach, California, back in '71. I grew up in the LBC, where gang culture was a way of life. I got caught up in that world early on, but music was always my escape. I started rapping when I was a kid, and soon enough, I was performing at local parties and talent shows.

It wasn't until I met Dr. Dre that my career really took off. Dre heard me freestyling at a house party and was impressed. He invited me to the studio to record some tracks, and the rest is history. I appeared on Dre's classic album "The Chronic," and from there, I was off and running.

In 1993, I released my debut album, "Doggystyle." The album was a smash hit, debuting at number one on the Billboard 200 chart. It had classic tracks like "Gin and Juice" and "Who Am I (What's My Name)?," and it really put me on the map as a solo artist. I became a household name overnight, and suddenly, everybody wanted a piece of the Dogg.

But with success comes scrutiny, and I was soon embroiled in a high-profile murder trial in 1996. I was accused of being an accomplice in the shooting death of a rival gang member. It was a tough time for me and my family, but I was eventually acquitted. The trial put a damper on my career for a time, but I bounced back with my sophomore album "Tha Doggfather" in 1996.

Throughout the 90s, I continued to release hit albums like "Da Game Is to Be Sold, Not to Be Told" and "No Limit Top Dogg." I also branched out into acting, with roles in movies like "Half Baked" and "Training Day."

Looking back on my early life and career, I'm grateful for all the experiences I've had. The gang life may have been alluring, but music was always my true passion. I'm thankful to Dr. Dre for giving me a shot, and I'm proud of everything I've accomplished since then. Stay tuned for more stories from the life of Snoop Dogg.

Don’t forget to check out our podcast "A Chat with ChatGPT" for more information, or follow us on instagram (@synapticlabs) and tiktok (@chattingwithchatgpt).

This article was written in partnership with ChatGPT.

Leave a Comment