Lesson Description

The "One-Shot Prompt" Lesson is part of the full, Practical Prompt Engineering course featured in this preview video. Here's what you'd learn in this lesson:

Sabrina compares one-shot prompting to zero-shot. With one-shot prompting, one example is provided with the request. The model learns the pattern, format, and style from the example, which establishes the format for future requests.

Preview
Close

Transcript from the "One-Shot Prompt" Lesson

[00:00:00]
>> Sabrina Goldfarb: Let's talk about the next type of prompting, and here's where stuff is starting to get interesting. We're going to be talking about one-shot prompting. When LLMs fall short in zero-shot prompting, we are going to pull out the slightly bigger prompting guns, and we are going to say we need to prime the model. We need to train the model a little bit. So we're going to start to add what are called shots.

[00:00:33]
One-shot prompting is providing exactly one example with your request. Zero-shot prompting was providing zero examples with our request. One-shot prompting is providing exactly one example with our request. From this example, the model learns the pattern, the format, and the style, right? So we give it pattern, we give it format, we give it style, we prime, and we train the model. And you might say, well, the model is trained on billions of parameters of data, you told me.

[00:01:08]
So this one example isn't going to mean anything, but it does. And the research shows it does, and we'll take a look at that in a little bit when we talk about some other prompting examples. But priming the model for this and giving it the ability to learn the pattern and the format and the style from this example can be extremely helpful. Again, this is very useful for establishing a format, right?

[00:01:35]
So if I want to have the model think in a certain way, then I can provide it with an example of thinking in that direction. If I want to get an output in a certain direction, I can provide the model with an output example in a certain direction. I am establishing some kind of format for that model, and at the bottom you'll see it says show don't tell. What does that mean? I can just as easily use a zero-shot prompt as a one-shot prompt and do the same thing, right?

[00:02:07]
I can give a whole paragraph of make sure you do this and don't do this, and add this and make it look like this and all this other stuff, but isn't it so much easier to just give an example of what I want my output to mimic? Let's say that I am in the real world right now. I mean, I am, I guess technically, right? But let's say that we're sitting at my job right now and I'm pair programming with somebody, and I want them to create a new API.

[00:02:37]
Would it not be easier for them to create an API that fits my codebase's standards if I show them a piece of prior art, of a piece of the codebase that does the exact same thing I want it to do, or I want them to do, but all they have to do is change around a few things to get there. Right? If I'm talking to a junior engineer at work and I'm like, hey, create a new API and make sure when it touches the database that it does this, that or the other thing, that's fine.

[00:03:09]
But if I say, hey, junior engineer, create a new API that touches the database and gets this information, here's an example of something else that does something similar. All of a sudden their output is going to look a lot more similar. It's going to follow that prior art of the codebase the same exact way, and LLMs will follow those instructions. So it's a really good way to get just more consistent outputs like we want, which is what we've been talking about all day, right?

[00:03:38]
Notice for one-shot prompting, we only have one example, so it is important that we're not trying to think of every edge case, and we're not providing an edge case to the model. We want to provide the model with a generalized case, our best general case, right? We want this to be better than zero-shot because we want the model to understand our full intent, but we're also not going so deeply into it that we're covering every edge case and everything in between.

[00:04:09]
This is really great if we're working with straightforward transformations, if we're trying to work very quickly and we don't have the time to be like, what edge cases can hit here, what errors can hit here, but we just like, we need to work quickly, we need to build. But here's an example to go off of, let's just do it, right? It's still more helpful than providing nothing to the model, which we saw in a zero-shot prompt.

[00:04:37]
We're providing instructions, but no examples, nothing that it can really hold on to. Some pro tips for one-shot examples are to choose your example really carefully because it does set the pattern, right? So make your example the majority representative, don't pick an edge case. Include all of the elements that you want in your output. If you are trying to provide JSON as your output, and you don't provide three or four different keys, right?

[00:05:06]
The model isn't going to know that you want those, so provide every element that you really want within your example. Combine it with any explicit instructions you need for any additional clarity on the example. This is a general case or maybe not every answer will have these fields, right? These fields are optional. Provide it with some additional clarity in your instruction. But don't use an overly complex example as your example.

[00:05:38]
Like we said, the model is going to very much generalize this as a pattern. So just make sure that you're giving it the very general case and not like the most overly complex case you can think of, because the model might generalize all of that as the pattern. Okay. So, I am going to show us a couple of examples of this in Claude chat. Okay, so we're back to creating our AI applications, right? So maybe we want to create an AI application that helps with content creation, right?

