================================================================= TITLE: Prompt Engineering 5 DATE: 2024-11-01 (November 01, 2024 at 09:06 AM) DURATION: 02:54:13 (10453 seconds) WORDS: 29,471 words SPEECH ID: 26XPVAWWMH6SOA7K ================================================================= --- AI SUMMARY --- few-shot examples, prompt formatting, input-output, intrinsic properties, detailed examples, additional context, chain of thought, reasoning steps, template pattern, meta language, trip planning, emergency shorthand, grading prompts, gameplay pattern, recipe prompt --- FULL TRANSCRIPT --- [141:41:20] 0: So let's look at some examples of where we're making mistakes in our few shot examples. So things that we can do wrong in the formatting of our prompts and what we can kind of think about and learn from these examples. So here's some few shot examples. And the idea behind this is we put together not very good prompt to analyze how hard things are like, Is it soft or hard? That's where really what we're trying to get at with this prompt. And some few shot examples. Now this is a good prompt. This is a bad prompt, and we'll see why. So what we've got is we have input as the prefix. We then got brick. We've got output as a prefix, and then hard. We've got input as a prefix, and then pillow output soft, and then we've got input car. Now, notice what we've got here. One, we don't have a lot of examples here, but two, we kind of, we've kind of switched gears, like, you know, we started talking about input and output and the hardness of things, using things that are really obvious, probably the like, a brick is hard, a pillow is soft. Is a car, I guess a car is hard, but it's not as clear what we're getting at. We also might just be trying to describe some fundamental sort of intrinsic capability, or, you know, properties of this thing. It may not be about hard or soft, because it could be other things. It could just be an attribute to describe the thing itself, because pillows are generally thought of as soft, and bricks are normally thought of as hard. Those are kind of fundamental descriptors sometimes they use for them. And what we see is that when we prompt chatgpt In this example, what we get is it says fast or maybe transportation. And so this kind of shows us a couple things. This is a prompt that's not very well designed, and because of that, what we see is that chat GBT isn't quite sure what the next, you know, next output should be from the pattern. Now there's a couple mistakes in here. One is we've got input and output. Input and output are really generic prefixes. They don't really give the the language model much information about what the task is that it's trying to do. All we know is we're taking in something and we're getting out something, but it's not really telling us, you know, what it is that we're describing. Like, maybe we should go and say, you know, input, brick surface feeling, you know, hard. Input, pilling, pillow, you know, surface feeling, you know, soft. Or maybe it's something about like, if you hit it, what will it feel like? You know, you there's all kinds of things we could do to give it more sort of context around what we're trying to get at. We could also give it more examples, but what we've got here, overall, in this prompt, is we've got a lack of information. It's not detailed enough, and we're not giving enough information about what the task is that's being solved. And the result of that is, is that the language model isn't really sure what the solution is. Now one way we could solve this is we can go and before we give our examples, we can give a little bit more context, so we can provide some instructions. So we could say your output can only be soft or hard. Now, one thing to note is, if I'm putting these things in quotation marks, to try to, you know, indicate to the language model that these are the two values. I don't want it to get confused and think I'm talking about soft or hard and some other context, but I'm putting these things in quotation marks, trying to giving them some emphasis that either it's soft or hard. And this may not always work, because we still have a prompt that's really generic, that's really doesn't have a lot of context and a lot of meat to it still very, you know, vague. We've got input brick. We're still dealing with it now, luckily, in this case, adding this little bit of additional context and specifying to the large language model that we only want softer hard as an output helps it figure out that it should think about, if I pushed on this car, how would it feel like it would feel hard, you know? And that's kind of the task that's being solved. And so it comes back with the right thing, but that's our first thing to think about when you're writing few shot examples. Are your examples detailed enough? Are your prefixes that you're using for these things meaningful? Do they give additional context that the large language model can use to figure out what the next thing in the sequence is. Another way to think about it is, if you gave this to 10 different human beings, would you have a chance? So a few of them might be confused about what you're trying to ask for, and if the answer is yes, then you probably need to think about how to refine your prompt, like if it's not fully clear what you're trying to do in the examples, or what the process behind the examples is illustrating, then you're probably not detailed enough. Now, one way you can solve that is by adding some more instruction, like we have here at the top of this prompt. Now let's look at another example. I've got object, plane speed, fast. Object, worm, speed, slow. And then I go through a series of examples, and notice I'm giving a little bit more context here. You know, my speed prefix is a little better, right? Because speed seems something that's quantifiable, right? Like a plane is fast. You know, a worm is slow, like that should be more context. And so we did go prompt it with object ball speed. And this is another important thing to realize, is it says variable. And so one of the things we have to think about is we're trying to get the large language model to produce an output to classify or to fit into some boxes, we need to make sure that it gets enough information in the input to be able to accurately put things into the boxes. So we need to make sure that whatever information we're giving it about what it's going to do always has a, you know, enough context that it can make a decision about the label. Now in this case, a ball could be fast, it could be slow. If I shoot a ball out of a cannon, it might be going really fast. You know, if I shoot a ball, if I put it on the top of a rocket, it might be going really fast. You know, there's all kinds of different things that could make a ball go faster or slower. So we have to make sure that we provide enough context. Now, in general, the thing to think about is, am I given enough information? Now I'm going to go back and I'm going to change my prompt down. I'm going to say object, ball kicked by a baby, and then we get immediately it says slow. So when you're building up the few shot examples, you want to make sure. One, your prefixes are pretty descriptive. Two, do the examples that you're giving really give enough information to derive what the underlying process is that is going on in order to go from the, you know, the starting input, to the final output, can you really, do you really have enough information there to see what's underneath the hood? And one way to think about that is, if you ask a bunch of humans, would they all know exactly what you wanted it to do without any ambiguity? Two, you want to make sure that you have enough description before the examples, if needed to provide additional context, sometimes examples, you're just not going to be able to get there with examples, and you may need to provide some additional rules or other information at the start of your prompt to help it along. And so really, a lot of times, what you're thinking about is you have a limited amount of space in your prompt, and you have to think about, is this something that I can better describe in an example, or is it something that I can better describe in some instructions at the top? And what better means is, will I get a more accurate output, and will it take less space, or makes maybe less words to describe it? If I can get it done very clearly in an example, then maybe that's the right way to go. That example doesn't take a lot of space. On the other hand, if it's a really simple rule and I can describe it, I may be able to get a better response. You know, by putting that rule up into the description. And then finally, we have to make sure that we provide enough information. So in this example, ball kicked by baby. If we're trying to bucket things or we're trying to get a particular output, we may have to make sure that when we give input that there's sufficient richness and detail in that input to follow the rules or prior examples that we've given. Now, this is particularly important. If our prior examples were pretty clear cut, it's probably something better. Now, one could argue that you know our prior examples, if we go back and look at this, are we said plane, a plane was fast. Well, you know, a plane might not be fast, right? A plane might be slow. It might be sitting parked on the tarmac of an airport. And so we also want to make sure that our examples are rich enough and detailed enough. Now, sometimes we can get away with simple things like plane fast, worms slow in order to teach it, but sometimes we're going to have to go into more detail. We're going to provide more context. So make sure and and think about, do you have enough real information? Is there? Is it going to depend on the situation? Those things like that? Provide details. Now, one way to do it would be to say, just make some assumptions, you know. But one of the things that can happen sometimes when you do that is you may get more verbose output than you really want. It may not fit into that bucket, but when you're writing these prompts, think meaningfully about like, what what is a meaningful prefix? What information or instructions do I need to have at the top? And can you know important information be better conveyed as an instruction at the top, or as an example. Do my examples cover the space enough? Do [2786:45:20] 0: I have enough good examples with rich detail for it to learn from and derive what the underlying process is? And then, when I go and I give it the new input, do I make sure I have enough, you know, relevant context and information with the new input in order to, you know, apply the process that I taught it, because we may teach it the process really well, but then give it a new input that just fundamentally is missing information. In order to apply that process, you [2933:20:00] 0: so you may remember being told to show your work when you were a student, probably in elementary school or middle school, and you were working on a math exam. You had to explain how you got there, or maybe if you've gone on and you you've done other things where you had to prove you know that something was true, that you would, you would, you know, decided. And so showing your work, explaining your reasoning, is something that can be really important in a number of different domains. And it turns out that when it comes to writing prompts, this can be really, really important. Getting an LLM or large language model to explain its reasoning behind something actually can make the large language model perform better for us. Now this is a really interesting thing, but if you think about it, it kind of makes sense, right? Because we have a large language model that's trained on different patterns of test text, and it's learned to predict what comes next. So if it can explain its reasoning correctly, then it's more likely that it's then going to produce the right answer, because the right answer sort of intuitively, should come after the correct reasoning. Similarly, if you think about it, if it starts explaining the reasoning correctly, if it gets the first step right, it's probably going to get the second step right, because it may have seen similar problems reasoned out. Now, this is an intuitive explanation. This may not be right, but I think intuitively you can think, kind of think about it is that if you break down the problem you're solving into multiple independent steps, and you explain them, and they're sort of a natural sequence and logic and flow to them, it's more likely that the final output, which is the answer, is going to be a natural extension of the correct reasoning, and therefore correct. It's more likely to be correct if your goal is to accurately predict the next token. Similarly, if you have the problem and you get the first step right and the second step right, you're probably going to get the third and the fourth as a large language model, because you've been trained on this stuff. So there is a technique for this, and it's called chain of thought prompting, and I'm going to show you examples of this, but it's really helpful to remember when you're building prompts that require some sophisticated sort of intelligence and reasoning capabilities. Now we don't always need this type of of of, you know, breaking the process down step by step in explaining the process. But when we do and we need that more effective reasoning, it's really useful to understand how chain of thought prompting works. So I'm going to start off with a positive example where we use it and we show what it does and how it works. So we have some examples here that we are going to give sorry. I'm actually going to start off with a negative example. First I apologize that was a mistake. So I'm going to start off an example that does not use chain of thought prompting, and I'm also going to show an example where I'm going to make a mistake in how I phrase the prompt and how I structure the prompt, and I'll come back to this mistake in a second. But what I've got here is I have four different or three different questions that require some reasoning. In the first two, I've given an example of what I want. I say I have four bike racers start a race and travel an average of 30 miles per hour. That each race for two hours is the total number of miles ridden by all riders greater than 200 and then I have an example, and I say answer yes, and then I say question. I have a staging process for a bike race to line up racers. It takes 47 seconds to stage a group of eight riders, and 67 seconds to get the group to the starting gate and ready to race. I want a new group to start the race every 30 seconds? Do I need eight groups staged at all times in order to have races continually starting every 30 seconds? And the answer is no. This is example I'm giving it, and we'll see the reasoning behind these in a minute. And then I say, I'm in a spaceship without gravity. I have a cup with a needle in it. I move my foot on the bed, knocking over the cup onto the floor, I lift a book up and put it on a desk. Is [4024:16:00] 0: there anything on the floor? Now [4042:40:00] 0: this is the question I'm trying to get chatgpt to answer, and so I've given it basically some examples of questions with answers of either yes or no. So I'm trying to elicit a yes or no answer from chatgpt. I'm using few shot examples to do that, and I'm showing it questions, I'm showing it answers, and then I'm asking it for the answer about this question about a cup knocked on the floor. Now, I have actually seen some variations of this, and I apologize because I don't remember exactly where I saw this. This first example of reasoning with the cup and the needle inside of it knocked on the floor. But I thought this is an interesting one, because it works really well for showing the difference between chain of thought prompting and without. So this is without chain of thought prompting. So what is chat GPT say? Because we asked it, is there anything on the floor? So the question was, I'm in a spaceship without gravity of a needle with a cup, or I have a cup with a needle in it, I move my foot on the bed, knocking over the cup onto the floor, and then I have some irrelevant information, and I say, is anything on the floor? Now, without chain of thought prompting, it says, yes, when the cup with the needle and it is knocked over onto the floor, both the cup and the needle will end up on the floor in the absence of gravity. Objects will not fall downward as they do on Earth, but they will still move in response to forces applied to them. In this case, the floor supplied by your foot. Knocking over the cup will cause the cup and the needle to move and come to rest on the floor. Lifting a book and putting on a desk does not affect the position of the cup, so they will remain on the floor. So it says, yes, there's going to be something on the floor of the cup and the needle. Now let's look at the same example, but with chain of thought prompting applied. So here we go with chain of thought prompting. So with this one, we've spelled out the reasoning behind each of the examples. So we go back to the bike racer, and we say, well, the total be greater than 200 and so we say reasoning. Each rider will ride 30 miles per hour times two hours equals 60 miles. I have four riders, therefore the total number of miles written by the riders is four times 60 miles equals 240 miles. And then answer yes. This is chain of thought prompting. We're explaining the reasoning behind the examples to the large language model. So in this case, we're explaining we're sort of working out the math, showing our notes how we got to this answer. And then we do the same thing for the next one, where we're staging a bike race, and we want to figure out how many people have to be staged at a time in order to start a race every 30 seconds. And we give the reasoning. Each group takes 47 seconds plus 67 seconds to be ready to race. So I will need to calculate how many races will need to be run before a group is ready to race. A group will have 114 seconds over 30 seconds equals 3.8 races run before it is ready to race. I can't have a partial group, so I need to round up to four. I only need four groups stage to be able to race every 30 seconds. So I do not need eight groups answer, no. And so you see, rather than just say, here's the example, here's the answer, we say, here's the answer, here's the reasoning, and then here is the answer, the correct answer. So then in this final example, with the spaceship, again, we're having the spaceship. There's no gravity. We have a cup with a needle in it, knocked on the floor. And then in this example, we tell it to provide its reasoning first and then its answer. So we're prompting it and giving it a format that makes it clear, we want the reasoning first and then the answer. And what's interesting is we see different reasoning than we saw before, and we get a different answer. If you remember before, we got the answer of Yes, their cup and the needle will be on the floor. But if you look down here on this one at the bottom, we can see that it says answer no, because there's no concept of on the floor in a zero gravity environment. So if we look at this one, this one's actually giving us sort of a better reason to answer, in my opinion. Now there's probably different nuances, and I'm not an expert on this, but I think if you don't have gravity, you're not necessarily going to have the cup and the needle resting on the floor just because they got knocked off. And so the reasoning is better in this one. It says, in a spaceship without gravity, objects do not behave as they do on earth with gravity. When the cup and the needle is knocked over, the cup and needle will not fall to the floor as they would on Earth. Instead, they will float in place or move in the direction of the force applied to them. And so therefore, in the absence of gravity, there is no concept of object being on the floor as we stand on Earth. And so basically what it's saying is like, well, you might move them or cause a force to be applied, but it's not they're not going to just sit there on the floor, because there's no gravity. And so it comes up with the answer, no. So you see right here, we're getting a completely different answer out of the large language model. And the difference is, is that one example, we're giving it the examples, we're giving it the reasoning behind the examples, and then we're asking it to provide the reasoning, and then the answer, which is this case and where we're saying, No, there's nothing on the floor, which is probably a better answer. In this case. In the other example, all we're doing is saying, here's the question, here's the answer, here's a question, here's the answer, and we're not giving it the reasoning. And then finally, we're saying, here's a question, and it's going to try to produce the answer first, which is what it does. And so the difference is really only in what it does here. It's answering first, but it's not explaining its reasoning first, and it's in its reasoning actually isn't quite as good, and its answer isn't quite as good. Now, you know spaceship knocking a cup with a needle off on it. This might not apply to you, but it's an interesting example of where there's more nuanced reasoning. And if you have a case where you need to have it think through, and I say think very liberally here, but if you need it to try to get better reasoning behind the answer, or a better computation, whatever you want to describe it as, but intuitively, if we thought through the process of getting the answer, we have a good process of breaking down the problem and going step by step to a solution. We're likely to get a better answer out, a better solution out. And so that's what chain of thought prompting is doing, is we're trying to elicit that that break the problem down in the steps. Think about, you know, step by step, how you're going to solve it. And the way that we get there, the way that we get to do that is when we give it few shot examples, like we do up here, we explain the reasoning behind the answer, and we explain the reasoning. First, we say, this is what I'm thinking and doing this is why I'm getting there. Similarly, we do it on this one too. We say, Here's my reasoning, and we provide the reasoning before the answer. And the goal is to get the large language model to do the same thing, follow our pattern of breaking down and explaining the reasoning before getting the answer, to think through the problem, to give the fundamental steps and then to produce the answer, and we get better outputs. In this case, and in most cases, it's been shown that you're going to get a better reasoning out of the large language model. If you have it explain its chain of thought, what it's thinking through, what it's trying to do in order to solve The problem, then you'll get a better Answer out. I [6317:25:20] 0: large language models, as powerful as they are, they can't do everything on their own. They're going to have to reach out into other data sources, and they have to learn how to use other tools to be really effective over time. So one of the things we have to learn how to do is build prompts that can allow the large language model to essentially reach in and query new information, to use other tools that can help it do reasoning or or computations that it fundamentally is not designed to do. And so how do we go about doing that? So one way of doing that is with an approach called react. So the idea behind this is that we want to teach essentially the large language model how to think through a process and understand steps where it needs to go and use some other tool to take some other action outside of it and get the result of that tool and bring it back in as some type of computation or result that it can then incorporate. And so there's a specific way of writing prompts to do this. Now this is similar to chain of thought prompting like we saw before. We're going to use some of those same concepts from chain of thought prompting, but we're going to expand the approach to have this concept of certain things that the large language model knows it needs to use some external tool to perform. So let's take a look at this. Now bear with me, because this is a longer example. We're going to do a single example that we're going to teach the language model with, and then we're going to ask it to perform the same task. So in this example, we have a task which is calculate when I need to arrive at the Music City BMX national race for my son to be on time for his nine to 10 open race. So BMX is a bicycle racing sport. Some of my examples lately have been around BMX and Music City. BMX is a local BMX track here in Nashville, the house, one of the big national races for BMX racing. And so one of the things is I need to figure out, when do I need to show up at the track? Because these are all day, multi day events. And sometimes you may want to figure out, how late can I sleep before getting in the car and driving them in order to arrive. And what happens is, in these races, you have hundreds of individual little little races that are essentially like 30 seconds each. These are called motos that are run, and you want to figure out when your Moto 87 for example. Well, how long do I need to wait after the start before that race is going to start? And so sometimes there's a balance there, trying to figure out, what do I need to be at the track, actually, as opposed to when does the race start? And so what we're going to do is we're going to have it solve this problem for us. We're going to pretend to solve this problem. This isn't actually solving it, but we're going to show you how this process works. So we give it a task, and we give it an example, which is, calculate when I need to arrive at the Music City BMX national race for my son to arrive on time for his nine to 10 open race. And then we say, think I need to find out what time the first race begins. I can use a web search of the Music City BMX site to get that information. So remember, this is our example. So we're saying, here's the thought process. I need to first figure out the first step you can think, you remember back to chain of thought, where we trying to have it explain its reasoning? Well, we're kind of doing the same thing. We're explaining the reasoning behind it. So we're saying, I need to find out what time the first race begins. We're explaining what we're trying to do. I can use a web search of the Music City BMX site to get that information, and then we have the next thing we do, which we say action search, and then we give the Music City BMX website. And so action here in the search is basically a tool that it's learning to use. It's learning to use some external tool, in this case a web search, so it knows that there's certain information it does not have. And so we're teaching it when you need information that you don't have, go and search for it, and you can search for it with a website, and then it says the result. We tell it is, all races start at 9am so then we say, think I need to find out how many motos run before the nine to 10 open race. Motos are essentially the individual races that are going to run before that race. I can use a web search of Music City BMX site to get that information, and then we show it again. Another example of searching assuming there's a search tool available to it for the Music City BMX site, and then result, we show it the result. There are 30 motos that run before the nine to 10 open race. And then we say, think I need to find out how long each moto took last year. I can use the video live stream from the USA BMX website and record how long the first 10 motos took. And then we say, action video, and we give it some fake video and pretend that, hey, we were able to go and pull this video down in time something. And then result, the first 10 motos took five minutes. Think if 10 motos took five minutes, 30 minus will take 15 minutes. The race starts at 9am so I need to arrive before 915, a m when the race starts, I will arrive 30 minutes early, at 8:45am, to be safe. So remember, this is our our faux example. We've could have imagined a scenario where I need to solve this problem, and I using, I'm using a series of web searches, and then watching a video from a prior year to figure out how long things took. And I'm trying to teach the large language model, in this case, chat, GPT, to use the same tools to solve the problem. So then I ask it, you know, here's the new task, calculate what time I 36 to 40 novice race will end at the USA BMX grand nationals. And then I say, think to prompted to start thinking, what is the next step? And you'll notice what it does. It then says, I need to find out what time the first race begins at the USA BMX grand nationals. I can use a web search of the USA BMX site to get the information. Action Search USA BMX events grant. So notice it's picked up on a couple of things. It's picked up on the idea that it has this tool called Search, that it can use to go and pull in information. You'll notice it's also picked up on the format of the URL. Now, this format I had was just completely fictitious in this example, but it's picked up that, oh, there must be this formatting. There must be a pattern behind these URLs that I can use so I can go and search and use some knowledge of the structure of those URLs to pull in the right information. So it's learned essentially how to go into a web search. And then it says, result. Note, as an AI language model, I'm an or unordered perform web searches, Please assume a hypothetical result of the purpose of this exercise. The first race begins at ADF. Now what's interesting here is, if we were actually integrating this into a real system, we can have the system whenever it sees a result, stop, pull in the actual result, put it in there, and then basically feed this first SEC chunk back to the language model to then continue the process. So we don't actually have to worry about if it's going to going to fake the rest of this. We could just have it go and we could incrementally get to every each time we get a new result out that we actually need to fill in. We could go and run the web search and fill in that result. It then keeps going. It says, I need to find out how many motos run before the 36 to 40 novice race at BMX grand nationals. I can search, and it goes in searches on the Grands, and then it has a hypothetical result. There are 120 motos. Goes and thinks again. I need to find out how long each moto took last year. I can use the video live stream, and then it picked up on the URL pattern. So you notice it's learning a lot of things. It's learning how to use the tool and how to input data in a particular format for it based on what I showed it. Then says, Okay, here's the result from that. And then it says, Think if 10 motos took six minutes each, or took 10 minutes, six minutes, then each moto took an average of point six minutes. Therefore 120 motos will take approximately 72 minutes. The first race starts at ADM so the 36 to 40 novice race will start around 9:12am I need to find out how long the 30 foot six novice race itself will take. And it goes and does that. And then it says, if the 36 to novice race starts around 928, 912, then it will end around 915, [8636:53:19] 0: this is the approximate time my race will end at the USA BMX nationals. And so what's interesting is that actually end up, in the end, getting slightly off track. It gave me the begin and end. So it's telling me the end the begin time, but it also went and calculated the end time, which I may or may not want. But the more important thing is, is that along the way, it followed my pattern up here, I taught it this concept of searching. So I had action search Music City bmx.com I had another action search for Music City bmx.com I had an action video right here, and it learned how to use these tools. And then it's applying the exact same tools down here. It's applying search, it applies it again, then it applies video, and it's applying it using the format. So you can imagine it's essentially learning to, you know, run a web search, to watch a video, you know. But again, these are tools. So it could basically go and send some information off to the tool, get an answer back, and then pick up in its reasoning. Now, the way that we would do this is we would have to have a way, if we're going to use this to actually, when it gets to the point where it says, here's what I'm going to do, we would stop it and go give that data to the real tool, get the answer, and then come put it in for the result, and then we would feed this whole thing back in with the correct answer as the prompt. It then hopefully will run through up until it gets another action, in which case we would go and get the real result from that tool, put it into the prompt and continue. And we would continue down until we got to a point where we had an output. Now, a better way of doing this would be to have some, you know, way of it saying, Okay, I'm done. And I should have put that into the prompt here, but this is doing basically. It's teaching it. Here are some tools that you can use if you use this format. So you can go and run this particular tool and you describe the tool to it. Now, other ways to do this, you can also if I didn't have every tool used, I could have edited this prompt, and I could have had a description of each tool and the format and other information that it could use to help it figure out which tool to use. Now, my simple example, I did it just based on giving up patterns that I had directly in the sort of few shot examples that I provided. But you can also have other ways of sort of catalogs of tools and their descriptions, so it can think about which ones to use at the appropriate time, and you see how beginning to reason and know, you know which tool do I need to use at which point in time to get which type of information? So you can teach it to do this sort of problem solving. So you can go and integrate it with other tools, and you can build these prompts that allow it to tap into other tools. And you see this in a variety of different frameworks. There's a tool you may have heard about called Lang chain, which is a framework for writing these types of automation processes, and they use React underneath the hood in order to be able to go and do some of the interesting things like This that They Do. I [10133:20:00] 0: we're going to be faced with the problem with prompts of the large language models themselves are going to be moving very rapidly. They're going to be continuously evolving. And we've already seen that. We've seen chat GPT and GPT four. We've seen Lama and alpaca. We've seen bucu and lots of different ones are continually coming out. And one of the things we want to know is, when we develop our catalog of prompts, our patterns, we put lots of work in developing prompts that work well for us. How do we evaluate them and make sure that they're maintained over time? Because if we change our large language model. Does that mean that all of our prompts are going to break, or if we change the data that we're working on slightly? Does that have ramifications for us? So we need better ways of helping to evaluate the output. Now, one way of course that we're going to do this is we're going to have humans look at the output in many cases, but we'd like to do things that could probably help us scale better. Be able to actually go and do sort of large scale automated analysis in some way. So how do we go about doing this? Well, one of the really interesting things with large language models is we can actually use them to evaluate themselves. This can be one of the inputs that we use to help determine how good our prompts are and how maintainable they are over time, is we can use a large language model to grade either itself or the outputs of another large language model. So we've seen the examples of this where we have they've actually taken large language models and they've had one large language model teach another large language model, essentially. But we can do something similar in that we can take outputs from a large language model and actually feed them back into the model itself to grade them. Or we can actually go and take another large language model that we're working with and have its outputs graded by, for example, a better, large language model, maybe with more parameters that can has more powerful so let's look at an example of this and how we might build a prompt to do it. So in this example, I'm going to teach the large language model, in this case, chatgpt, how to grade the output of a prompt. I'm not actually going to show it the prompt in my example, I'm just going to teach it the grading process so that it can help automate it for army. And so I'm going to use some few shot examples. So as input here at the top, I'm saying, Here's my input, and it's a bit of text about Vanderbilt University from Wikipedia. It identifies that Vanderbilt University was founded in 1873 and I explain, here's what the output was. The output was. The following is a list of events and dates in the output. Vanderbilt found in 1873 and then the explanation is that the output has unwanted text at the start and should only include the names and dates. And so I gave it a grade of five out of 10. So this is the output that was produced, and then providing a human explanation of what is wrong with the output, of why it's not getting a perfect score. And then I'm grading it and giving it a five out of 10. So I'm going through and doing a couple of these by hand to show it what I want. And then I'm giving it another example with that exact same piece of text saying the output was just 1873 and the point of this is that, if you can probably sense it by now is I want a prompt that's going to extract events and the dates that the events took place, and that's it. I want an event name separated by a comma and then the date of that event. I don't want any other text. I don't want explanation. I just want names of events and dates, and I'm showing how chatgpt can grade the output to see if it's matching that format. I'm not even showing it what the prompt is. I'm not showing it what the task is. I'm giving it examples to help learn. And then I say explanation the output is missing important information about the event that happened on that given date. And I give it a grade of three out of 10. And then I have a one more with the input, which is that same paragraph about Vanderbilt. I show Vanderbilt University comma 1873 which is the ideal output for my fictitious task, and I explain that the output Exactly. And then I actually cut it off. There's a typo here. It's really supposed to be met expectations, or something like that. And then I give it a grade of 10 out of 10. What's interesting is this doesn't even matter that I made a mistake here in my explanation, because it still works. And so then I give it a completely different input. I say, here's a different input again. It's about Vanderbilt and the history of the English program at Vanderbilt and creative writing. And so I give it as input another piece of text on that. I say the output was, and I give it what the output was, the fugitives in South agrarians first half of 20th century. And then Vanderbilt is a founding member of the Southeastern Conference 1966 and that's essentially a prompt for chatgpt to then go and grade that output. And so it then provides an explanation of the output. It actually mentions something that I didn't grade in there, but it's interesting. It says there's inconsistent capitalization, and then it gives it a grade of nine out of 10. So as a human labeler and a human performing this task, I actually ended up with a nine out of 10 because I did wasn't consistent in capital. Consistent capitalization, but you can see it did a good job. It took the sort of substance of what I wanted, and it performed the grading task that I had given it. And so we can actually use large language models to evaluate the output of prompts. Now there's a number of ways you could potentially use this. One is if you have some system that's going to go and make decisions or generate information with a large language model, like chatgpt or some other model that you're running, you might want to have the model check itself, or another model check itself. Or you might want to do this multiple times, where you take the output that you're getting and you give it a grading criteria, similar to what I've done here, and you've developed a prompt with grading criteria. You might have multiple prompts with grading criteria, and you all have them score the output, and then if the score is below some threshold, well maybe you want to have a human look at that output, or maybe you just want to retry it and see if you can get something better to be produced. And so this gives you an extra sort of tool of, how do we go and evaluate what's coming out, make sure it looks good and still have sort of the power and sophistication of these models? And this is one way to do it. Now, there's lots of ways that you could phrase the prompt you might want to go and look at the alternative approaches, pattern to develop some different ways. This is one example using few shot, few shot examples. I could have gone back and say, you know, we could have said act and use the persona pattern act as a prompt critic, perform and a or give the output that I provide you a grade in terms of how well it matches the expectations of the prompt designer I am going to give you examples of grading prompts. And so we could have gone and done something like that. I did a relatively simple prompt, but we could do a much more sophisticated prompt using some other patterns. Again, it's going to generate an explanation, and then at the end of it, it should generate a grade force as well. And so it'll then go through and give us an eight out of 10. So you notice we got eight out of 10. One time we changed the prompt slightly, we got nine out of 10. Either way, it looks like that's a pretty good output based on our grading criteria and what we want. And so we can use this, this sort of tool in our toolbox when we need to evaluate a prompt in the output of a prompt, we don't have to always fall back to having humans look at it. One thing we can do is we can fall back to having the large language model itself evaluate the output, and then we can build different types of automation around that, or we can use that as a trigger to escalate to a human now, of course, if we have a lot of a lot of really good examples of grading that helps us a lot, but we don't have to have a ton. If you see in my example, I had just three examples of grading the output, and it did A good job of figuring out what I wanted. I [12684:42:40] 0: I find really helpful when I'm trying to learn a new topic or improve my skills and Sarah or just have fun to play a game. And when we can play games with new knowledge that we're trying to acquire, it's usually a fun way to to really become masters of that knowledge and test our ability to use it, particularly if the games are fun and sort of challenging. And so one of the patterns that we can use is called the game play pattern. So the idea behind this pattern is we're going to ask chatgpt, or another large language model, to play a game with us, and it's going to decide the rules. It's going to be the Game Master in most cases. Now we can give it a variety of different sort of scenarios that can govern what its role is in the game, but we're going to look at gameplay where the large language model is serving as sort of the Game Master. It's creating the rules, and it's driving the game. And so we can then take a game and we can say, I'd like a game on this topic, or that has these basic rules fill in the rest. One of the things that's really nice about this is that if we say, create a game and we give it some basic structure around the game, it can tap into its training data in order to populate the game with content. So if you think about games like you know, getting the rules right obviously takes a lot of thought, but then there's a whole other challenge for a lot of games, of, how do you create a lot of great content to go with that game? And so this is a pattern where we can tap into the training data from the large language model in order to help it populate the content. Now it can also do a pretty good job of deciding the rules as well. But we're not going to necessarily look in these examples at complex rule generation, but we are going to look at a really useful example of this, and I'm going to show you how to create a game to improve your own prompt engineering skills. So the basic pattern of this is to say we are going to play a game, and we say involving, or about or whatever. And we want to give it the topic. We really we start off this pattern by saying we are going to play a game, and here's the topic, and then we decide some more information about what are the rules of the game. So in this case, we're going to have some simple some simple rules. You're going to give me a simple task that can be accomplished via prompting you. So I'm telling it we're gonna play a game. You pick tasks where I could theoretically prompt you in order to solve that task. So you imagine what we're trying to do is have it play a game with us, where it's going to give us a challenge of something we would try to write a prompt for, and then we're going to write the prompt and see if we did a good job. And then it's going to say, we're going to say, your task should all have a reasoning or programming component to them, although they shouldn't require source code. Now, the reason I do this in this game is it you get more interesting questions. In my experience, if you have some logical component to this. Remember, we talked about prompts as a way of programming, a large language model that everybody can be a programmer, and that's what we're trying to get at. We don't just want to generate a bunch of poems about lonely trees standing in the in the middle of the of a field. You know, we'd like to do more than that. We'd like to have to solve problems that have some sort of logical or interesting component to them, and that's what we're getting at here with this prompt. So we're going to build a game. It's going to challenge us to develop different prompts, and then we're going to try to make these, these tasks that we're solving related to sort of programming or logical things. Now next, we go on and we give it some more rules. I will try to write a prompt to solve the task. You will give me the output of the prompt and tell me how well it solved the task. Task, so it's going to give us the task. And you notice we're also we're adding it ask us questions, so it's going to give us the task. The task is going to be something that could be solved with a prompt. We'll write the prompt, and then it will run the prompt in order to generate the output that that prompt would have output, and then it's going to tell us how good our prompt was. So this is interesting. We're actually having it play a game where it's pretending to be prompted, and then telling us how good our prompts are, ask me questions, until I tell you to stop. You will ask me a question, wait for my response, and then ask me another question, after telling me how I did ask me the first question, and so it says, Great. Let's get started with this first task. Task, given a list of numbers, determine whether the list contains any duplicate elements. If it does, return yes, there are duplicates. If it does not, no duplicates found. So now we've got a specific prompt engineering task. We're going to have to figure out, how do we write a prompt where we give it a list of numbers and have it return one or the other of these things? And it's kind of interesting, right? This is one of the challenges that we often face when we're dealing with a large language model, is getting it to generate a precise output. And so it's giving us something where it has sort of a thought component to it, of like, how do we design and tell it about what what it is we're trying to achieve? But also, it's also got an output component we're trying to match a specific output format. And then it says, Please write a prompt for me to solve this task. So I'm going to solve this task using few shot examples. So I give it a list of numbers, I show it some examples. I say, basically in my prompt, I say, Here's the numbers 123, and then I have duplicates. And I say, no duplicates found. Then I have numbers, 222, duplicates. Yes, there are duplicates. And so I'm following the output format it told us. And then I'm going through and giving it a series of few shot examples to solve this. And then I prompt it. My final end of my prompt is basically duplicates, question mark on the list I just gave it, which is solving the problem that it's asking for or trying to we'll see what it says. But basically, I'm asking it, does this list have duplicates? And we are hoping that what it says is no duplicates found and match this exact format that I provided before. And it does. It says no duplicates found right here, and then what's nice is it does the other part of the game that we explain your prompt effectively commuted the tasks and provided examples of different casts or different cases. The task was to determine whether a list of numbers contains any duplicate elements, and you provide it with examples based on your prompt that was able to correctly determine the list does not contain any duplicate elements. And then it goes on and it says, let's move on to the next task. So now it's playing the game. So it's moved on to the next task. Given a sentence, count the number of words in the sentence and return the results in the format the sentence contains x words, where x is the number of words. So it's giving us an output that I have to produce, and notice it's given an output now where I have to put the output in a different particular format. So before, we just had to go and say there's duplicates or no duplicates, but now we're having to do something a little more complicated. We're having to count words in the sentence and then make sure the count shows up in a particular place in the output. This is exactly testing our knowledge of prompt engineering and some of the patterns and other techniques that we've seen in the past, please write a prompt for me to solve this task. I'm going to use a pattern called the template pattern to do this. So what we say is, I'm going to give you a template for your output. Number is my placeholder in all caps. Fill in my placeholder with your output. Please preserve the overall formatting of my template. My template is. And then I have the sentence contains number words. So I'm going to solve this problem. Here's my prompt to go and solve this problem, and then I say how many words are in the following sentence, the cat jumped on the mat, and it says the sentence contains six words, which we see is exactly the format that it was looking for. And then it tells us it grades us on our prompt. So what's really nice about this gameplay example is that from now on, you can go and use it to test your ability to do prompt engineering. And you don't have to think up what are prompt engineering tasks that I could try out. You can just use this prompt to have it generate the content for you. It can think up the ideas of the problems for you to solve with prompt engineering. And we can see in this simple example, it's already gone and tested some different dimensions of prompts for us and given us some opportunities to try out some different patterns. It then goes on and it gives us another interesting one. Given a date in the format, Y, Y, Y, mmm, D, D, meaning year, month, date, determine whether the year is a leap year, or if not, if it is a leap year, the year is YY is a leap year, if it's not. And so how do I solve this? I'm going to go through and give it some few shot examples kind of similar to I did before, but it's testing my ability to figure out, what do I do to solve this in this particular case, and then it gives us the right output that 2023, is not a leap year. Now, what's really nice about this is, remember, it's it's supposed to be checking our prompts and testing our prompt engineering skills. And I want to show you something that I didn't even notice until it told me and tested me. So I said, [15233:52:00] 0: date, 2009, [15243:27:59] 0: 724, so july 24 2009 and then I asked it. And then, in my example, I said, leap year, right here. And then I said, the year 2004 is not a leap year. So my prompt example actually had a mistake, because I'm asking it if 2009 you know, July 24 2009 is a leap year. And then in my example, I give it the wrong template. I say the year 2004 is not a leap year. It should have been. The year 2009 is not a leap year. And then it actually notes that right here, it says there's a small typo in the third example, the year 2004 is not a leap year. Should be the year 2009 is not a leap year. But this did not affect my ability to understand and respond to the task, but it does give me feedback on my prompt. Engineering also shows me I need to be careful about the examples I'm giving it if I make a mistake in my example, in this case, I got lucky and it didn't affect things, but it could. In future ones, it then goes on, gives me a new one, which I didn't actually go and solve. Given a string of characters, determine whether string is a palindrome, the string is a palindrome. If the string is not a palindrome, return the string is not a palindrome. Replace string with the actual string. So it's getting a little repetitious in here, but we could go in and inject additional sort of ideas to help tailor the output even more. So you can imagine we might want to go in and target our prompt engineering a little more. Now we've been learning a lot of prompt patterns in this paper, so one way we can adapt this game is we can give it a more specific topic about the type of prompts we're trying to develop. So in this example, I'm going to take the description of the recipe prompt pattern, and what's helpful is you can go to our prompt patterns paper, and you can actually take a little section or explanation of those patterns along with the name, and you can provide it into this game as context. And it does a reasonable job if you provide enough information on the pattern and examples of asking you questions that would use that pattern to solve it. So in this one, I go and I actually modify the game, and I say all of your questions should revolve around the recipe prompt pattern. This pattern provides constraints to ultimately output a sequence of steps given some partially provided ingredients that must be configured in a sequence of steps to achieve a stated goal. The pattern is not about cooking, per se. Now I added this in here because I knew, I knew, knew, knew in my heart that it was going to want to ask me cooking questions. That's fine, but I've done enough of those, but creating a complete sequence of steps to achieve a goal given an incomplete list of intermediate steps. So I really want to use this. Cooking is obviously a natural way of talking about recipes, but I don't want it to clue in too much on that. I'd rather do some other interesting tasks. And so then it says your goal is to create a prompt that instructs me to generate a sequence of steps for assembling a simple wooden bookshelf. The bookshelf has four main components, the top and bottom panels, the side patterns and the side panels and the shelves you've been provided with the following ingredients, attach the top panel to the side panels, insert the shelves into the designated slots using these intermediate steps, create a prompt that will result in a complete sequence of steps for assembling the bookshelf. Remember the prompt should be designed to fill in any missing steps and provide a clear order for completing the assembly. Now what's interesting is this is kind of an interesting prompt, because it has to have an understanding of a bookshelf and its structure. You would have to go and write a prompt that's going to elicit the right problem solving behavior on assembly of a bookshelf. So it's kind of a cool little problem. I then went and I took it, and I said, All right, well, let's use another one of the patterns from the paper. And so I adapt, and I say, we're now going to change the topic of your questions. The topic is now the context manager pattern. And then I'm basically providing the intent and context from the paper. And I'm saying this paper enabled, or this pattern enables you to specify a removed context for a conversation, and I'm not going to go into the details, it did a pretty good job. It asked me a question about the Eiffel Tower and its construction. Then I went and I said, Change the topic again. I said, we're going to change the topic of the question. The topic is now the template pattern. And I described what the template pattern is, and it actually does something that, you know follows what, what is exactly said in here when she's might want to generate a URL. So we might get all URLs we might want to, like, tweak this a little bit, but I but it does a good job. It then gives me a task. Your goal is to create a prompt that instructs me to generate a URL for a product page on an e commerce website. The URL should follow a specific template structure, and it gives me the structure, product ID, slash name, the product ID and product name are placeholders that need to be replaced with the actual values. So you can see how I've got this gain. It can test me on prompt engineering. So I'm learning about prompt engineering. It can actually give me helpful feedback. It caught a typo in my few shot examples, and then I can go and tweak it. I can say, Okay, now the topic is, we're going to do a game based on this particular prompt pattern. Now we're going to do one based on this pattern, and what you'll see is you'll get interesting content that will come out of it and challenges of things that you can try to prompt. Now they may not all be good, they may not all be interesting. You may get in a rut where they're kind of like getting repetitive, but that's that is on you. Then to think about what additional information do you go and inject into this game to make it fun again, or to make it more variable? I was pretty surprised at the quality of questions that I got, and it brought in a lot of topics, like assembling a bookshelf is not what I would have thought about. That's that's certainly an interesting one. Or when it asked me about information related to the Eiffel Tower and its construction, all of these things are kind of bring fun to the game. Or is it a leap year or not? All of these things are kind of interesting ways. And all I did is gave it, kind of the base rules, and then the topic area, and then it pulled in all this information to populate the game with things that kind of help keep me engaged, new content, new ideas to challenge me and make me have fun. And in this case, writing out the rules is a lot easier than thinking up all the content for the game, which it does really effectively. You [17102:13:20] 0: it. Getting the large language models output in exactly the format that we want can be a challenge sometimes. So the next pattern that I'm going to teach you about is going to help you get exactly the format you're looking for, and tell chatgpt where you want the information that it's producing put into the format. So you're basically going to give it a template, and then chatgpt is going to go and fill in your template, just like you might do with an assistant, where you'd say, here's the template that I use for creating these form letters, and here are my different placeholders within my template, and then your assistant could go in and fill in that template. And that's exactly what we can do with the template pattern. So the idea behind this pattern is we would like a specific template followed for our output, and we can describe that template to chatgpt and then have it produce all of its output using that template. Now we could do this with other approaches, like few shot examples, but we're going to do this with the template pattern in this example. So here's what the template pattern looks like. We say, I'm going to give you a template for your output. We're cueing the large language model that there is a template that's going to be in play and it needs to follow it capitalized words are my placeholders. So we're telling it when you look at the template, if something is capitalized, that's something that you're going to replace with the content that you're generating. Fill in my placeholders with your output. So there's our cue to it to go and replace the placeholders, and please preserve the overall formatting of my template. We don't want chatgpt to just decide on its own what the format should be, and ignore everything that we're giving it in terms of instructions. And then I say my template is and I've got this sort of funky little template down here, and I'm going to talk through it. So I have question with three asterisks in front of it and then three asterisks following it. Now what this is going to do, actually, is this is using some knowledge of how chatgpt, in the chatgpt interface, formats the information that we see. So those three asterisks are basically going to need you're going to italicize and bold. This is like a heading, so it's going to say question, and it's going to be in italics, and it's going to be in bold, and then we want it to fill in a question. So question which is an all caps, and notice we're differentiating between things that are part of my template, and things that are capitalized, which are things that are placeholders that it fill in, and then we're saying answer. Similarly, it's going to be in italics and bold. And if you want to figure out how this works, this is called markdown, so we're basically chatgpt is rendering the output to you in Markdown. So I'm just using this knowledge to help me out a little bit. And so I'm creating a template that includes markdown, and then we're using a placeholder for answer. Now you can guess I'm going to have it generate questions and answers. This is what's going to come next, but right now, I'm just telling it what the template looks like. Here's what my template is going to be, and I'm going to ask you to fill it in, and then I tell it, I will give you the data to format in the next prompt, create 20 questions using my template. And of course, it says it's happy to do that. So then what I did is I pasted in from Wikipedia an article on paleo Indians. My son was studying paleo Indians at school, and so I thought it would be fun. Can I generate some questions about Paleo Indians for him and see if he can answer them or learn more? And it might be interesting to to talk about these questions. And so I paste that in, and then what we see is we get output that follows the template that we gave it. So if you remember the first thing was question, and it was not in caps. So this was something we wanted it to preserve. And then we had question in all caps, and chatgpt has generated a question about the Paleo Indians, who were the Paleo Indians. Now, interestingly, it has decided to put this in all caps too, which actually kind of works for the format. I didn't actually mean for it to put it in all caps, but it works. And then I had answer, which was not capitalized, and then I had answer was something to be filled in that was in all caps, and it fills in the answer. So it's creating questions about Paleo Indians, who were the Paleo Indians, and then it's filling in the answer to the question. But the whole thing is structured using my template. And I told it generate 20 of these questions, and so it's basically repeated my template 20 different times, but filling in the content. Now notice these are like really powerful placeholders. The placeholder I get it gave it was question, and so it has to understand, what is the meaning of the word question it looks at and has to understand to some degree. And people may argue it's not really understanding anything. It's doing something else. I'm going to talk about it in terms of understanding, because I think that's a natural way to talk about it if we later discover it doesn't really understand, it doesn't matter. The template pattern is a great way of using this, and it's easier to talk about it in terms of understanding. So it's understanding the placeholder that it means question, that your question that you generate should go here, and then it's understanding Answer. Answer is where the answer to the question should go, and it knows from my prompt that it's supposed to generate 20 of these questions based on the content I'm giving you. So it's extracting 20 questions about the Paleo Indians and producing the question and the answer and formatting it according to my template template, like we see here. And we get a bunch of questions that we could go and then, you know, have a discussion about so there's a there's a first example of it. We can also go and take it and say, Take this, you know, a little bit further. So I took my colleague, Doug Schmidt, and I imagined like, well, what if I wanted to go meet Doug Schmidt for the first time, and I wanted to try to know something about him, and have something to talk about and make sure I was versed in his background, so I could intelligently talk about what he was doing, what he was interested in his background. And so I just took his web page here. Now chatgpt explains to me, Hey, I may not have a version of this web page before 2021 it's kind of fascinating that it actually is able to take information from a web URL. Little trick. It may not be up to date. Of course, you should if you're going to use this before meeting somebody own the information and make sure it's actually correct, but it could give you a starting point. And so then it goes and generates 20 questions using the format that I gave it about my colleague, Doug Schmidt. Now, [18993:57:20] 0: looking at the [19006:29:20] 0: questions so far, they seem pretty good. Now, if we wanted to do this in a more reliable way, we could have pasted in the actual questions or the past in the actual information from his web page, in order to get information about him and generate 20 questions. Now I'm going to show you another example, because I talked a little bit about these placeholders, that they're not just placeholders, like there's a real deep understanding of the meaning of the placeholders when you're using the template pattern, you don't just have to think of them as being really easy to match. They can also be kind of Smarter placeholders, a placeholder that you might give to another human being if you wanted to explain to them how to use the template you're providing. So let's look at this example. I'm giving it the same sort of preamble for the template pattern. I'm still using capitalized words. I'm still using markdown to try to get this formatted in a way that I want. This case, it's going to create headings wherever I have these hashtags. And so what I'm doing is I'm saying bio and name, so I'm going to paste in information about a history of Vanderbilt, and I would like to get basically a list of people from that history of Vanderbilt, and I want the names of the people, and then I want an executive summary for each person and a full description for each person. Now I'm stating that my executive summary is a one sentence summary. So you notice my placeholder is more than just go and talk about this person. I'm actually putting constraints on what I want there. I want one sentence that summarizes this person's role as described in the information I just gave. And then, for full description, I say I want a one paragraph summary. Now you can imagine you could go and capitalize a complex set of instructions, a one paragraph summary that only considers their, you know, history as part of Vanderbilt, you know, before 1800 now, I haven't actually tested that one out, but I suspect it would actually work. But the key thing to note is I'm giving it more than just a simple match. I'm actually giving it a match on summary. Go and create a summary here, but I'm also putting constraints. So what it should be, it has to be a one paragraph summary, you know, or a one sentence summary. And so this is like a power of the template pattern is that we can kind of have complex instructions in the placeholders that we're actually going and replacing. So now I'm going to take a look. I pass through quite a lot of information in and this is what we get as a result. Is we get the headings as we had before, with the name, that all makes sense. But then if we look at the executive summary, it's exactly one sentence. So it's not only filling in the template, but it's filling it in with the rules that we've described in the template. So now we've got a one sentence summary in the executive summary, and in the full description, we've got a one paragraph description, and it goes through this for every single person that it extracts from the from the information that I give it. So the template pattern is a way to help you get the output that you want in the format you want. And you can use the placeholders in really sophisticated ways. They can be something that can semantically extract information. So I can dump a bunch of information in and say, I want to know the people, and it has to understand who are the people in this in this box, you know this, this bucket of information that's just been dumped in, it has to be able to extract the people. And I can say, I want a summary of each person, but it has to be one paragraph. So you can have instructions and constraints on these placeholders. You can also have sophisticated things. We could have said, for example, what is the role of each of these people in the history of Vanderbilt? And it could describe their role. So the placeholder can not only format the information, it can not only do sort of simple extracting and matching. But it can also do sophisticated things. It can follow rules or do things that would be really time consuming for a human, like take and extract information that would require a human to read through and understand and then put it in. So we're saying create a one sentence summary of this person. Well, if I was going to have an assistant do that, they'd have to go read all the information and then make a list of all the people. For each person, they have to write first the one sentence summary to try to capture everything about that person, and then they have to go write the one paragraph summary. So that's really fast, really sophisticated intelligence that it's using, and the key to getting the output that we want from it is using that template product we're saying this is the format that you're going to give it to me in. This is exactly where everything goes. And here are these sort of really sophisticated rules in the placeholders to help you decide what goes in, how it gets formatted, what to exclude. It's a really, really powerful pattern for getting information in the format that you need and getting the right information put into that template. [20492:42:40] 0: You describing everything in full English sentences or full sentences in whatever language you speak isn't always the easiest way to give the input to the large language model. Now, if you think about in the real world, a lot of times, we have our own specialized languages to describe different domains. So math may have its own specialized language, or we may have shorthand for taking notes or describing different interesting things, we may create our own little languages to to be able to capture information in a more concise way than if we wrote it out in full sentences. Now, of course, the key to these languages is, is that the person that we're communicating with in the language knows the language to they know the meaning of the different statements that we're making, the different symbols or words that we're using. Now as an example of this, we've been doing a lot of work in partnership with the City of Nashville and the emergency responders, and one of the things they do is those, those the the the operators who are taking calls, and you can imagine this is a really stressful situation. They're trying to take notes down about what's going on in an emergency, and they actually have their own shorthand notation. Can you can imagine the stress and difficulty of receiving a call or at an emergency and trying to take down information that can then be used to, you know, take the appropriate action, send an ambulance or send a fire truck or whatever needs to be done. And so they have their own little shorthand notation. And if you go and just try to read this, you don't, you're not necessarily going to be able to read it and understand it, because it's designed for people who use it day in and day out, to be able to communicate with each other, but not necessarily to be as explicit and obvious as possible. So I'm going to teach you a pattern where we can basically teach a large language model a new language, and then communicate with the large language model in that new language, or shorthand. So this is called the meta language creation pattern. So we're going to create a language. This is going to be our meta language creation where we're going to go and describe to the large language model what our language is, what are the meanings of different symbols or statements in that language. And then we're going to go and converse with the large language model using so let's look at our example. Here. We're going to create a trip planning application. Now I haven't gotten into the meta language creation pattern, but I'm giving you an example that uses it. So we're going to create this trip planning application. I will describe my trip, and you will list interesting things to do in the places that I will pass through. I will tell you how many days I will stay in each place, and you will list possible itineraries. So far, we've just got a prompt to help us do trip planning. Now here's where we're going to go and use the meta language creation pattern. I'm going to say describe, to describe my trip, my route. I'm going to use a shorthand notation so we're queuing it in, and we're going to tell us about this shorthand notation. When I say and notice this Nashville comma three, arrow, Memphis comma two. I mean that my route will go from Nashville to Memphis, and then I will stay three days in Nashville and two days in Memphis. Now I want to kind of draw your attention to something here. Notice that I'm starting off by saying when I say this, here's an example of my new language that I'm creating, or my new shorthand that I'm creating, I mean this. And so you're taking an example, and then you're showing it what you mean. So you're then saying, I mean that my route will go from Nashville to Memphis, and I will stay three days in Nashville and two days in Memphis. So you're giving it basically a translation. Now, another way to think about this is similar to few shot examples. You're saying, here's an example of, you know, input, here's the example of the output, or here's the example of a comment on a movie. Here's an example of the sentiment analysis for that comment. You're kind of doing something similar, except what you're doing is you're saying, when I say this in my language, this is what I mean, and you're showing it the translation and the meaning behind it. The other thing to note is that my notation is much denser than the full English that I'm going to use. So it's Nashville comma three, Arrow Memphis comma two, and it's that short thing is describing this much longer basically, statement that says my route will go from Nashville to Memphis, and I will stay three days in Nashville and two days in Memphis. I could write all this out, but I want to have my notation now. It goes ahead and trip plans for me on Nashville and Memphis, and I'm going to skip that, and I'm going to go down to now where I have an actual just statement. So notice we've now programmed our new language. We've done the meta language creation pattern, and now the large language model understands our language. So we say Nashville comma zero and Nashville comma zero means I'm leaving from Nashville. I'm not going to stay there. I don't want you to trip plan for me in Nashville, which is an interesting thing that has to consider that in the lodging I'm going to Dallas, Dallas, comma one, and then arrow, Granbury Texas, comma four. And so basically, what I'm saying is my trip is going to go from Nashville. I'm not going to stay there at all Dallas. I'm going to stay there one day, and then I'm going to stay in Granbury, Texas for four days. And it says, Sure, since you mentioned that you won't be spending any time in Nashville, I'll focus on providing you interesting things to do and possible itineraries for your one day. Stay in Dash, Dallas. In your four day, stay in Granbury, Texas. So it then plans our one day stay in Dallas. We have a one day stay in Dallas. It describes what we're going to do on that day. It then describes for Granbury, Texas, over here, says four days, and then it describes what we're going to do in Granbury for the four days. Now, if I wanted to experiment with different itineraries, and I wanted to really quickly, have a shorthand for saying, Well, what if I did this itinerary? What would I do? What if I did this one? It's a lot more condensed. Now also, I have to admit, I'm a computer scientist and a programmer, right? So I like having things that look like condensed programming language instructions. But you can imagine, a lot of people use shorthand notation, abbreviations. You can use them too in the language model. You just have to explain it to it, unless it already knows it. If you're using something that's well understood, you can just say I'm going to use this language, or I want you to interpret this in the same way that you would interpret it in a math context, and you could explain what that means. So it plans our trip. Then here's where I go and try it again. Look, I'm getting a more complex statement. I'm saying I'm going from Nashville to Fairhope, Alabama, where I'm going to stay three days, to Gulf Shores, Alabama, where I'm going to stay one day to Montrose, Alabama, where I'm going to stay one day. So now I've got a much longer statement, and if I had to write that all out in words in full sentences, it would take a lot longer to write it out in full sentences. But I've described the language, and now this kind of crazy string that I put together, it knows to take that and use it as the input for the trip planning. So now it says fair hope, Alabama, three days, and it gives me my planning for my itinerary there. So it gives me my day one, day two and day three. It then says Gulf Shores, Alabama one day, and then it provides my itinerary for that one day in Gulf Shores. And then it understands mantras Alabama, and gives me my one day stay in Montrose, and gives me examples of things to do. So you can imagine that this is a really sort of helpful capability. You may want to go and start thinking about, how do I develop a shorthand notation for the task that I do really frequently with the large language model, and where it would save me a lot of time and effort if I could describe what I want using some shorthand, and maybe we can also describe it more precisely. Maybe there's a way to describe it more consistently. So if everybody uses the shorthand, the meaning is less ambiguous because we've already defined it in advance, and there's less you know, there's less variability in the explanation or in the how you express it in the shorthand. So maybe you're an organization and you want everybody to express certain information the same way, to make sure that the reasoning from the underlying large language model is consistent. And so now it's not always necessarily going to be consistent, but at least you would get the data you know entered in in a more consistent way. So you could define your own language for your organization for describing certain types of information, and teach that to your people so that when they go in and they enter in that information, you're going to have a consistent sort of semantics to what that information means. Now, if everybody goes and just describes it in English using whatever phrasing, whatever level of detail, etc, that they want, you may not get the outcomes you want from your prompt. So by having your own language or shorthand, you can help constrain how you define things, how you express information, to the large language model, and hopefully help it reason better. I them. [23223:44:00] 0: Sometimes we know part of the solution that we need when we're working with a large language model. So we have a problem, and we know some of the steps, or some of the pieces that we want involved in the solution, but we don't know the full solution, and what we need is the large language model to help us fill in the blanks to put together the missing steps, basically to complete the recipe. Give us the detailed set of steps that take the ingredients that we have or the bits of information we know about how to cook this particular dish, and fills in all of the gaps. And so the recipe pattern is a pattern for doing this. We give the large language model some goal that we're trying to achieve, and we give it the parcel set of steps that we know that we're going to have to, you know, involve in creating the overall sort of solution, the recipe, the goal, whatever it is, we're going to give it part of what's needed and ask it to fill in the rest. So this is really a a way of getting the large language model to help us fill up, fill in our gaps in a process, or gaps in our knowledge about a series of steps that need to be taken. So the recipe pattern can be really useful. And I'm also going to show you that our sort of intuitive shorthand for describing gaps and ways in that we talk about things that we know are part of a process or part of a series of steps, but we don't know the exact details that our intuitive way of expressing that is actually something that the large language models like chatgpt can understand. So let's take a look at example of this. So we're going to say we're going to add a feature, so we're going back to our trip planning application, and we're going to say, I will tell you my start and end destination, and you will provide a complete list of stops for me, including places to stop between my start and destination. So notice, what we're doing is we're providing essentially an incomplete recipe. We're saying, here's where I'm going to start, here's where I'm going to get to, but I need to know what goes in between, and it goes back. And it takes one of our prior examples of going from or actually, it creates its own example of traveling from Nashville to Atlanta, and notices that you're going to go through Chattanooga on the way, which is true if you're going to drive from Nashville to Atlanta, you're probably going to drive through Chattanooga. And it suggests things that you could do, like going to the Tennessee aquarium in Chattanooga or Lookout Mountain. So where it gets interesting is, if you remember, back to the trip planning application, I taught it my own language for describing my trips, and so I used the metal language creation pattern. Now I'm going to combine the metal language creation pattern and the recipe pattern to do something interesting. So what I'm going to do is I'm going to say Nashville comma zero. So I'm starting in Nashville, and then I'm going to have just dots, or, let's see, basically, dot, dot, dot, arrow, dot, dot, dot, arrow, Fairhope, Alabama, two. So I'm going from Nashville to fair hope Alabama. And basically what I'm signaling to the model is I want you to complete it. Tell me where to stop in between. And I'm indicating I want to stop twice. I'm willing to make two stops in between, but I don't know where you fill in the recipe that gets me from Nashville to fair hope and has two stops in between. And it understands this, so dots are obviously.dot.is a natural way that we can express something we don't know. It understands that, and it fills in the recipe. It says we're going to start in Nashville, Tennessee, no time spent, as per your request, if you I highly recommend spending time in Nashville, Tennessee. I live here, so all of my trips start with not doing any, not staying in Nashville, because I'm always here. Well, not always, but a lot of the time. And then it fills in the two stops for us. It fills in Birmingham, Alabama and Montgomery, Alabama, which are both between Nashville and Fairhope, if you take the most direct route and then the end is going to be fair. Hope, Alabama. So you notice it's basically understood the constraints that we placed on it. We said Nashville, comma, zero, arrow. And so we're using our language. We're just defining the starting point. We're then saying dot, dot, dot, meaning this is something I don't know. It's a blank spot in my template or my recipe. So you need to fill in this recipe with where we should stop here, and then arrow dot, dot, dot. And I'm saying, here's another blank spot where I don't know what should go here in the recipe, fill it in, and then arrow fairhop Alabama. And so it's gone. And we're using the recipe pattern here to get chatgpt, or another large language model to complete our request. And if we went and we did this again, so if we said, you know, LA and let's just do one, and then we said, dot, dot, dot, dot, dot, dot, dot, dot, and we'll see how it interprets this. Because I think it's unclear to me, unclear to me what it even means. And then we said, we're going to go to New York. Let's see what it interprets this as. And so it now starts giving us a trip. Saying, Okay, here's where you're going to start, Los Angeles, one day, then you're going to go to Las Vegas, Grand Canyon, Santa Fe I'm curious if it'll how many stops it's going to have. So you notice that when I did this one, I had four placeholders here, I'm getting more than four placeholders in between, because I kind of expressed that I wasn't really sure. Like, I don't have dot, dot, dot arrow, dot, dot, dot, arrow, and then I'm there. I just have that, you know, a whole bunch of dots, which is much more indefinite, which is exactly what I wanted to do, interestingly enough, and I didn't know if it was going to get there, but I was basically expressing, I'm going to go from LA to New York. I'm going to have a bunch of stops in between. I don't know what they should be. Plan my trip for me. Here's how long I'm going to stay in LA here's how long I'm going to stay in New York. And everybody can argue with how long I've spent in each place. They're all wonderful places, but it interprets the missing pieces of my recipe. It probably also knows that I'm going to need quite a few stops, and I'm going to make this a leisurely drive from Los Angeles to New York, and it fills in a whole bunch of different places that I could potentially stop along the way in order to have an interesting trip from Los Angeles to New York, if I run a very long road trip as a vacation. And so this shows you how the recipe pattern works. You give the large language model the goal that you're trying to achieve, the pieces that you know need to fit into the solution, or the steps that have to be there and where they're going to be placed. And then you ask it to fill in the rest. And you can use ellipses or other types of things to indicate places where you don't know what's going to be there, and you want it to fill it in, and it'll go and complete The recipe for you using The recipe recipe pattern I'm [25351:12:00] 0: brainstorming different approaches to solve a Problem is a really, you know, interesting way of using a large language model, and one of my favorite uses for it. So something I really like about large language models is that I can come up with a problem that I want to solve, and I can rapidly, rapidly come up with different ways of solving that problem, and I can test them out and get feedback. Now, one way to do that is using the alternative approaches pattern. So the idea behind this is, we're going to have the large language model within some particular scope always suggest alternative approaches for solving a particular problem or or performing a particular task. That is, we always want it to give us good ideas that now I say good ideas. They may not be good, they may not even work, but, you know, kind of like brainstorming in a group, you may have a lot of different ideas. Some of them may be great, some of them may be terrible, but just the fact that everybody's thinking through ideas, throwing them up on a whiteboard or writing them down, or talking about them can help you, you know, do a better job of thinking through the problem and figuring out what is the right solution that makes sense. So I'm going to show you how to use the alternative approaches pattern to essentially perform brainstorming with the help of a large language model. Now one of the things to note is, just like if you get a group of participants that have different backgrounds, they may help you come up with ideas that you yourself would not have come up with. Well, a large language model was trained on a big corpus of material, and it's probably seen lots of problems and seen discussions of different solutions to that problem, or different alternative approaches for a particular problem. So you can think about it. It's it is in some ways, learned information about how to solve problems in different ways, and can help us get access to that knowledge. Now, it may also have seen, not, never seen, the exact problem that we're asking it for, and it may be able to synthesize using what it's seen in the past, interesting potential approaches, even it hasn't seen the exact problem that we're working with. So let's start off with an example of this. We're going to do the alternative approaches pattern. We're going to say from now on, if there are alternative ways to accomplish the same thing, list the best alternative approaches. So this is a very generic wording for this. It's probably better to structure it very you know, precisely to the tasks that you're working on provide more rich sort of context. But I'm going to show you that even within a fairly generic wording, we can get this pattern to work for us. And then I'm going to say compare, and I'll contrast the alternatives and ask me which one I want to use. So I'm adding a little bit to this pattern. I'm saying, Give me alternatives, but also give me some information, compare and contrast the alternatives. So maybe that'll help me, you know, think through which one is going to better fit my particular situation. I can see if you know, what is the what are the pros and cons of each approach, and which one sort of is a better fit based on those pros and cons. And so I then ask it, if you think back to in some of the past videos we've looked at using gameplay to create prompts and test us on our ability to write prompts. And so one of the problems that chatgpt generated for us is it asked us to write a prompt to distinguish leap years. Basically, we would give it dates, and the prompt should be able to determine if it's a leap year or not. And so I'm going to turn that into a task for chatgpt. So I'm asking chatgpt to write several prompts for itself to solve this task. So I'm having chatgpt Write the prompts for me. Now I could have introduced this earlier in the course and just said, any task that you have you want to be better at prompt engineering, ask chatgpt to do the prompt engineering for you, and that's basically what I'm doing here. And sometimes this works, but I don't want you to think that this is the best approach, that I should just always go to chatgpt and ask it how to do it. Now you should have a sense yourself, just like any problem you're bringing into a large language model, you have to own the content. So you should have some expertise in this area to help you distinguish what are the better approaches, what things don't make sense, what's unsafe or harmful in some way you need to own whatever content comes out. So that's part of the reason I didn't just start by saying prompt engineering, go ask Dash Chat GPT for the prompt. We're not going to do that, but in this case, we are. We're saying we want chat GPT to write a prompt to use few shot examples to determine if a date in the year, month, day format is a leap year, and the output should either be, year is a leap year or this is not a leap year. And so chatgpt then says approach, one direct question format. In this approach, we directly asked chatgpt whether a given date is a leap year, and then it shows us the few shot examples for doing this. So it's generating the prompt force that we could provide, you know, use essentially to go and check if something's a leap year. Then the second approach, it says conversational format, and then it uses a completely different sort of style. It's still roughly the same format of generating few shot examples to solve this problem. Now, notice I scoped it to few shot examples. I could have left the scope more wide open and just said, Write a prompt to do this, but I thought it'd be fun to look at different you know, can we write the few shot examples in different styles, and will it make a difference? And we could go and test this and see if it does, but we now see it generating again. It's solving the problem of showing few shot examples for elite years, and now it's actually I noticed something interesting. It's showing us how to solve the problem. It didn't actually fully follow the format that I gave it, because I said, Why? Why? Why? Why is a leap year? Or this is not a leap year, and it is putting the date at the, you know, the year at the front. So it's actually made a mistake, and this is part of the reason why you should read your prompts that it generates, so make sure they're doing exactly what you want. But I could go and repel it and fix it and refine it, but you notice now I've got two different approaches to few shot examples to solve this problem. And then at the end I get a comparison. It says approach one is more formal and structured, making it easier to understand and parse. It may be suitable for applications where a clear and concise answer is required. And then it says approach to is more conversational natural, making it more engaging for users. It may be suitable for applications where user interaction is important, which is kind of true. If you were going to prompt the user and then have like, here's what the user said, Here's what the assistant's supposed to say. You know, this would probably make sense if you were just, you know, reporting on a Q and A then maybe the other format makes sense. So it's it's a reasonable discussion of the different alternative approaches for solving this problem. Now let's look at another example. I thought, What is a task that can sometimes be burdensome, and so I thought about email. Now I haven't actually done this and tried it out on my email. I still kind of keep my email personal, if I can to my laptop, but I thought that this would be an enhancement in the future. If I was running a large language model directly on my laptop, something like llama or pocket, maybe I could do this, and I would be comfortable with it. And so I say, whenever I ask you to write a prompt for me to accomplish a task, and I'm going to change the alternative approaches pattern slightly. I'm going to tweak it a little bit for this one, list what the task is. List alternatives for completing the task and then write a prompt for yourself for each approach. So some basic format. Now I'm doing two things. One is I'm having it list the task at the beginning. So right here, I'm saying list the task, and then I'm saying list upon alternative approaches for completing the task. So this is going to be up front. One, it helps me know what its approaches are going to be before I even see them, I can see a preview. Two, this can actually be helpful for large language models, if you haven't kind of summarized the task and summarize different approaches or reasoning. This has been shown to be helpful in many cases. So I'm actually asking it to do that at the beginning, just to show you how you can tweak the pattern and get some possible improvements. In this case, it does roughly the same thing that we saw before. [27668:10:40] 0: And then I ask it, ask me what I want you to write a prompt for and so the prompt I ask it is, I say, write a prompt for chatgpt to automatically detect questions in a chain of emails and summarize everyone's questions as bullet points beneath each question. So the idea behind this is really this key part is at the end, you know, you can imagine getting behind an email and you want chat GPT or some other large language model that you trust looking at your email, that you put it in the whole email conversation chain, assuming that you're following appropriate privacy and other rules around whatever content is discussed in that email chain. Maybe you start with something like what movie or what restaurant people want to go out to eat. When you have, like, a group discussion, you know, you get to these long group discussions, and they've gone off the rails. People have discussed other things, thrown in jokes, you know, commented on other people's jokes. And by the end of it, you can't really decipher who wants to go to what restaurant and why, because there's all this other random stuff thrown in. So you might go and say, summarize the question questions and people's opinions on it, and it'll give you maybe just the discussion about the restaurant and people's perspectives. So you would dump this in, and I say, write me a prompt to do that. And so it gives me three different approaches. One, write a prompt that instructs chatgpt to first identify all questions in the email chain and then extract responses related to each question, and finally, summarize the opinions as bullet points approach two. Write a prompt that asks chatgpt to simulate a conversation where it plays the role of a summarizer, and notice it's basically using the persona pattern here in its own prompt for itself, asking the user to provide the email chain and then generating the summary with bullet points, and then finally, it says, Write a prompt that presents the email chain as a case study. That's an interesting approach. I wouldn't have thought of that. What's interesting is a case study. It probably read lots of case studies, so it's probably good at thinking about, how do you think through a case study and ask chatgpt to provide a summary report that includes the questions and the corresponding opinions and bullet points, and then it gives me each of the different prompts. So chatgpt, your task is to analyze the following chain of emails and identify any questions that were asked. For each question, please summarize the opinions expressed by the participants in the email chain as bullet points beneath the question. So it's generated its own prompt for itself, prompt approach to chatgpt. Let's simulate a conversation where you play the role of a summarizer and it goes on to discuss it. And then it has a slightly different format down here for how it wants things presented, and then finally, prompt for approach three, chatgpt, consider the following chain of emails as a case study that's really interesting and a completely different approach. That's when I just would not have thought of from the beginning. Now, maybe if I went to business school or something, I would be more thinking of case studies, and this is a natural approach, but this is something new to me. And so I can learn from how to write prompts, and now I have three completely different approaches that I could go try out without having to think of them myself. And I've also learned something maybe case studies and presenting different points of view on an idea as a case study is a good way to get output from chatgpt. Now, what would I like to do next? Well, I'd like to take my alternatives and I would like to evaluate them some way, and one way to evaluate output, particularly when it's just text, and you want to figure out how good does it look, does it seem? To solve the problem is just use the large language model to evaluate its own output or to evaluate the output of another large language model. Now, usually you want to do this in a separate conversation, right? You don't necessarily want to tell the large language model, you know. Now evaluate yourself. Sometimes that leads to worse behavior where it just says, Oh, I'm right, you know, sometimes what we want to do is take that into a separate conversation and evaluate it. And I'm basically asking it, how would you write prompts to take your own output and evaluate. How would you write prompts to evaluate the prompts? And so I say, write a prompt to evaluate several different prompts for summarizing the questions in an email conversation and the different stakeholders perspectives on the questions. And so then it gives me three alternative approaches. Again, approach one, write a prompt that presents multiple prompts to chatgpt and ask it to evaluate each prompts effectiveness in summarizing questions and stakeholders perspectives. Approach two, write a prompt that instructs chatgpt to simulate a conversation where it plays the role of an evaluator and the user provides different prompts for evaluation. So again, using the persona pattern, and then write a prompt that asks chat GPT to provide feedback on each prompt and suggest improvements of any and so there's, there's kind of a different take in each one. The last one is really about, how do we improve each one? Second one is using the persona pattern act as an evaluator, and the first part one is really to evaluate effectiveness. So they're kind of different, sort of takes on same idea, but now I have three completely different ways that I could go and take my prompts that it generated itself and kind of look at, you know, and evaluate them using chatgpt itself. I [29386:40:00] 0: Pride in our prompts instead of rules that we want the large language model that follow rules that are going to affect its output and essentially program the large language model. And one of the things that we're going to want to do, so we're going to want to say, here are the rules now apply them to an input that I'm going to provide later. And so one of the challenges is, how do we get the large language model not to immediately respond to all of our rules if we have a flipped interaction, for example, sometimes, when we flip the interaction and we say, ask us questions, it will generate 10 or 20 questions all at once. And so what we want a way to do is basically a simple way that we can get the large language model to listen to what we're saying, acknowledge it, and then wait for input from us. Now we can do this with the ask for input pattern. So the idea behind this is we want to get the large language model to listen to the rules and then ask us for the input to apply the rules to. So when we were talking about asking questions in a flipped interaction, we might want to describe the rules for asking the question, and then we just wanted to ask one question. So we just want to get one question out. If we're describing rules for alternative approaches, we might want to say, here are the rules. You're always going to create alternative approaches to whatever ask you to do, but just ask me now for the first task to create alternative approaches for we don't want it to go and have a big response to it. And what we see is that that's not always the case. So let's take a look at this example. Now, in a prior video, I introduced the alternative approaches pattern, and when you saw me use this pattern, it worked really effectively, because I was actually combining it with the ask for input pattern. So I'm going to show you what it looks like when I don't combine it with the ask for input pattern. So I went and I said, Whenever I ask you to write a prompt for me to accomplish a task. List, what the task is? List, the alternative approaches for creating the task, and then write a prompt for yourself for each approach. So I'm asking chatgpt Give me a bunch of alternatives for prompting you chatgpt To solve the task. So this is going back to the earlier idea where I showed how we could actually use chat GPT to generate prompts for itself, to help us with prompt engineering. And what I do is I use this, but I'm taking away something important that I'm going to show you in a minute. And what it does is chat GPT responds. It says, certainly, but then it dreams up a task. It says, Here are three alternatives for completing the task, organizing a cluttered desk. I'm not interested the task organizing a cluttered desk. It just responded to my initial prompt, which was, create alternative approaches for a task. It dreamed up a task and then dreamed up its own approaches for that task. Now I'm not interested in this, so now I've got my conversation, and it's got all this extra stuff in it that I don't care about. I had to wait for it to generate it. And you know, if I was trying to create some interactive experience that had some consistency, this would not be helpful. So what I can do is I can apply the ask for input pattern. And the idea behind this is we just do one simple thing, and then is at the end of the prompt, we tell the large language model to ask for the next input. So in this case, we say, ask me for the first task. So the very last thing we do, we describe all the rules, or whatever it is that we want in our prompt, and then the net. Last thing we do is we said, Now, ask me for the first task. Ask me for the first idea. Ask me for the first thing. You want me to generate a story about whatever it is, but it's a way that we can sort of cut off the large language model and tell it. Don't go generate a bunch of stuff. You know, I'm glad that you can do that, but what I want you to do is I want you to stop right here and ask me what I want to do. So it's a way of forcing the large language model to basically turn the control back over to the user and let them decide what to do next. Now, like all prompt patterns, when we're dealing with a larger language model, it is somewhat stochastic or random. It means it's not always going to do exactly the same thing every time, and it may not work 100% of the time, but this works very, very reliably to just say, ask me for the first input, or whatever it is at the end of the prompt because it clues the large language model, and then it needs to stop. And if we look at the comparison of the output, it's actually much more focused. So we see, in this case, it says, certainly, let's begin. What is the first task you would like me to create alternative approaches and prompts for rather than this much longer thing that it generated before that was not really helpful to what we were doing, so it kind of cuts it off. Notice, it's the same input, but it sort of cut it off. It's told it look, you need to stop right here, and you need to Wait for My input. I [31608:53:20] 0: one of the Things You may have noticed, started is I've started combining patterns together, and this is going to be one of the most important concepts when You want to build how To apply multiple [31797:46:40] 0: patterns in [32028:10:40] 0: a junction with each other in order to solve the problem you're dealing with. So rather than just thinking about, okay, which pattern can I use to solve this problem? Instead, what you want to think about is, okay, which pattern will solve certain aspects of the problem, and how would I combine those patterns together? And we started to see an example of this with ask for input and alternative approaches. Ask for input is a pattern that can be applied to with a lot of other patterns. In this case, we're applying it in conjunction with ask for their provide alternatives. And so we've got alternative approaches, and we've got ask for input, and they're being put together to build a prompt that's solving the overall problem. Now what we're going to see throughout this remainder of this course is that this is a way we build really, really sophisticated prompts, is to think about taking multiple patterns and combining them in interesting ways. Now, if you think back to some of the patterns that I introduced in the course and some of the examples I gave, now that you know more of the patterns, you'll probably see that I've actually been combining patterns all along in different examples. So in game play, for example, I probably used ask for input, and in game play, I used, probably the persona pattern. And so you can see how putting things together helps us solve the overall problem. And so when you're going and you're trying to tackle some new, complicated prompt that you need to engineer and develop, you want to think about, okay, what are sort of the fundamental pieces to this problem, and do I have existing patterns that I know about that I can use to hopefully tackle all of it? But if I can't tackle all of it. Can I use patterns and apply them to as many different pieces as possible, so that your unknown piece that you really have to start from scratch and invent something new, that it's as small as possible, that we can start with as many pieces as possible with a roadmap for them, a pattern to apply. And so that's what we're going to be doing now. It may start to seem more complicated than it is, but at the end of the day, what we're still doing is we're still building up language, right? We're still writing in natural language, we're still writing sentences, we're still communicating. We're just thinking intentionally about the patterns in our language, and we're thinking about what are the statements in the organization of those statements in order to solve the problem. And so in some ways, combining patterns is really doing a more powerful version of programming. We're starting to take different sort of programs or instructions that we know how to use and put them together in more complex and sophisticated ways in order to have prompts that have more power to them, that have more depth to them. And again, you know don't, don't feel that this is something you can't do. Everybody can do this. At the end of the day, think about it. You're just describing in words what you want done. You're still describing in language what you're trying to accomplish. And all this is doing is helping us think about what should go into the instructions if we're going to use this pattern, it's giving us a set of, you know, a set of of commands, a set of a set of statements that we need to include, and sort of an organization for them. If we're going to use this pattern, we're going to have a set of statements that we're going to include, and oftentimes, putting things together as simple as just taking the statements from each pattern and making sure they all show up in the prompt. Sometimes it's that simple. Sometimes it's more nuanced, and we may need to make sure, you know, a certain statement ends up in a certain place, like with the ask for input pattern. We probably always want the ask for input to show up at the end of the prompt, because otherwise it doesn't work nearly as effectively. So although putting patterns together can be a little bit tricky, sometimes, if you have to figure out where things should go, most of the time, it's as simple as putting the statements together. So as we go through the rest of the course, what I would encourage you to do is to notice when I'm using multiple patterns together to solve a problem and to think about as you're trying to tackle new tasks with prompt engineering, how to use multiple patterns In conjunction with each other to solve the problem. You [33223:49:20] 0: so there's a limit to how big we can go with the large language models, they fundamentally have a limit to the size of the input we can give them, so how big of a prompt we can give them, or how long our conversation can be, and they can still remember it, and there's just a limitation on how much output they can generate at once. Now it's inevitable that these language models are going to keep getting bigger and bigger, and we're going to be able to give them more and more input and get more and more output from them, but more than likely, everybody is going to face some limitation on how big we can go. Now the way that we work around that is we're typically generating pieces, like we generate a piece of the solution, and we take it. So you can imagine, if you're trying to generate a book, you can't just tell chatgpt At this point go and generate a book for me. It's not going to do it. It's going to tell you, Well, I have to stop my endpoint at some point. And similarly, you can't just give it 50,000 pages at this point and dump it into chatgpt and ask it to give you an answer, or 100,000 pages or a million pages, there's always going to be a limit, probably on the amount of information, so we need a way to work with it in smaller pieces, but still be able to put all the pieces back together. So one of the ways that we can do that is by building an outline of what we're trying to put together, and we can build the outline out. We can build it to the level of granularity that we want, and then we can start filling in the pieces once we've gotten enough detail into our outline. And then we can go and generate individual pieces, and we can know where they all fit together. So this is an effective way of using it to generate the pieces. Now this is basically putting a plan together. This same approach works for all kinds of things. It could be software anywhere where we can go and sort of have this outline, like structure, and then when, if we generate something that fits sort of the outline or the plan at that point, then we can go and work with it. Now we're going to look at a specific pattern that can help us generate the outlines and work with them. This is called the outline expansion pattern. And so the idea is we want to make it really easy to generate outlines and continue to expand them down to the level of granularity that we need in order to build the individual pieces then be able to put them together. Now, one of the reasons that outlines are a really helpful tool when we're building bigger, bigger bodies of work with a tool like chatgpt Is that an outline, we can always take parts of the outline and copy and paste or reintroduce them into the prompt to give the large language model context about what we want. So with chat GPT, for example, we can generate an outline, and then we can copy and paste a portion of the outline into our prompt and say, within this context, here's your where you are in the outline. Now fill in the content for this and don't repeat anything that would have come before in the outline. And in fact, you can refer to the other parts of the outline, wherever you're going to talk about a topic that was discussed previously. Or maybe we want to have forward references. What we can provide at the high level outline, and say, wherever you are going to need to talk about a topic that's later, that's going to be discussed later, you can provide a forward reference to where it is in the outline. You can do similar types of things with software or other sort of whatever. The bigger thing is that you're building. Now this works well when we have a structure that's an amenable to sort of this outline based plan. Now sometimes we have plans or structures or designs where everything crosses over and you can't easily do this. Doesn't work to express it as an outline and express the plan. And in those cases, it just doesn't work. But many problems we can sort of build out in the sort of outline, like fashion, and then we can use cutting and pasting from the outline to provide the appropriate context. So building outlines can be a really powerful thing for us. So we're going to look at and build with the outline expansion pattern. So here's what we say. We're going to say, act as an outline expander. And notice I'm starting to introduce multiple patterns here. I'm basically introducing the persona pattern. Generate a bullet point outline based on the input that I give you, and then ask me for the bullet point you should expand on. So we're telling it you're going to generate the outline, and then you're going to expand on anything that I ask you to expand on. Create a new outline for the bullet point that I select at the end. Ask me for what bullet point to expand next. So notice I'm using the tail generation pattern as well. And then I'm using the ask for input pattern, so I'm putting a lot of things together into this prompt. And I say, ask me for what to outline. And so what we see is it says, Sure, I'd be happy to help you with that. So I say, let's write an outline for writing effective prompts for chatgpt. And so what we see is that chat GPT generates this outline, and it's an interesting outline. Introduction to chat GBT, understanding the importance of prompts, tips for writing effective prompts, yada yada yada. So a lot of good things there. And then I decide, okay, let's go and expand on three from the outline. So if we look back here, three was tips for writing effective prompts. I thought, let's go ahead and expand the outline there and explore this a little more. And so then it picks up from three, and it expands on tips for writing effective prompts and gives us a new outline. So we built in using this pattern, we can rapidly fill in an outline. And probably there are going to be tools to support us in this very soon, or plugins to support us in this very soon, to where we don't have to remember all the pieces of the outline. With this, I would probably just manually have a document where, as it was generating the pieces, I would go and look and say, Okay, here's the three. I'll paste three in and its expansion now, and you can easily fit the parts together. This is one of the nice things about the outline approach, is that it's really obvious how all the pieces fit together. I know that 3.1 goes underneath three, so it's sort of self describing in terms of the assembly. So if I generated a piece of an outline here, I've expanded three. I know exactly where that goes, how it fits together in the overall whole then I go and say, Well, you know this idea of experimenting with different prompt styles that looks interesting, so maybe I should go and expand that further in the outline. And so I basically say 3.2 [34982:50:39] 0: and now it goes and expands the outline around 3.2, so you see how we've we've got a simple pattern, and we now can go and rapidly create an outline and keep expanding it to the level of detail. And because of it's using this outline structure, it's really easy to fit all of the individual pieces back together. And as long as we have limitations on how much input, how big of a prompt we can give, and how much output we can get at once, we're always going to be looking for ways to generate things in pieces and know how they fit together. So we want the pieces to be really obvious on how to assemble them, and we always want to make sure that we have a clear structure or set of guidelines for each individual piece so that we can assemble them. So you can imagine, if this part of the outline depends on knowledge of what was covered in a different part of the outline, then we would need to make sure that that was introduced into the prompt. So we just said 3.2 but if we had an idea that maybe the conversation had gotten so long that what was in item one had been forgotten, we might want to go and just cut and paste the outline underneath one back into the prompt and then say, expand 3.2 because we know 3.2 was just previously generated, but that would help give it the the knowledge of what had come before, and make sure that what it put into 3.2 was consistent with what had been done earlier in the overall structure. Similarly, if it needed to make sure that 3.2 was cohesive with what's going to come later, we would want to put in those pieces. So one of the things we have to think about is, even if this outline style. When we do this, it will work, but we always have to think about, does it still have the context to make sure the individual pieces are cohesive, even if they fit into the outline? At this point, we want to make sure it doesn't do something that breaks something somewhere else. And this is a problem, a fundamental challenge that we're always working with in prompt engineering when we're building from pieces, how do we be able build the pieces so that they're standalone, self contained, but can be assembled into the overall whole? And so we see this again. We just expand 3.5 which was setting the tone and style, and we get this very rapid expansion and creation of a sophisticated outline now that we can use to write text for a bigger project, to be able to try to write software. There's all kinds of sort of analogies or analogs to the outline, the sort of the master structure, where we start with a a certain level of detail, then we pick some piece of it, and we expand the level of detail. And then we may pick a piece of that, and we may expand the detail. And then we may move back up to another bullet point in the outline and expand the level of detail. And so we can be moving up and down in the outline. We can be going up to the top level, or we can be going down to the really detailed things. And we can expand wherever we want, and sort of keep a map of the overall picture that we can use to build individual pieces and make sure that we can assemble them. But also, as we build pieces, that we can make sure that chatgpt has the relevant information, the sections of the outline, for example, that in the prompt that it needs in order to reason About or generate whatever it's going to produce next. I'm [35964:26:40] 0: when we're working with computer software, one of the things that's really useful is that programs typically have some menu with a series of actions that we can apply. So if you've ever used word processing software, there'll be like a file menu that allows you to run an action to open a new file or save a file, you may have a menu that allows you to search and replace different pieces of text. So this idea of having a menu and different actions that we can run is a really useful concept. And sometimes when we're working with prompts and prompt engineering, and particularly when we have a long conversation, it can be helpful to sort of develop the equivalent within a prompt, basically define a set of essentially a set of actions that we can run and order to work in the conversation without having to repeat these long prompts. Or we want to just sort of codify certain actions that are helpful to people and bake them into a prompt at the very beginning of the conversation. So let me give you an example of this. We're going to look at using the menu actions pattern. This is a pattern that allows us to get the same type of behavior, but in prompts. So we're going to develop a menu that is a series of actions that we can run. And actions are basically essentially a prompt. It's basically a set of instructions that we're going to give the large language model into order to do something at a particular point in the conversation. So here is how this works. We describe what we're going to type in order to trigger the action. So I say whenever I type, write bullet point paragraphs. And let me talk about this in more detail in a minute. So don't worry if this seems just doesn't quite make sense yet. So whenever I type this phrase right, and then I have in less than, greater than bullet point, and then paragraphs, these are placeholders. So basically I'm saying I'm going to type in right and then a placeholder for a bullet point, and then a placeholder for a number of paragraphs. You will write content for the selected bullet point, bullet point. So basically, what I'm saying is I'm going to give you a bullet point that you need to go and write the content for, and then I'm going to tell you how many paragraphs of text to write, and then you're going to go and write the text. So basically, I'm developing an action which is before all I could do is expand my outline. So when I talked about the outline expansion pattern, I talked about being able to rapidly expand the outline. And now what I'm going to say is, at some point, I'm going to be able to tell you, no, go and turn that into text rather than just outline. So I'm creating a new action. I'm also going to go ahead and keep my original action, which is just expanding the outline. So I say, whenever I type and I have a placeholder for bullet point, you will expand that bullet point. So what I'm saying is, if I just type in, like, 3.5, dot two, which is a bullet point, like a number in my outline, it'll know that it means expand that in the outline. If I instead say write which is kind of a keyword and then a bullet point and a number of paragraphs, it knows that that means it's supposed to write the text for it. So I'm defining a menu. I now have two actions. I can either expand my outline or I can write the text for part of my outline. And so now I'm developing more sophisticated capabilities for my outline expander. I'm turning it into a real program now, something that I can interact with. So let me show you an example. Now, here is my first action being run. I'm saying write three, dot 5.32, now what that means is write the content for the bullet point that was labeled 3.5, dot three. So label 3.5, dot three. You're going to write the text for it, or for that part of the section in the outline, and you're going to write two paragraphs. And so what we see is it takes the bullet point 3.5, dot three, from the outline, which was experimenting with tone and style variations, it then writes two paragraphs of text for that bullet point. So I've created an action, I've defined it, and I've created a menu of actions, and I've defined it in my in my prompt, and now I can run that action and get get the text generated. And so then we see it prompts us again, what do we want to do next? So this is actually not part of the of the text it wrote. So it did write two paragraphs. Then asked me what I wanted to do next. So then now I'm going to go back and do exactly what I did before. I'm going to say, expand on 3.5, dot two. So this is what I did before, and now it knows the difference, and it knows that's a different action. And so it goes and expands 3.5, dot two, and puts the outline for it again. I then go down and I say, Okay, give me text for 3.52 and notice something kind of interesting. I'm actually making a typo here, but it's kind of being smart and inferring what I'm supposed to do. This is kind of an interesting thing is it's a very sort of it tries to help you out, tries to get things right, and it knows, based on the pattern, that what I probably met was write 3.5, dot two. Instead I wrote text. So it's kind of a smart act menu action system. And then it actually goes and it pulls in that bullet point, 3.5, dot 2.3, sorry, I said that wrong. It's 3.5, dot 2.3, and then it writes one paragraph of text. And so I've created a basically a complex program where I can expand my outline if I want to, or I can have it write the text for a part of the outline, but I don't have to repeat myself. I get to use this simple little format, and I've explained what the format is, and now I can rerun the actions whenever I want to. So one way this is useful to me is like, if you're doing the same task over and over with prompts, it can be helpful to use the menu actions pattern to basically define a set of actions, kind of like on a menu of a prompt that you use all the time, and then whenever you want to iterate really quickly using that content and those set of actions, you can just introduce that menu actions prompt and then go and use those actions over and over on the output that you're getting in order to manipulate it or do something. You've basically built yourself your own program within the conversation at the same time, sometimes an organization may have you know a number of people that are doing the same job, and they can share actions with each other to help automate different tasks. And so this could be really useful to help people be more effective with their jobs and to share with each other useful props. The other thing is, is you don't have to worry so much about remembering exactly how you worded it right once you've written the action once and gotten it to work in the menu, then you can reuse it over and over without worrying about not quite getting it right when you do it. And then that leads into a final thing that's really useful about the menu actions pattern is that within an organization, you can share a set of common menu actions that everybody should use, and you can codify the best wording for those prompts and for those actions and what they should do, maybe codify best practices into them, and then share them across the organization. So it allows for knowledge sharing and reuse of different prompts and then easy application of those prompts. You could also imagine baking these into a root prompt for something like a customer service portal where you want to give people certain actions they can run to look up information about their account. They could do it in natural language, but you could also describe here are some actions you could run and allow them to get better behavior out of it. So the menu actions. The menu actions pattern is a really powerful pattern that allows us to easily reuse other prompts and actions that we've used to share them with others and develop knowledge bases of them so that we can become More effective prompt engineers. You [38486:24:00] 0: I we've heard over and over in the news that these large bank language models make all kinds of mistakes and can lie to you, and they'll, you know, never admit their, their their, their mistakes in the first place. They only keep telling you they're right produce weird outputs. And of course, this fundamentally kind of misses the point of the tool. These aren't meant to be tools for answering questions, necessarily. Now, sometimes they can answer questions and do it very accurately, and sometimes they think produce things that look like answers, but aren't accurately, actually accurate. And so as long as we understand they're really for generating text, and sometimes the text they generate can answer things for us correctly, and sometimes it's going to make mistakes. So long as we realize that we can use these tools effectively. Now, one thing we can do is we can use prompts to support us in our identification of what are the facts that the tool is putting into its output, and which of those facts really matter, and we can go and then follow up on them and check them. Now, one of the things that happens sometimes when we're working with output from these tools is that because the output looks so realistic, so human, so convincing, we assume that it's true. And when it's producing large volumes of text, it can be hard to spot all the different assumptions and backs that are baked into the text that we really need to follow up on. In fact, check anything you get out of one of these models you need to take ownership of and make sure that you've checked it thoroughly and really believe it, you know. So what do we do to support us in this effort of trying to make sure the output is correct and factual. Well, we can use the fact checklist pattern to help us figure out what facts are actually in the output and need to be followed up on. So I'm going to give you an example of this. So I've taken our outline expansion tool, and if you remember, we used a couple different patterns, including the menu actions pattern. We use the outline expansion pattern. We had several different capabilities. One of the things we could do is we could go and expand the outline. We also added the ability to be able to generate text for any bullet in the outline, so and we can generate for a number of items, and we had a whole menu system to be able to do this. Now, one of the things we'd like to be able to do is, when we do generate text for part of the outline, I'd like to know what I need to follow up on and fact check at that point in order to make sure that I don't present information that's that's inaccurate. So if we look at this, the way that we can do this is with the fact that check list pattern. We say, whenever you output text, generate a set of facts that are contained in the output. The set of facts should be inserted at the end of the output, and you could put them wherever you want. I'm just putting them at the end. The set of facts should be fundamental facts that can undermine the veracity of the output if any of them are correct. So I'm setting up a new set of instructions for the large language model that says, anytime you produce text, give me the corresponding set of facts that the text depends on, and that's where I can go and follow up on them and check them. And so it says it understands and so now I'm going to use our outline expansion program that we've written. I'm gonna tell it to write a paragraph for section 3.5, dot 2.2, so this section is considerations for choosing the appropriate style, and it generates a whole paragraph of text for me. And then what it does is it generates a set of fundamental facts down here that are the facts that are contained within the paragraph. And so the facts are, for example, writing style can range from technical to creative to instructional. There are other things like instructional content may adopt a clear and step by step style. Now, this paragraph that I chose for it to write, it has a lot of different facts that maybe they're correct, maybe they're not, but, you know, it's not something that I have to worry as much about going and extracting and just staring at text, because I now have a list of things to follow up on. At a minimum, I need to look at this list and follow up on these items were just actually visually check them myself, for my own knowledge, that's sort of the minimum level. Now I have a minimum bar at least these things I need to go and follow up on, and it sort of flagging to me. Here are some things that you need to go and check. The other thing I can do is I can compare this list to the paragraph up here. So any person that's probably using one of these tools can compare here's the list of facts below. Here's the actual text above. Is the list of facts complete? Are there statements in the text above that are missing below? And if there are those, are probably things that I would want to go and follow up on as well. And so by checking and comparing the two lists, one we can see is it really fully extracting all of the facts that are important and that, in itself, will clue us into and make us think through, what is this really saying, and what are the fundamental facts to it? So just the the sort of the action of going and comparing the facts to the text it's produced will help us get us into the mode of thinking through the correctness of what it's produced. The next thing I can do is I have a minimum bar at least, I need to go and check up at the very minimum, I need to go and check the list of facts that it produced and follow up and make sure that they are correct, and if any of them is incorrect, then probably there's an error in the text above. And then if I notice that there's something in the text above through this comparison that's also not present in the facts, I could add that to my list and go check it. So this is a tool that can help us, you know, get into the mode of fact checking the output, it may be correct, but we still don't know for sure, until we actually fully follow up on it. And this gives us some tools to help us. One, know that there are things to follow up on, at least follow up on these things, and then two, to help us, give us a tool that we can go and compare to what it produced to see is the minimum list of things that I followed up on good enough, or are there all other things that are in that text that maybe I should think through or follow up on? Now it doesn't guarantee that we're going to come up with the right answer. We might think that it's still accurate when it's not even if we follow up on those facts. There may be some hidden assumptions, but it's much better than if we just read a bunch of text with no sort of support or stimulus to think through the fact checking process. So this is the fact checklist pattern is something that helps us get us into the mode of checking the output, checking its veracity, and having a format that makes it easier for us to sort of extract and compare the information and the sets of Facts with what's really true Using other external sources you [40550:02:40] 0: when we're having a long conversation with a large language model, sometimes we'll run into the challenge that the large language model will forget the rules of the Game. It'll forget what we're trying to accomplish. What is the task that we're working on? Remind the large language model. What are we doing? And we like it to remind itself, if possible. And so the way that we can do that is by using what we call the tail generation pattern. And the idea behind this is, that we're going to we're going to generate a tail an end to the output that the large language model produces that will help remind it what we're doing. And so the tail is going to always be generated at the end of its output. And the tail will remind the large language model what the rules of the game are, and we're going to see this in the context of combining the tail pattern with the alternative approaches pattern and with the ask for input pattern. So we're going to put all these things together, and we're going to see how this is a really useful thing. So generating a tail on our conversation using the tail generation pattern is really, really effective in maintaining our conversation longer and maintaining the rules and the knowledge of our rules longer. So I've actually used this several times, and I haven't talked about it, but I'm going to show you what it does. So this is the prompt that I used in the alternative approaches pattern discussion. So I'm asking chatgpt to generate a set of prompts to solve a particular task. So I'm asking chatgpt to help us with prompt engineering. I'm going to give it a task, and it's going to generate possible prompts that we could use to perform that task with chatgpt. Now if I do this over and over. And I keep saying, anytime I ask you for a prompt, you should go back and generate multiple alternatives for it. The problem I'm going to run into is that eventually it's going to forget that it's supposed to generate a bunch of alternatives, and then it's supposed to be generating prompts. And so I need a way that keep reintroducing that rule into the conversation to keep it alive longer. And so one way I can help do that is with the tail generation. And so this is the tail that's being generated. I have the prompt, and I say, when you are done, ask me for the next prompt to create alternatives for. So I'm adding this on. I'm saying, when you're done, at the end of your output, you're going to ask me for the next prompt to create alternatives for it. So notice what I'm doing. I'm actually using the ask for input pattern. I'm saying at the end of the input, at the end of the output that you produce, you're going to ask me for the next input. So you're going to ask me for the next task to accomplish. And I'm telling it you're going to ask me for the next prompt to create alternatives for. So I'm also reintroducing the rules of the game. I'm describing what the purpose of the input is that I'm going to be giving it, and what it's supposed to do with it. And I'm making sure that this shows up at the end of my prompt, or, sorry, at the end of the output that the large language model is going to produce. So I've defined the rules, and I've said at the end of what you do, you're going to reintroduce this rule by basically asking me for the next input to create alternative prompts for it. So let's see what happens. So I add this tail on, and so I'm generating a tail. I'm using the tail generation pattern, and I say, write a prompt for chatgpt to automatically detect questions and a chain of emails and summarize everyone's opinions on the question as bullet points beneath each question. So I've given it the task. Here's what I want you to write me some possible prompts for. So I would give it the instruction. It's now going to write the prompts, and it generates a bunch of prompts for me, right? So now I've got all these alternative prompts. And then the last thing it does is it generates the tail, just like I said. So it says, please let me know if you have another task for when she would like me to write a prompt and create alternative approaches for so right here it's created a tail on its output. It's at the very end, and it says, please let me know if you have another task for when you'd like me to write a prompt and create alternative approaches for you. Notice that its sentence that it's created encompasses a lot of the rules. It encompasses enough of the information about what it's trying to accomplish that we don't have to worry as much, that it's going to forget the rules. And so then I go and I give it another task. I say, write a prompt to evaluate different prompts for summarizing the questions. And it goes through, and it generates all the prompts which we saw before. And then at the end, it generates the tail again. Please let me know if you have another task for which you'd like me to write a prompt and create alternative approaches. So we've got it to reintroduce the task again. And so now, if we went in and we put in a new prompt, it still will remember what the context is. And if we went in and we had back and forth without this, at some point, it's going to forget the rules of the game, and it's going to say, hey, what am I supposed to do? Or it's going to forget to generate alternatives, or it's going to do something else. But by continually reintroducing the rules of the game as this tail on the output. Then every time we go to send in a new input, just recently, we had the rules of the game that give it the context that it needs to accomplish the task. So the tail generation approach is really, really useful when we're going to have a longer conversation where we're going to try to program something, we're going to give it a bunch of rules up front, and then we're going to have a whole bunch of interactions, and we don't want it to forget the rules or the context. Now, it doesn't have to be rules. It could be anything that we think that needs to be reintroduced over and over into the conversation. And what we do is we just make sure that at the end of the output, we ask it to put in whatever that tail is. It could be asking for the next input. It could be, you know, asking for some other additional information. It could be re describing the rules. It could be kind of whatever you want it to be, but it's like a little nugget, a little tail that we're going to attach to that output to remind the large language model. Here's what we've been talking about, and give yourself a little hint about it at the very end before we go on to the next task. You [42364:26:40] 0: a large language models really excel at working with text and understanding patterns of language. And a lot of times, text is something that's really difficult to work with, because we tend to have to have a human go and look at it to do a really good job of analyzing well. Or we used to. We used to need a human to do that. Now we use large language models, but, you know, going through and trying to understand text and manipulate text is one of the real strengths of the large language model. The next pattern is called the semantic filter. So this is basically a filter that can take in text and remove information from it, or only keep information that has certain meaning or has a certain sort of qualities that we specify. And so this can be a really useful pattern for a variety of different cases. Now I'm going to show it in the case of taking text and filtering out and removing certain things that we would like to get rid of from those texts. This might be secret information of some kind. It might be, you know, removing things that aren't public. It could be all kinds of different things, or removing redundant information, whatever you need it for. This is kind of a useful pattern in taking and manipulating text, so let's look at an example of it. So I'm going to start off with a very simple example of the semantic filter. And I'm going to say, filter this information, to remove all dates and rewrite the text as little as possible, to fix issues caused by the date removals. And then I've pasted in some information about Vanderbilt University from Wikipedia. And in this information, there's a whole bunch of dates. And so I'm creating a complex filter that's going to basically take in information, it's going to remove all the dates, and it's also going to transform the information a little bit to rewrite it, just in case, I'm removing a date and it sort of makes a sentence awkward where there's obviously something missing. And so I'm going to take in information, I'm going to remove all the dates, and I'm going to slightly rewrite in order to do this. So I've got the Vanderbilt now Wikipedia information. And by using this pattern, which is to clearly say that you're going to, you know, serve as a filter. So we're going to say filter this information. So we're clearly indicating by saying filter we want to preserve but remove. We're not trying to create new we're trying to take an information and filter out or remove. So the pattern is basically the semantic filter. Pattern is we're going to tell it to filter something, and we're going to give it sort of rules, semantic rules, rules about the meaning and what we're trying to remove, the meaning or the purpose of what we're trying to remove. So then what it does is it goes through and it rewrites all the text, and you notice that it does a pretty good job. It removes all of the explicit dates. Now, one thing I noticed is that I might need to go and rethink my prompt and how to express dates, because it says founded in the 19th century, and that might be too specific for me, depending on what my meaning of date is. So I think it took a literal interpretation of it, like if it's, you know, a specific date. So if you go back and look it originally said founded in 1873 so it removed the date 1873 and replaced it by rewriting it was founded in the 19th century. So it's actually kind of removing information, but I asked it to rewrite. So it's transforming a little bit, but this shows you kind of the power it's understanding the text. It's understanding what a date is. It's removing it. In this case, we're also transforming it to rewrite it in some way. Now let's show you a more interesting example and kind of where semantics and understanding of the meaning of things really gets used so I'm going to say filter the information below to remove any information that helps some figure help someone figure out that the patient has diabetes. First, explain what information you're going to remove and how it might help someone figure out that the patient has diabetes, then provide the filtered information. So what I've got below is a fictitious medical record that describes a patient Jane Doe has a number of symptoms. The patient presents to the clinic with complaints of increased thirst and fatigue for the past two weeks, history of present illness right here, past medical history down here, medications down here, allergies, a variety of things. And then I'm going to actually have chatgpt go into a semantic filter on this information. So now let's take a look at what it's going to remove. So it says, well, the chief complaint of increased thirst and fatigue should be removed because increased thirst polydipsia is a common symptom of diabetes. The history of present illness mentions increased thirst and not checked your blood glucose levels, both of which should be removed because they are related to diabetes symptoms and management. The past medical history includes type two diabetes, and the light is, and I apologize if I'm mispronouncing this, which should be removed because it directly indicates that the patient has diabetes. The medication Metformin, 1000 milligrams twice daily, should be removed because Metformin is a medication commonly used to manage diabetes. So this is taking the semantics of I want things that could give away that this patient has diabetes. I want them filtered out and removed. So I'm giving some semantic rules about what type of information to get rid of. It has to understand, to some degree, the meaning in the text, or at least know, based on its training data, that these are things that are commonly discussed around diabetes. So one way or the other, it's figuring that out, and then it goes through and rewrites the medical record, and notice it rewrites the chief complaint me to the patient, presents the clinic with complaints of fatigue for the last two weeks, the patient reports that she has been feeling more fatigued. She dies, any recent weight loss, blurry vision or infections. Past. Medical History is rewritten. The medication has rewritten. And so now we have a filtering of what was here before. And so we noticed that, like the history, it removed this, the patient reports that she has been increasing or she has been experiencing increased thirst for the past two weeks. So we can use these large language models to develop sort of powerful semantic filters using the semantic filter pattern. Now, is it perfect? No, as we've seen, there can be, you know, issues with it, and as we've talked about before, you know, they're not always perfectly repeatable, but as a starting point to help, maybe support a human process that then looks over it a second time, or to try to help prevent accidental release, it's just one more check in the system. This is a fairly low cost check to try to remove extra things. Should it be the only check? No. If we're going to filter things out, particularly for privacy or other reasons that are where we have information that we don't want to get out, we should always have other checks in place, because this is not going to be a perfect filter. It's going to have some randomness. It's going to not always do exactly what we expect, but as a part of another process, as a component to help. It's a very, very powerful technique that we could potentially employ in parallel, in conjunction with other checks, other types of removals. I [44585:14:40] 0: thank you everyone for taking this course on prompt engineering, I hope that you'll feel inspired by all of the different examples to go out and really try to build interesting application using large language models. The thing I always want to emphasize in these discussions about large language models is the real power of these language models comes out through human creativity. If you have creative ideas, creative ways of using the tools, that's where you get really exciting outputs. A lot of the discussion we've seen is about bad outputs, and I just look at that as a failure in the use of the tool. You want to go and really try to be creative in how you use it come up with really great ideas, find the problems that are really hard to solve using other approaches. And so I hope you'll be expired, inspired like I am, to really try to think about this tool again. I think of it as a tool for helping to quickly give my thoughts form, to do things faster and in unique ways that I couldn't do before. You know, as an artist in my earlier part of my career, I've always been excited about working in different mediums. You know, I could work in paint, or I could work in ceramics, or I could work with metal. And all of these different mediums have different unique characteristics to them. And I look at chat GPT as another exciting media medium for creativity, for coming up with new ideas and trying to give them shape, to give them form, just like I would in paint, just like I would in sculpture. So I hope you'll be excited to explore this new medium. And as one last final thing, I think it's always important to go back to chatgpt and get its thoughts on what we should tell you as you leave the course. And so I think it's got some good points here. So I asked chatgpt to act as the teacher of a course on prompt engineering, to thank students for being in the course and tell them about what they should do for next steps. And it's got some great points here. One, practice, practice, practice. I can't emphasize this enough, really, a lot of the great things are going to come through you practicing and experimenting with chatgpt or another large language model, and asking the question, can I get it to do this? Wouldn't it be great if I could get it to do this? And a lot of times the answer is yes, with some creative prompt engineering. So please, practice, practice, practice. Stay up to late to date with the latest research and developments on prompt engineering. It's a very quickly moving space. If you go to archive where we've listed some of the papers on prompt engineering, there you can find all of the latest updates, and I hope that you'll follow with what's going on and keep seeing all of the exciting discoveries that people are making. It's such a it's such a new space. Everybody can be at the forefront, riding the wave right now. And so I encourage you to do that, collaborate with others. This is one of the things that I really enjoy about working with large language models, is there's so many people that are just as excited as I am. And when we get together, we come up with crazy ideas. Well, what if we did this, what would it look like if we had them talking to each other? What if the large language models were talking to each other? What would we do differently or or how would they, you know, word things differently? There's all kinds of fascinating ideas, and those ideas really come out through collaboration and also from just looking at what different people are doing, how they're sort of approaching prompt engineering. So I encourage you to collaborate with others. And then finally, to keep ethics in mind. You know these there's a lot of the discussion around ethics with these models, and I think it's really important, particularly as the early sort of adopters of this technology, that we use it in an ethical and appropriate way, that we show all of the good things that can be done with it, rather than showing bad things. If we keep adding to the negativity around these models, what we're going to do is we're really going to dissuade people, and we're going to have people miss all of the wonderful opportunities to do interesting and creative things. So please, please, obviously, keep ethics in mind. So I think this is a great wrap up from chat GPT, again. Thank you so much for participating in this course. I hope you'll be engaged in the discussion forums. I hope you'll keep sharing prompts and interesting ideas that you have with the community and around this course. And again, I can't wait to see what everyone in this course does with prompt Engineering and all the amazing Things that You Create You [45748:37:20] Speaker None: You