================================================================= TITLE: Prompt Engineering 4 DATE: 2024-10-24 (October 24, 2024 at 04:02 PM) DURATION: 01:01:12 (3672 seconds) WORDS: 9,083 words SPEECH ID: 26XPVAWWHEJICAYF ================================================================= --- AI SUMMARY --- question refinement, large language models, improved questions, cognitive verifier, audience persona, flipped interaction, few shot prompting, sentiment analysis, driving scenarios, intermediate steps, pattern learning, output constraints, problem breakdown, audience tailoring, question generation --- FULL TRANSCRIPT --- [78:24:00] 0: A really simple way to improve our interactions with a large language model like chatgpt, is to use the question refinement pattern. So this is a really, really simple idea, and hopefully it'll inspire other ideas from view of patterns that you can use. But basic idea behind this is that we want chatgpt, or another large language model, whenever we ask a question to try to improve our question. So the fundamental sort of intent or idea behind this is that we may not have as much information or underlying thought behind our question as chatgpt has from its training data. So it may be able to infer patterns and other questions or words or things that are useful when asking questions on this particular topic or when trying to request something be done on a particular topic. So if you think about it, you know these large language models are trained on patterns and language. So if we give it maybe a more general question and ask it to refine it. It can use its knowledge of what other things are asked about in the context of the question we've given it, or what other words are typically associated with that type of question that might help improve our question, make it more specific, or provide additional context for other things. So sort of intuitively, what we're trying to do is we're using a sort of a general question, and we're tapping into the large language model's understanding of patterns and language around that topic of that question in order to create an improved version of it. Now the sort of pattern behind this is really, really quite simple. All we need to do is say whenever I ask a question, or you can give it some scope to this, just for the next question, or the next three questions, or whatever you want to do, you say something like whenever I ask a question, suggest a better question and ask me if I would like to use it instead. So this is just a really simple idea. We want to always try to have the best questions, best prompts to interact with the large language model. So we'll simply tell it, whatever I do ask or suggest a refinement. Now I'm going to show you kind of a little tweak to this. It's a really helpful tweak to know, which is we can say, whenever I ask a question, suggest a better question and ask me if I would like to use it instead. So this is kind of a nice little refinement that sort of helpful from a user experience perspective, because what we're doing now is, not only are we going to tell the large language model to create the question is better, but rather than requiring us to go and, you know, cut and paste it, or tell the large language model use the question you just generated. We just have it safe. You want to use this question instead. And if we say yes, it uses that question. If we say no, it should use our original question. So it's kind of a nice little, a little tweak to this pattern that can make it even easier to use. Now every time we ask a question, the large language model will go and try to improve it. So let's look at an example of this. So I'm going to start off with a generic question, which is, should I go to Vanderbilt University? Now if we look at this question, we can see it's really kind of ambiguous and vague. And if somebody was asking you this question, Should I go to Vanderbilt University, or as a faculty member? If somebody was asking me, should I go to Vanderbilt University? Not only is this a big decision for the person, but there's really not enough information at this point for me to make a decision. So a better question is going to help give me more information about the criteria that you're using to decide do these types of you know, what are the pros [1084:16:00] 0: and cons? How do you weigh them and decide if it's the right thing? [1096:15:59] 0: And that's exactly what we see chatgpt doing. Chatgpt says, Sure, here's a suggested question, what factors should I consider when deciding whether or not to attend Vanderbilt University, and how do they align with my personal goals and priorities, and then it says, Would you like to use this question instead? This is a really nice pattern, because once we've sort of turned it on, we can begin asking questions and automatically getting better versions of our question. And one of the things that's nice about this is it also helps us to reflect on what we're asking for, and if we see a question come back like this, like, what factors should I consider when deciding whether or not to intend to Vanderbilt University, and how do they align with my personal goals and priorities? Either we'll see that and see that's a really useful question, and that's how I [1320:10:40] 0: really would have phrased it [1324:42:40] 0: if I thought about it better or more but but sometimes [1342:08:00] 0: what we'll also see is that [1355:12:00] 0: the path that's taking down, taking us down, is not the one we want to go. And we'll realize there's lots of paths, lots of ways of answering the question, and we need to give some additional context. So not only is this useful in many cases of you know, getting a better question, but sometimes it's helpful to us to see that a question could be interpreted in many different ways. There's many different pieces of information that may be needed to make an effective decision, and so by seeing one version of a refined question, we'll identify missing pieces of information. So for example, if I really care about computer science at Vanderbilt, I might think, Oh, well, I should have mentioned that I'm planning on majoring in computer science, where, if the town that I'm going to be in when I go to college is really important, then I might want to say something about, you know, Nashville. And living in Nashville, you know, you want to make sure that you think through the question really effectively, and this is a pattern that can help us really hone in on producing better questions, learning from the refinements to the questions, and also using the questions the refinements to understand what's missing in the context that we might Want to introduce in order To get a better output you [1818:34:40] 0: an interesting property of large language models is that in many cases, they can actually reason better if they break a problem down into a bunch of smaller problems. So sometimes it can even reason better if they explain their thought process. Now, there's a number of sort of hypotheses about why this might be but I think intuitively we can think about, you know, a large language model may have seen particular problems broken broken down into a series of steps. So if it can go and follow the individual steps, and we'll know what to generate next in order to produce the output that's needed to solve a particular step. Now that's going to be discussed later in the course these ideas of breaking things down, but right now, we can actually tap into a simple technique, a simple pattern, to help us with automatically breaking things down to try to get better answers out of large language models, and a simple way to do that is just to ask the large language model to always take questions or problems and subdivide them into a series of individual questions or sub problems that could be useful in answering the overall question or in solving the overall problem. So we can simply program our large language model to do this. Now the cognitive verifier pattern is exactly for this purpose. What we're going to do is we're going to tell the large language model, whenever you're asked a question, follow these rules, generate a number of additional questions that would help more accurately answer the question, combine the answers to the individual questions to produce the final answer to the overall question. Now, again, sort of intuitively, we can think about this. If we have a generic question that we or some particular question that we ask large language model, it can go and tap into what it's seen, the patterns it's seen in the training data to see what are other questions that are often related to this question. So one it can help it sort of think about or collect from its knowledge base other questions that would typically be associated with that question, and when it's fine in these other questions, there are likely to be other questions that are relevant to that question will provide additional details or context to answer the question. And then when we go and give answers to all of those individual sort of sub questions, it's then going to have additional context to give us a better overall answer, and it also helps us as the users, to structure our thinking, because when we go and ask and it begins breaking questions down, it'll help us sort of realize what are additional dimensions to the problems. So let's take a look at this in practice. So here I am. I'm saying when you're asked a question, follow these rules, generate a number of additional questions that would help more accurately answer the question. Combine the answers to the individual questions to produce the final answer to the overall question. And chatgpt, in this case, says, Sure, I can do that. Just let me know what the question is, and I will generate additional answers. So let's see what we can start with. Well, I thought of a question that I have no way of easily answering and I don't know a whole lot about. So I figured by asking a question that sort of I'm guaranteed probably to ask a question that's too generic and doesn't have enough information, this will be helpful to me. And so I asked Chad chiquiti, how many mosquitoes probably live in my front yard? I don't know the answer to that question. I didn't think too hard about it, but I'm kind of interested, what is the answer to this? How would I even figure this out? And so I asked chatgpt That question. And so here's what it says. Well, it follows our prompt pattern, it follows the cognitive verifier pattern, and it generates a bunch of additional questions. Let's look at those questions, what is the size of your front yard? Well, obviously that's really important. If I have a bigger yard, I'm likely to have more mosquitoes. Probably, it's probably related to square footage in my yard. What is the climate like in your yard? That's obviously really important. You know, if I live in the desert or if I live at the North Pole, it's unlikely that they're going to be any mosquitoes. What time of year is another great question. You know, I didn't think about that dimension to it when I asked the question. But I'm probably asking the question when I'm, you know, in the spring or summer, when there's a lot of mosquitoes floating around in my yard, and it's driving me nuts, but I'm not thinking about I need to include time in my question as well. Are there any bodies of water or standing water sources in your front yard or nearby? Obviously, that's an important one, because mosquitoes breed in water, and I actually knew that, but I didn't include that information in my original question. And then, are there any plants or vegetation in your front yard that mosquitoes are attracted to? [3128:10:40] 0: That's another important one. So we see now [3140:10:40] 0: it's taken my original question and it's broken it down into a bunch of sub questions. They're going to help it answer the original question. This is really useful, and I've also learned something now to answer this, I'm just going to go back to go back to it, if you'll remember, it had a series of questions. Went through five I'm just going to go now and answer with one, about 2500 square feet. I honestly don't know, but I'm just sort of guessing my yard's not that big in the front yard. This is probably actually an overestimate of the size of my front yard. I live in the southeastern United States, it's April. I'm not telling it seasons or things. I'm just going to give it the month, which probably isn't specific enough. There's probably a difference between the date and different times [3350:13:20] 0: within April, even within where [3358:29:20] 0: I live. Then I tell it No, there's no standing bodies of water in my front yard. And yes, there are plants that likely mosquitoes would breed in. And so then it goes and says, based on the information provided, here's an estimate of how many mosquitoes living in your front yard. Then it gives me a number of things. It says, with a front yard size of 2500 square feet, according to some estimates, a single female mosquito can lay up to 300 eggs at a time. But it says in other things, and it kind of goes on to hedge its bets, which is a good thing, right? It says in general, or typical, mosquito population density in an area with standing water sources can range from 10 to 100 mosquitos per square meter. However, since there are no standing water sources in your yard or nearby, the density could be lower. And then it goes on to say it's difficult to provide a precise estimate. However, it's possible that there could be anywhere from a few dozen to a few 100 mosquitoes in your yard, depending on various factors as a species, climate in the presence of vegetation, that's pretty good. The fact that it's gotten us down to a few dozen to a few 100, that's a tighter range than I would have expected, and also just sort of sets my expectation. In the middle of summer when I go out in my front yard, I would swear it was in the 1000s. I'm absolutely dying as I'm eating alive on mosquitoes. And so I typically think it's a much higher number. But you know, based on this, it may be wrong, it may be erroneous, but it actually gave me a few fairly good reason. One of the things that's also nice about this is I'm less skeptical of its answer being completely wrong, because it asked me a bunch of reasonable questions to derive its answer. It also gave me a bunch of facts which I could go and follow up on, like, how many eggs of the whole mosquito leaf lay, the density of mosquitoes in areas with water. But it gave me kind of a pretty good answer, and it gave me a bunch of questions that I could ask to improve that answer. Now I'm going to go back. I'm going to actually qualify that. It said it said it gave me a pretty I said it gave me a pretty good answer, but the truth is, I have no idea. I'm not an expert on this topic, and as with anything that we get out of one of the large language models, I would highly encourage you to verify the output. But I think this is interesting, because at least at the very minimum, it helped me learn about through this question, what might influence the number of mosquitos in my yard, and give me things that I could do and follow up on and verify see if they're correct with these facts for water. See if these questions really are useful, but they certainly look like valid and important questions. What is the size of your front yard? I'm not sure that there's that. I even need to go research that a larger yard is likely to have more mosquitoes. What is the climate like in your yard? I know that that matters. What time of year is it [4148:21:20] 0: I know that that also matters. [4162:45:20] 0: Are there any bodies of standing water sources in your front [4173:41:20] 0: yard nearby? I know that matters [4187:06:40] 0: general knowledge in Southeast United States. And are there any plants or vegetation in your front yard the mosquitoes are attracted to, actually? So it's actually given me a bunch of really good questions. It's given me some facts related to those questions, which I would have to go verify and I don't know as much about but it is a really helpful tool for automatically taking a question, breaking it down. I can see sort of its reasoning about how it's going about thinking about this. It improves my reasoning about thinking about how I might answer this question. And in many cases, what we'll see is having a large language model break down the question will help it give a better answer to us, so that we'll get something that's more accurate. You [5325:14:40] 0: we discussed that the persona pattern and How we can use it to give the large language model all of this rich information about what it's supposed to do and what it's supposed to output. With a very little bit of work on our part, all we have to say is act as and it will know what it's supposed to do and how it's supposed to format and the types of things that it's supposed to incorporate into its output. Now, sometimes what we'd also like to do is we'd like to do the same thing, but rather than focusing on who the large language model is supposed to act like, we want to have the large language model produce an output for a particular persona. So this is called the audience persona pattern. The idea behind this is we want to tell the large language model you need to produce an output for this audience, persona, for this person or thing, so that it can think about how to tailor the output, and it will use its knowledge of the audience to make sure that it generates an output that is appropriate for that audience. So rather than saying, Don't do this or do this, or having a whole bunch of different rules describing what is and is not okay to go into the output, instead we say, this is the audience of your output. This is the audience persona. And so with the audience persona pattern, we can get a similar type of reasoning and ability out that we got from the act as this persona. Using the persona pattern, we can get that by saying, here's who you're providing the output to. This is the persona of the audience, in order to get intrastate outputs. So let me show you an example of so we're going to start with the example of large language models, which we've been studying in this course, and we're going to say, explain large language models and how they work to me, assume that I have no background in computer science. So we're giving it a persona of who I am. We're saying, assume that I have no background in computer science, and that's telling it who is the persona, who is the audience that I'm giving this information to. And so it says, Sure, let's start with the basics. And I want [5902:39:59] 0: to call out a just a couple of things. [5914:39:59] 0: It starts with a very sort of, you know, intuitive way of describing this, a large language model is a type of computer program that's designed to understand and generate human language. It's a bit like a virtual writer that can understand and create sentences in a way that sounds natural to humans. And so it's describing it. It's not describing it like you would to a computer scientist. It's describing it to be, you know, something that is accessible and approachable to anyone. Language models are used in many applications such as speech recognition, not machine translation and chat box. Now let's talk about large language models. The word large refers to the size of language model, and it goes on to describe it. And it says parameters are like adjustable knobs that the model uses to learn patterns in the language. So it's describing what a parameter is in a sort of accessible way. And it goes on and it talks about all the different steps and creatives. It did a good job, right? Assume that I'm not, you know, I don't have background in computer science, and explain it to me. And so it made sure in its explanation that it had the right information and then presented it at the right level working. [6237:09:19] 0: So let's go a step further. [6246:45:19] 0: Let's show you how interesting this could get. I'm going to, say, explain large language models and how they work to me, assume that I am Christopher Columbus, so notice now I'm giving it something completely different. I don't know how you would explain large language models to Christopher Columbus. So it's going to have to use and draw on information and its training data and patterns related to Christopher Columbus and history to try to figure this out, right? I'm giving it an audience persona that's a tricky one that I wouldn't know how to do easily. And it says, greetings, Christopher Columbus as an explorer of 15th and 16th centuries. You may not be familiar with the concepts of Computer Science and Artificial Intelligence, and I don't know how well this really works, but it's still pretty good that it's doing it. I'll do my best to explain [6492:31:59] 0: it. Best explain it, imagine that you have a magical scribe, [6516:05:19] 0: a being that can read, write [6524:05:20] 0: and understand many languages. This scribe has spent years reading countless books, scrolls and manuscripts from all over the world. It has learned from poets, scholars and storytellers. The magical scribe has a special ability. It can predict what comes next in a sentence. For example, if you say to the scribe, the ocean is vast, it might respond with mysterious completing your sentence in a way that makes sense. And so you can see how all we did is we said, you're going to explain the exact same thing, but you're going to assume, in the first case, that I don't have knowledge of computer science. And then we said, now you're going to assume that I'm Christopher Columbus, right? And so it completely changes how it describes large language models, [6749:03:59] 0: and it's actually doing a pretty good job. [6757:09:19] 0: So it's saying here, like Christ, Christopher Columbus doesn't know what a computer is, you know, Christopher Columbus, but maybe this concept of a magical scribe, right? And a magical scribe could be a concept that could make sense to Christopher Columbus. And then he's explaining how large language models predict the next word. He's saying the magical scribe studied all of these, you know, all of these scrolls and poems and different things, and learn to come figure out what is the next word in a sentence. And now we're going to use that magical scribe. We're going to talk to the magical scribe. So he's, you know, he's this, he's explaining, you know, that this scribe, like Christopher Columbus, you [6929:30:40] 0: know, as he's going to understand it as Christopher Columbus will, [6941:52:00] 0: will be able to look at the text and kind of understand that, like, okay, [6965:04:00] 0: you know, [6970:40:00] 0: I have this, this large language model, and now I've got this magical scribe, it kind of makes sense on what that means and like, how that would possibly work. [7015:59:59] 0: So now let's look at a third example. [7028:53:20] 0: We say, explain large, large language models and how they work. To me, assume that I'm a second grader that gets bored easily. And so again, we're giving a totally new persona, and we're also refining this persona. We're saying I'm a second grader, and here's some additional details about me. I get bored easily. And so now it goes and says, Okay, I'm going to tell you something super cool called a large language model. Imagine having a robot friend is really good at playing word games. This robot can finish your sentences, ask, answer questions and even tell you stories. Here's how it works, reading time. The robot friend loves to read. It reads lots and lots of books, websites and all kinds of things with words. And so it's explaining this concept of, you know, similar to as it explained to Christopher Columbus. You know, it sells Christopher Columbus. You know, the large language model is like a scribe. It's read all of these scrolls and poems and things like that. And now the large language model is explaining to the second grader. It's like a robot, and the robot loves to read. It reads books, websites and words, and so now it's switched up the description based on the persona of the audience, and then it goes on to describe all of the different aspects again. And you could go through and ask it, you know, to describe it in many different ways. So if we wanted to go back and we wanted to say, well, let's switch it up from a second grader, and let's say, assume that I am I only accept explanations in math. Thank and then we could say something completely different. So now it's saying, okay, language model is a probability distribution, and it's starting to give, trying to give a mathematical explanation of what a large language model is. And we can see that we're getting something completely different. And each time, we don't have to necessarily think through, well, you know, how would I explain this to Christopher lumbus, what would the rules be to describe how that output should look? We don't have to tell it what the output was should look like. We tell it who the audience is, the persona of the audience, and then we get all of that rich capability around it. So just like the persona pattern is really useful in tapping into large language model capabilities, the audience persona pattern is sort of the complement to it, and is also sort of an equally powerful thing that we can use to basically get really interesting and powerful output out of large language models. [7834:56:00] 0: You it. Sometimes we need the large [7946:18:40] 0: language model to ask us questions, to really guide the process of solving some problem that we have, or helping us obtain an answer or an output that we need, and we may not know what are all the steps to achieve that goal? And so what we really like to do is definitely have the large language model ask us questions. So whenever we want the large language model to ask us questions, the pattern that we can use is called flipped interaction. And so the idea behind this is, rather than we're going to flip the interaction, rather than us providing questions and the large language model providing answers, we're going to flip that, and we're going to have the large language model ask us questions and we're going to provide the answers. And we can do this in a number of different ways. We can do this to play games. We can do this in order to try to reach some goal, like the large language model keeps asking us questions until he gets enough information to achieve some goal. There's a variety of different ways that you can use this, but this is incredibly helpful when you don't necessarily know everything that's needed, or if you want to be tested or quizzed on something anywhere where you don't want to be in the driver's seat, you want to really be helping provide information, but you don't want to be formulating the questions or tasks. So let's take a look at an example of the Flipped interaction pattern. So the key to this is we start off by asking the large language model to ask me questions, and then we give it some topic that we're going to have it ask questions on. So ask me questions about fitness goals until you have enough information to suggest a strength training regimen for me. When you have enough information, show me the strength training regimen. Ask me the first question. Now this is the basic pattern, is you say, ask me questions on a particular topic, and then it's more helpful. Usually, if you give some goal, why are you asking the questions? Are you trying to have it quiz you? Are you trying to get a fitness regime, like we're in this one, and have a fitness plan. What is it you're trying to achieve? And the more information, the more context you can give about what you're trying to achieve, the better questions it'll be able to ask you. Now, other things you can do are, you can tell it how many questions to ask you, how many questions to ask at a time, a variety of different things, but one really handy thing you can do is end the Flipped interaction prompt with ask me the first question. So one thing that you often want to do is do it one question at a time. Now, sometimes you'd like to have like, 10 questions listed, and you can ask answer them. You know, one, here's my answer two, here's my answer three, here's my answer. And you can certainly do it that way if you want to get it all at once, and think about it all at once, but a lot of times I like to do it one question at a time. And so if you want to get that one question at a time, behavior, [8772:42:39] 0: usually a really reliable way of doing that is to say, ask me the first question at the end of the prompt. So we're going to generate this fitness plan. So we say, ask me the first question. And it says, Great. Let's get started. My first question is, [8838:40:00] 0: what are your specific fitness goals? [8849:03:59] 0: Are you looking to build muscle mass, increase strength endurance performance, or achieve a particular goal? And I go on to say, I'm looking to build explosive power and also prevent patellar tendinopathy from doing jumps on a mountain bike. Now I don't know if this is a correct pronunciation for the teller tendinopathy, but this is what I sort of looked up as the the the I've started to experience a pain in my knees at certain times when I've been doing a lot of jumps on a mountain bike. And so I looked it up, and this seems to be the reason for it. And so I'm providing that information because I don't necessarily know. Actually, I do know because as part of the reason I picked this one is I could fact check it a little bit against what I've read on the internet, but I wanted to generate a fitness regime for me. This is something that I've actually been doing, is figuring out what exercises I should do to help out, you know, my need and strengthen so it doesn't happen again. And then it asks, you know, do you have any current or past medical conditions or injuries that may affect your ability to participate? Additionally, you've been diagnosed with this, or are you looking to prevent it proactively? [9121:52:00] 0: And I give it some information, [9130:40:00] 0: and then it goes on and asks me, how many days per week I can dedicate and additionally, do you have any access to a gym or fitness equipment, I'm specifying, I can work out five days per week for 30 to 45 minutes at a time. And then we finally get to the point where it actually generates a full sort of fitness regime work of what I'm going to do to work on this. Now, what's really interesting is it's gone through, and it's taken into account the answers from my earlier questions. And I know that because I've been looking for what are good exercises to help work on this issue with my knee that I've been having, and these are exactly the types of things that you see recommended, like the goblet squat, the split squat is one that you see a lot of times, a lot of different types of squats and things are very helpful, and these are the types of things that I see. But it's also taken the overall context that I'm looking for weight training, it's gone and generated the entire weight training regime. Now notice at the very beginning, I said, when you have enough information, so I said, Show me the strength training regime. And so this kind of shows another important sort of power of this prompt pattern, this flipped interaction pattern, is we give it what we're trying to achieve and how much it should ask you. And basically we said the goal is, ask me enough until you have enough information to show me the training, and so it asks questions until it thinks it has enough information and then generates the output. Now, sometimes what you'll see when you ask questions to a large language model is it'll tell you, well, in order to do this, well, I need to get a bunch of additional information, or it might generate a generic initial, you know, plan, and then say, but if you provide additional details to me, I might also be able to do blah, blah, blah. And so what we what we see here is this is kind of getting rid of all that. Let's skip that step of getting something generic or being told that there's not quite enough information you need to answer questions for us. And let's just say, go ahead and ask us the questions that you need until you get there. Now this can also be used for doing other things like quizzing and playing games anywhere where we want to have knowledge in the large language model drive the creation of the questions. And this is really helpful when it has theoretically or been trained on knowledge or patterns in language that will be useful in creating the questions and are things that we don't possess ourselves. So whenever that's the case, he can probably go and more effectively think of questions. So if we say, Okay, I need a fitness regime patellar tendinopathy, I may not know. You know, what are the types of questions that you should ask somebody who has this you know, I may not know, what are the types of exercises that are commonly discussed if you have this condition, but it has been trained and seen patterns of language where when people were discussing this particular condition, these are the exercises that were discussed. These were the additional questions that were asked in order to select exercises. And it has access to those patterns from its training data to [10016:21:20] 0: then help it to [10020:05:20] 0: select good questions to design that appropriate training plan. So whenever you need the large language model to ask you the questions, where you can think about a customer service example, where you're trying to diagnose some problem that a customer has or automate some response, and you need to collect information and then take action, the Flipped interaction pattern is a really powerful prop pattern to use to do that. I [10311:06:40] 0: The really interesting thing that we can do in a prompt is we can actually teach the large language model to follow a pattern using something called few shot examples, or few shot prompting. So the idea behind this is we're going to give the large language model examples of input that we would give it and then the output that we would expect. And so you can imagine a human will go through and go through a couple of examples. So they'll give it some input, they'll show it what the correct output should look like. They'll then give it another input, give it the correct output. And the idea behind this is, is that we're developing a pattern that the large language model can then learn to follow. So actually, within our prompt, we're teaching the large language model a new trick. We're basically showing it what we want it to do and how we want it to format the output within a series of examples. So rather than describing the process we want it to follow, we're giving it examples of what we want it to do, and then hoping that it will continue the pattern that we provide. So let's take a look at this. So if you'll see right here, we've got a simple example of few shot prompting. So the idea behind this is we start off with input, and you'll notice that our this is a common thing that you will see in few shot prompting is that you'll see a prefix applied to the lines. Now you can have all kinds of prefixes, and your prompts and your patterns don't have to just be input and an output. It could be a couple of different steps, and we'll look at that in a minute. But as we see here, we have an input, which is, the movie was a bit long, and what we're going to do is we're going to do what's called sentiment analysis. This just basically is try to analyze some comment about a thing and try to figure out what the user's sentiment was about it, like, were they positive about it? Did they think it was a good thing? Were they negative about it? Do they think it was a bad thing, or were they neutral? And we're just going to do a really simple example with sentiment analysis, where we're going to take some fake reviews of different things and then we're going to decide if they were positive, negative or neutral. So what we're doing, rather than saying, go and analyze these user comments and tell me if they are positive, neutral or negative. Instead, what we're going to do is give a series of examples. So we give the first example, which was the movie was a bit was good, but a bit long, and we say the sentiment was neutral, so it has some pluses and minuses. It was good, but it was too long. Then we have an example where we say input. I didn't really like this book. It lacked important details and didn't end up making sense. And then we say the sentiment was negative, and then we have another input where we say, I love this book. Was really helpful in learning how to improve my gut health, and the sentiment is positive. And then what we do is we're going to give it the thing that we actually want to perform the task on, that we're going to hopefully get it to follow the pattern on. And we'll say input. I wasn't sure what to think of this new restaurant. The service was slow, but the dishes were pretty good. And then we cue it in to follow the pattern by saying sentiment colon. Basically tell us what you think about this thing. Now, my prefixes are a little bit leading. They are giving you information about what to do, but it could also learn from these patterns. If we just said input and output, it can also do that, and I'm giving it a little bit of richer information. Now, my goal then is to get the large language model to go and analyze the input I give it and decide what should be attached to sentiment. And it picks up on our pattern, and it says neutral. So it sees it in this review, you know, it says service was slow, but dishes were pretty good. And so it's seeing that sort of positive and negative, and it's following my pattern that I gave I didn't tell it. This is what neutral meant. But in the examples that I had before, kind of a weight balance of positive and negative ended up being neutral. Now a couple things to note. One, we didn't tell it what to do. Two, we didn't tell it exactly what the output should look like, and what we see is that it's constrained itself to the output, and basically the labels that we gave it earlier, we had negative, positive and neutral, and it's automatically constrained itself and provided an output based on that. Now it won't always constrain itself, but this is a nice thing, as in many cases, this can help us get a more constrained or bounded output out there. Now, if we went we gave it a new one, we could say input. I really hated this copy. [11566:24:00] 0: It was [11577:09:20] 0: roasted too much and tasted burned. Now notice I'm not going to give it the prefix for sentiment, so let's see what happens when I do that. And then you notice it provides the prefix and the output that I expected. Now the really important thing to think about with this is, if you go back to when we talked about large language models, and what they're doing, they learn to predict next word. They're learning patterns. And so when it sees input in a statement, it's predicting that the next word should be sentiment, because that's what it saw in the examples that we provided it before, when we ended with sentiment. Then what it did is it knew that it needed to pick up right after sentiment. So if we go back to this and we edit it, and we just add a line here and we say sentiment, then it should pick up the pattern right after sentiment. And so this is kind of helpful to know about when you're thinking about few shot examples. Now this is, this is a simple example of following a pattern. You can see how this is a powerful way of teaching, particularly if you have data that describes the task that you want to do, but and then, when I say describes, it shows the input and it shows the output, and it doesn't necessarily describe how the task would perform, but we can see what's being done, and that that type of thing can be a good fit for a few shot prompt you a [12048:48:00] 0: large language models can actually do some planning, which is an interesting ability. So they can actually go through and take patterns and with few shot examples, and they can learn what the next action should be given a particular situation. But I'm giving you this example not because they're limited to, you know, coming up with planning in the sense of actions, or, you know, doing sentiment analysis, but I want you to expand your sort of mind on what's possible with few shot prompting and see it as a technique that can be taken and adapted to all kinds of situations. So we've seen how we can use few shot prompting. We're doing sentiment analysis. Now we're going to do something very different with it. So we're going to take a look at this example where we're describing different situations with driving a car. So in the first one, we see situation, I'm traveling 60 miles per hour, and I see the brake lights on the car in front of me. Come on. And the action is we're going to brake. So again, we've got a first example in our few shot examples, situation, I've just entered the highway from an on ramp, and I'm traveling 30 miles per hour. Action accelerates. We're teaching the large language model that it's going to be given a situation, and it needs to decide what the car should do. Situation, a deer has darted out in front of my car while I'm traveling 15 miles per hour, and the road has a large shoulder action brake and swerve into the shoulder. Situation, I'm backing out of a parking spot, and I see the reverse lights illuminate on the car behind me. And then we prompt it with action Lee, leave off at the end of our prompt with something that indicates the large language model we want it to decide what the action is, and what do we see it do. It actually says stop and wait for the car to back out before proceeding, and it's making a sensible, you know, decision about what the action should be. Now, I don't think we should go and build self driving cars with few shot prompting. I don't think we're going to get there with that. But I do want to show you that we don't have to think just with a narrow, rigid box of like, you know, classify something. We can actually kind of have complex tasks that we're having to perform. Now, sentiment analysis is a complex task, but this is also a very complex task. It's sort of in a different vein. So I want us to think very creatively about how we can use few shot prompts. Now, again, one of the things that we're getting is we're getting some constraints on our output. It's learning what the output should look like. Now I'm going to then go and do something else interesting. I'm going to show you kind of an interesting capability of large language models. And one of the things that can be done to use one large language model to teach another one, which is kind of an interesting capability. So I'm going to say, Please provide more examples, and then I'm going to kind of prompt it with situation, and it's going to start, and it's going to start generating additional situations and actions. So it's learned from our pattern, the types of things that we're describing and the types of actions. And now it's going to go and generate more examples. So it says you're driving in heavy rain, and notice that the road ahead is flooded. So this is the continuation of our situation. And then it says action, slow down and cautiously drive through the flooded area, watching out for other vehicles, and avoidance sudden movements or changes in direction. I would actually disagree with this. I'm not sure that it makes that it's smart to drive through a flooded area. That's probably questionable decision making, which, again, just reminds you that you need to own the output of the large language model and check it. Situation. You are driving on a two lane road and a car is approaching you from the opposite direction with their high beams on action, dim your headlights to low beams to avoid blinding the oncoming driver. But you notice, the interesting thing about this is it's giving us some rich situations and possibly appropriate actions. I'm not sure I agree with the flooded one, but we're generating different examples of situations and what to do, and they look very similar to what we produced before. And one thing that's interesting is we can actually take examples like this and then curate them and have a human edit them and then provide them back to a large language model, either later, as additional examples for our few shot examples. And so once we've had a human look at them and curate them a little bit, maybe clean them up, maybe we don't want that one on flooding, because we don't think that's a good idea. So we actually so we actually say, Well, you shouldn't drive across flooding, and we sort of spelled the rules. But you can imagine that the level of effort to create the initial examples right here is much higher than the effort to go through and generate subsequent examples, which we can then go and hand edit and curate so we can quickly build up these examples, both in order to generate an output right now that we want, but also to generate examples that we can later give back to the same large language model, or that we could go and give to another large language model to teach it. And in fact, some people have actually gone and done this. They've taken output from chatgpt, for example, and they've taken it into another large language model, like Facebook's llama, and used the output from chatgpt to improve the outputs of llama. And so this is another interesting capability, is that large language models, through these few shot examples, they can generate few shot examples for other models. The other thing I just want to go back to is this is a very different sort of task and style than we had before. We have a situation, and then we have an action that's being predicted. And so we can have all kinds of interesting things anywhere where we can have a pattern that we can describe a set of examples that show the input and what we want the outcome to be. And we can also show things that have intermediate steps, which we'll look at in another video. [13695:28:00] 0: The examples that we give in few shot, prompts don't have to just be an input and an output. We can actually show intermediate steps to reach a particular goal. Now, one of the reasons why this is really interesting is that when we begin showing the intermediate steps, the large language model, can learn how to apply a series of intermediate steps in order to reach the goal. So we can start getting more interesting output than just here's an input and here's the output, or here's a situation and here's the action. We can start looking at, if this situation occurs, what might be the next action, and then the action after that, and the action after that, until we reach some state that is important to us, like we are no longer at risk of running into the car in front of us. And so if we tailor our examples correctly, we can actually have the large language model do sort of the intermediate breakdown of the problem into a series of steps where we can have it decide how it might go and tackle the problem. Now let's look at an example of this. We're going to take our car example from before, and now we're going to enrich it a bit. So we've now got, actually two essentially situational examples. We start off with one, and it's the same one from before. The situation is, I'm draft traveling 60 miles per hour, and I see the brake lights on the car in front of me. Come on. And then we say, think I need to slow the car down before I hit the car in front of action. Press foot on brake. Think the car isn't going to stop in time. Action, check if the shoulder is wide enough to swerve into. Think the shoulder is wide enough. Action, swerve into the shoulder. So now we've built a more complex scenario that includes the original situation, but then we have sort of updated steps of what's happening and what the thought process is and what we need to do next based on that thought process. So in this case, we're traveling down the road. Suddenly the brake lights in the car in front of us come on the we think that we're going to hit the car, so we hit the brakes. We think that we're not going to stop in time, so we look over, we see that your shoulder is big enough, so we decide to swerve into the shoulder. And so we're now basically having a more complex situation that also has multiple steps involved. Similarly, we've taken one of our other ones that we had before. I've just entered the highway from an on ramp, and I'm traveling at 30 miles per hour. Think I need to speed up to the speed limit so that I don't get hit from behind. Action, press foot on accelerator. Think I've reached the speed limit. Action, let off on the accelerator. So we're basically going through we're breaking down the problem or situation into multiple steps, and what's happening now, we provide a situation, again, the parking lot situation. I'm backing out of a parking spot, and I see the reverse lights illuminate the car behind me. Action. [14532:21:20] 0: So now we're prompting [14542:45:20] 0: for what we would like the large language model [14558:29:20] 0: decide. And now [14561:57:20] 0: we see, instead of just a quick it's done. You know, look, stop, waiting for the car behind me. Instead, it says, action, immediately stop backing up. So we see immediately stop backing up. And then it thinks I need to check my surroundings to make sure it's safe to continue backing up. And then action, check mirrors and surroundings for any obstacles or pedestrians. So it's thinking about what does it mean to do next. It needs to it's thinking oh I need to look around and make sure it's okay, so it looks in the revere the mirror, and it looks on the side mirror or the rear view mirror the side here, and then it thinks, Okay, it's safe to continue, backing up and so action. Continue backing up slowly and carefully while keeping an eye on. surroundings so now we've got more sort of fine grained detail in what we're actually going to do in the particular situation. Now, there's all kinds of interesting things where we can imagine doing this, we can think about. [16303:48:00] 0: come up with the next item.