[00:06:22]
So let's say, write an engaging introduction for a blog post about remote work productivity. All right. And I'm sure that we've all written blog posts before or seen on LinkedIn other people write blog posts that were like, for sure, these are AI generated. Well, hopefully, by adding a single shot to these examples, maybe we can make it sound just a little bit less like Claude wrote this for us. So, here's our example.

[00:06:49]
We're going to give it a topic and the topic that we had written about was benefits of morning exercise. Obviously, this was not something that I normally do. No, I'm just kidding. But this would be like a typical topic, right? I'm not a big morning exerciser, to be honest. Picture this. It's 6 a.m. Your alarm goes off. And instead of hitting snooze, and that's how you know this is not me writing about personal experience because I always hit snooze, you lace up your sneakers.

[00:07:45]
Sound impossible? Here's the thing. This is almost done. Those who exercise before breakfast report 23 percent higher energy levels throughout their workday. Okay. Now, write an introduction for remote work productivity tips. So we can see that now we've provided Claude with one-shot, right? One example. This is truly an identical example of really what we wanted, right? We're saying we want verbatim, something that sounds like this.

[00:08:27]
This is a prior piece of the artwork that we have written. Take this example and give us something new. So let's see what Claude came up with for our introduction. Picture this, you're working from home in your pajamas, coffee in hand, when you realize it's 3:30 p.m. And you've accomplished exactly one load of laundry. Sound familiar? Here's the thing, remote workers who implement just three key productivity strategies report completing their tasks 40% faster than their office-bound counterparts, all while maintaining a better work-life balance.

[00:09:06]
The secret isn't working harder or longer hours from your home office. It's about working smarter with the right systems in place. Okay, so, sure, Claude stole a little bit of my genius when it came to the beginning of the introduction. I'm just kidding, of course, it wasn't genius, but you know, we can see that it might need a little bit of tweaking if we were to publish this, just to not have the repetition or the repetitive nature, or maybe that's our thing, and we really like starting all of our blogs with picture this.

[00:09:38]
But we can see that now this tone and this vibe has actually been copied. We can see that I said in mine, people that exercise before breakfast report 23% higher energy levels, and you'll notice that now Claude has given that people report their tasks are 40% faster, so we can see that Claude has generalized this pattern extraordinarily well, given that it was just one very short example. We now have some percentages in there, right, to give us some confidence when people are reading about this.

[00:10:13]
We can see that he started with the same super quippy intro of you're working from home in your pajamas, coffee in hand when you realize this, and it kind of starts with that like you can't do it. Yes, you can, you know, that same kind of vibe, right? So we can see that these one-shot prompts are really good at generalizing some behavior, and this is also the same when it comes to code. So, let's take a look at one more very short one-shot prompt.

[00:10:55]
Maybe we want to run an AI application that recommends new movies to our users, right? So, recommend a movie based on viewing preferences. And then we'll say example. User likes Inception, The Matrix, and Interstellar. Right, and then the recommendation would be maybe Arrival and some other stuff. I don't know, we'll say. It's a movie. Arrival, we'll just say Arrival, we'll just have one. Perfect.

[00:11:45]
And then we can say, okay, so now our user likes, we'll say The Grand Budapest Hotel, Amélie, and The Secret Life of Walter Mitty. Okay, so now Claude has said, based on your love of whimsical, visually stunning films with quirky characters and heartfelt storytelling, I'd recommend Midnight in Paris. I do want to point out, and I was hoping that this would happen, that we didn't get consistent formats, right, when we did this.

[00:12:12]
If I go back to looking at this. We only got what we wanted, right? We wanted our blog posts, so it was convenient if we had built an AI application that said every morning, take this example and write a totally new blog post for us, right? How convenient. It just wrote it for us. But we can see one-shot prompting still isn't perfect because we didn't control our outputs very well. We got better outputs, more relevant outputs, because we were able to say, we like this, so we recommend this.

[00:12:41]
And of course I could have added more to the recommendation. I could have been like, you know, oh, because you like sci-fi and all this other stuff, right? Like very kind of focused, but we're still not controlling our output. And that is something that we will do later, but just something I want to note for right now, that you're going to have to combine some of these techniques if you really care about what your output is because maybe you're making an AI application where you're trying to pass answers from these models down to the next step in your application.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now