From the course: Introduction to Prompt Engineering for Generative AI

Few shot learning

From the course: Introduction to Prompt Engineering for Generative AI

Few shot learning

- [Instructor] Few-Shot learning is such an exciting technique because with little effort, you can start training a model to perform particular tasks. Let me show you what I mean. So when we build a prompt for Few-Shot learning, we start with some examples. And let's start with an example that begins with a paragraph about dogs with a few facts about them. Here we are told that they're mammals who bark and then we have a question and an answer that comes from the paragraph. Now, keep in mind the quality of samples is super important. It shows the model how we want it to behave. So here we see that it's a full answer and that it's from the paragraph. Next, we insert what's known as a stop sequence. And in many cases you will see two hashtags in a stop sequence because two hashtags in a row are not very common in writing. Next, we have another sample that follows the same template this time about Mount Everest followed by the same stop sequence. And after a few samples, we do something tricky. We give the model an example of a text about Earth and then we ask it a question and then we don't provide an answer or a stop sequence. So it says, if we are telling the model, what do you have to do before you can insert a stop sequence? And that would be following the template of previous samples. So if all these examples were answers not from the paragraph, perhaps the model would think we are trying to avoid things from the paragraphs. But since all of these answers are full sentences and all of these answers are from the paragraphs, it's likely that the model will pick something from the paragraph itself. Let me show you how this works with an actual model. So for this example, I'm using a very similar playground of a very similar model to GPT called G1 by AI21 Labs. And it's important for me to show you that there are various models out there that are extremely powerful. The Jurassic Model Series, which J1 belongs to, are slightly different than GPT. They have a different way of tokenizing, that is breaking things up into tokens. They also are particularly good at Few-Shot learning and tech summarization. Now let's take a look at this example. This is one of their examples. It's a customer service bot, and it can be found in the example section. You can browse by category Q&A and customer service bot. And you can try this in GPT3 as well. And the way you add stop sequences is using this stop sequence window. So if I didn't have this, I could do hashtag hashtag tab. And it's very similar in the GPT model. So here we have the user and the hashtag hashtag as a stop sequence. We have a few examples and let's see what the response will be for, hey there. Hey. And it has this like Shoe-La-La which is a imaginary brand, I presume. Customer service representative. What can I help you with? And you can create a conversation here. So I can say, can I buy some fabric shoes? Great. So you can see that the samples are here separated by stop sequences, and the user is another stop sequence. So you can see that the samples here provide a template for how this imaginary customer service representative is going to behave. Now, there are few limitations to using Few-Shot learning and one of them is that your prompts end up much larger meaning you're going to spend more money on tokens and you'll have fewer tokens left. As large language models have an upper limit of how many tokens you can insert. They're also extremely suitable for larger language models. Finally, they're a little bit less flexible. That is you kind of decide what it is your model wants to do and you can think of that as a good thing. In many cases, you don't want the Swiss Army knife that can do everything but not so well. You want something that can perform one task but with better execution.

Contents