
Welcome to the course on prompt engineering! This course is designed for everyone who wants to learn about prompt engineering and how to use it to get the most out of LLMs or ChatGPT specificly. This includes: Researchers and developers who want to use LLMs for their research or development projects. Content creators who want to use LLMs to generate creative content, or story, etc. Business professionals who want to use LLMs to improve their productivity and efficiency. Students who want to learn about the latest developments in AI and natural language processing. No prior experience with LLMs is required to take this course. However, basic computer usage skills are recommended. In this course, we will learn about the art and science of creating effective prompts for large language models (LLMs). LLMs are a powerful new technology that can generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way. However, to get the most out of LLMs, you need to know how to provide them with clear and concise instructions. This is where prompt engineering comes in. Prompt engineering is the process of designing prompts that align your goals and expectations to an LLM. It is a bit like programming, but instead of writing code, you are writing instructions in natural language. In this course, we will cover the following topics: The basics of LLM and prompt engineering Principles of Prompting How to create effective prompts for different tasks and best practice as well as some common mistakes to avoid Advanced techniques for prompt engineering By the end of this course, you will be able to write prompts that help you get the most out of LLMs. You will also be able to apply what you have learned to your own work and projects. See you next.
Prompt engineering is the process of designing prompts that align your goals and expectations to an LLM. A prompt is a piece of text that you give to an LLM to guide it in generating text like this one. <How can I develop a marketing strategy that aligns with my business goal?>< can you guide me through the process of setting enough budget for my business?> Prompt engineering is important because it allows you to get the most out of LLMs. By carefully crafting your prompts, you can help LLMs to generate more creative, informative, and accurate text. Here are some of the benefits of using prompt engineering: It can help you to get more specific and relevant results from LLMs. It can help you avoid some common mistakes, such as providing too much or too little information to the LLM. It can help you to improve the quality of the text and format that LLMs generate. As the field of artificial intelligence continues to grow, Prompt engineers are in high demand across a variety of industries ranging from technology and finance to healthcare and entertainment and much more. There are a lot of techniques out there on the internet or somehow but instead of learning word by word use exactly example sentences they provide to you. You should understand how LLMS works and the principle of prompting in order to have a sense so you can use these techniques in a way that is effective and gets what you expect. If you're looking for a challenging and rewarding career, prompt engineering is absolutely a great option. With the skills you learn in this course, you'll be prepared to leverage AI capability to enhance your productivity, shaping yourself for the future.
After this section we'll all understand What are large language models exactly? What do they do? How do they work? And some outstanding characteristic of large language model. And after that, we will go through some type of LLM we're all using at the moment. Let's start by asking chatGPT if it knows itself or not. ChatGPT is one of the various types and versions of large language models. now let's get the answer. <read respond> I won't go into the full details of this, but I want to provide you with just enough information about how they work to assist you in thinking about designing prompts. There are a couple of key points you should be aware of, which will be incredibly useful when you're creating prompts. For Now, the fundamental thing you should know about these large language models is what they're doing. Essentially, they take your input and attempt to generate the next word. Then, they take the word they've generated, add it to what you originally provided, and continue trying to generate the next word, and so on. This is one way to think about it. There is a lot more detail involved, but essentially, it's about generating words one by one to create a full response to your input. Regardless of your initial prompt, the models work by generating words sequentially. The next word in the output is generated until the model believes it has produced a complete response. The last word effectively serves as a stopping point, even though you won't see a specific indication of it in the response. What we're trying to do with large language models is to create prompts that, in turn, lead the language model to generate an output word by word. Now, I'd like to provide you with a brief explanation and some intuition about this process. If I go and I write, Mary had a little and we stop right there. If you're familiar with the nursery rhyme, Mary had a little lamb, it's fleece was white as snow. I'm giving it a prompt. If I say Mary had a little, it's going and then completing it, it starts from my last statement, Mary had a little and it's giving the, predicting the next word, which is lamb. It's fleece was white as snow. Everywhere that Mary went the lamb was sure to go, it followed her to school one day, which was against the rule that made the children laugh in play to see a lamb at school. And so the teacher turned it out, but still it lingered near and it goes on and on until it stops. Now you notice what it's doing is it's my prompt triggered it to produce the next word which was Mary had a little was my prompt. The next word was lamb. If I go and I say roses are red. What does Chat GPT do? It says violets are blue, sugar is sweet and so were you. It says this is a classic point is often used to express affection or admiration for someone. But the key thing to note is it's doing a next word prediction. I said roses are red and it's picking up where I stopped and predicting the next word which is violet's. It's an adding that in and saying roses are red violets and it's predicting are. Then going back, adding that in, it says roses are red, violets are, and it's predicting blue. If I go and I write "the sky is" and hit enter.. Now you notice what it's doing is it's my prompt triggered it to produce the next word which was ... It's doing this over and over until the last word, that signal model to stop generate more word, While we can't see this signal, the model always detects it. It does really incredibly sophisticated calculations behind the scenes. To have the ability to do that, the model was build and trained previously, basically what was done was a significant portion of text and other content from the internet was gathered, was taken. the model was given a series of words and it tried to predict the next word. IT was shown a part of the sentence and then asked to predict the next word in the sentence and then try to correct any mistakes as needed. The model was trained repeatedly until it achieved a sufficiently high level of accuracy. Now we know what is llm, and how does it work basically, in the next lesson we'll talk about some outstanding characteristic of it.
Large language models are unlikely, at least in the near term to give you an exact and repeatable answer every single time. There's always going to be the possibility they do something a little bit unexpected and this is by design and can be a really good thing. Now, a lot of what we're going to be doing in prompt engineering is trying to deal with the fact that large language models have some unpredictability to them. And we want to sort of constrain that unpredictability, we want to mold it and shape it and work with it in a way that's helpful to us. Now, what I mean by this is that there's always some randomness, some ability to generate new and different ideas each time you input a prompt. This can be really beneficial at times. For instance, when writing fiction and desiring a wide range of ideas, storylines, and characters. Each time we request new data or seek a new output, we receive something entirely new and unique, which is highly advantageous. On the other hand, if we're trying to have the large language model do some type of reasoning on a system, we may not want it to have a lot of variations in its responses. For example, when seeking a simple yes or no answer, we don't want it to sometimes respond with yes, sometimes with no, and then suddenly decide to provide a lengthy explanation about why it's challenging to determine. Sometimes, we simply want a straightforward yes or no without any explanation, and that isn't always easily achievable. So, many of the engineering techniques are going to be dealing with this. Now, I'll quickly show you an example of randomness. It's the idea that using the same input won't always give us the exact same output each time. Please keep this in mind as we go through this course because I'll teach you many different techniques to make the large language model do specific things. Some of these techniques will work really well, and sometimes won't. But what they usually do is give you something that's more dependable and works most of the time. The key point here is that we'll always have some level of randomness and unpredictability, and we need to accept and manage that. So, I asked ChatGPT I said, how many birds are outside my house ? how many bookstores are there in London? And it says: ..............<run again, again..>. So, we're getting a similar output each time, but they/re not not exactly the same. And so, this is a fairly constrained set of outputs for this question. We keep getting similar kinds of answers, but they're not exactly identical, which can be a challenge for us. So know that when you're developing prompts, a lot of what you're dealing with is the fact that there is variation. Now, if I wanted an exact number and I used a prompt like this, this is obviously not going to work. It won't provide me with the precise number of bookstores in London. In cases like this, we might need to go back and provide additional information to help it give a better answer. Let's try another example: 'Suggest 5 names for a new bookstore, they should contain the word 'Clever.' Now, regenerate the response. Now we can see different names every time we click the regenerate button, and this is clearly a huge advantage of randomness. Now, we know one of the most significant characteristics of a large language model. Let's keep this in mind and use it to generate diverse and relevant content when working with this type of model
So in the development of large language models or LLMs, there have been broadly two types of LLMs, which I'm going to refer to as base LLMs and instruction-tuned LLMs. So, base LLM has been trained to predict the next word based on text training data, often trained on a large amount of data from the internet and other sources to figure out what's the next most likely word to follow. So, for example, if you were to prompt us "Once upon a time, in a land far away" it may complete this, that is it may predict the next several word, these are "there was a hidden village nestled deep within the heart of a dense, enchanted forest". But if you were to prompt us with what is the capital of China, then based on what articles on the internet might have, it's quite possible that the base LLM will complete this with what is China's population, what is the largest city of China and so on, because articles on the internet could quite plausibly be lists of quiz questions about some aspects af China. In contrast, an instruction-tuned LLM, which is where a lot of momentum of LLM research and practice has been going, an instruction-tuned LLM has been trained to follow instructions. So, if you were to ask it what is the capital of China, it's much more likely to output something like, the capital of China is Beijing. So the way that instruction-tuned LLMs are typically trained is you start off with a base LLM that's been trained on a huge amount of text data and further train it, further fine-tune it with inputs and outputs that are instructions and good attempts to follow those instructions, and then often further refine using a technique called RLHF, reinforcement learning from human feedback, to make the system better able to be helpful and follow instructions. Because instruction-tuned LLMs have been trained to be helpful, honest, and harmless, so for example, they are less likely to output problematic text such as toxic outputs compared to base LLM, a lot of the practical usage scenarios have been shifting toward instruction-tuned LLMs. Some of the best practices you find on the internet may be more suited for a base LLM, but for most practical applications today, we would recommend most people instead focus on instruction-tuned LLMs which are easier to use and also, because of the work of OpenAI and other LLM companies becoming safer and more aligned. So, this course will focus on best practices for instruction-tuned LLMs, which is what we recommend you use for most of your applications. So, when you use an instruction-tuned LLM, think of giving instructions to another person, say someone that's smart but doesn't know the specifics of your task. So, when an LLM doesn't work, sometimes it's because the instructions weren't clear enough. For example, if you were to say, please write me something about Paris. Well, in addition to that, it can be helpful to be clear about whether you want the text to focus on location for sight seeing or traditional food or economic or something else. And if you specify what you want the tone of the text to be, should it take on the tone like a professional journalist or local people to write. Or is it more of a casual note for yourself or more of adversising paper? That helps the LLM generate what you want. And of course, if you picture yourself asking, say, a team member carry out this task for you, if you can specify what snippets of text, the more detail of it the more time they should read in advance to write this text about Paris for you. So, in the next video, you see examples of how to be clear and specific, which is an important principle of prompting LLMs. And you also learn second principle of prompting that is giving the LLM time to think. So with that, let's go on to the next video.
In this section, we will cover some of the most important principles for designing prompts.By understanding these principle you can create prompts for almost any situation from the basic to the most sophisticated. As we cover more and more examples and applications with prompt engineering, you will notice that certain elements make up a prompt. A prompt contains any of the following elements: 1. Context - external information or additional context that can guide the model to provide better responses. 2. Instruction - a specific task or instruction you want the model to perform. 3. Input Data - the input or question that we are interested to find a response for. 4. Output Indicator - the type or format of the desired output. You do not need all the four elements for a prompt and the format depends on the task at hand. We will touch on more concrete examples now, let dive in!!!!!
The next tactic is to ask for a structured output. So, to make reading and parsing the model outputs easier, it can be helpful to ask for a structured output like List, HTML, or JSON. So, let me copy another example over. So in the prompt, we're saying generate a list of three made-up movie titles along with their authors and genres. Provide them in JSON format with the following keys, movie ID, title, author, and genre. As you can see, we have three movie titles formatted in this nice JSON-structured output. We will discover more techniques for formatting responses in later lessons.
The next tactic is to ask the model to check whether conditions are satisfied. So, if the task relies on assumptions that might not hold true, then we can tell the model to verify these assumptions first. Then if conditions are not satisfied, indicate this and kind of stop an attempt. It's also a good idea to think about potential edge cases and how the model should handle them to prevent unexpected errors or outcomes. So now, I will copy over a paragraph. And this is just a paragraph describing the steps to make a cake. And so the prompt is, <exp 1> You can see that the model was able to extract the instructions from the text. So now, I'm going to try this same prompt with a different text. So, this paragraph is just describing a Paris's night, it doesn't have any instructions in it. So, if we take the same prompt we used earlier and instead run it on this text, the model will try and extract the instructions. If it doesn't find any, we're going to ask it to just say, no Instructions provided. So let's run this. And the model determined that there were no instructions in the second paragraph. this approach demonstrates the model's ability to check for conditions, making sure it only attempts task when the conditions are met, and providing a reliable mechanism to deal with cases where conditions aren't satisfied.
So, I'm going to outline some principles and tactics that will be helpful while working with language models like ChatGPT. I'll first go over these at a high level and then we'll kind of apply the specific tactics with examples and we'll use these same tactics throughout the entire course. So, for the principles, the first principle is to write clear and specific instructions and the second principle is to give the model time to think. Now let's dive into our first principle, which is to write clear and specific instructions. You should express what you want a model to do by providing instructions that are as clear and specific as you can possibly. This will guide the model towards the desired output and reduce the chance that you get irrelevant or incorrect responses. Don't confuse writing a clear prompt with writing a short prompt, because in many cases, longer prompts actually provide more clarity and context for the model, which can actually lead to more detailed and relevant outputs. The first tactic to help you write clear and specific instructions is to use delimiters to clearly indicate distinct parts of the input. And let me show you an example how and when delimiters are essential.
LLMs today, such as GPT-3, GPT-4, are tuned to follow instructions and are trained on large amounts of data; so they are capable of performing some tasks "zero-shot." which means just directly asking model to perform some tasks without any previous instructions or examples. Let try a few zero-shot examples: <exp 1> We see the response is quite long and hard to follow and understand. When zero-shot doesn't work, it's recommended to provide demonstrations or examples in the prompt, this is what we call few-shot prompting. Few-shot prompting can be used as a technique to enable in-context learning where we provide demonstrations in the prompt to guide the model to better performance. So let me show you an example. <exp 2> So in this prompt, we're want the model to answer in a consistent style. now we've said, teach me about resilience. And since the model kind of has this few-shot example, it will respond in a similar tone to this next instruction. We can observe that the model has somehow learned how to perform the task by providing it with just one example (i.e., 1-shot). For more difficult tasks, we can experiment with increasing the demonstrations or exp (e.g., 3-shot, 5-shot, 10-shot, etc.). So, those are our four tactics for our first and most important principle, which is to give the model clear and specific instructions. These tactics are designed to ensure that the model can interpret and understand your guidance accurately and provide you with the best possible results, keep it in mind when designing your prompts.
Our second principle is to give the model time to think. If a model is making reasoning errors by rushing to an incorrect conclusion, you should try reframing the query to request a chain or series of relevant reasoning before the model provides its final answer. Another way to think about this is that if you give a model a task that's too complex for it to do in a short amount of time or in a small number of words, it may make up a guess which is likely to be incorrect. And you know, this would happen for a person too. If you ask someone to complete a complex math question without time to work out the answer, they would also likely make a mistake. So, in these situations, you can instruct the model to think longer about a problem, which means it's spending more computational effort on the task. So now, we'll go over some tactics for the second principle.
We'll do some examples as well. Our first tactic is to specify the steps required to complete a task. <exp 1> So, in this prompt, the instructions are performing the following actions. First, summarize the following text delimited by triple backticks with one sentence. Second, translate the summary into French. Third, list all names existed in the French translation. And fourth, output a JSON object that contains the following keys, French summary and num names. And then we want it to separate the answers with line breaks. Now we format the prompt a little bit here. <exp 2> ... And also notice here in this case, we used angled brackets as the delimiter instead of triple backticks. You know, you can kind of choose any delimiters that make sense to you, and that makes sense to the model as well.
Our next tactic is Think step by step to instruct the model to work out its own solution before rushing to a conclusion. And again, sometimes we get better results when we kind of explicitly instruct the models to reason out its own solution before coming to a conclusion. And this is kind of the same idea that we were discussing about giving the model time to actually work things out before just kind of saying if an answer is correct or not, in the same way, that a person would. I have tried this example. <click> It gave me an incorrect answer. And so, we can fix this by instructing the model to work out its own solution step by step by adding this instruction "Let's think step by step". <click> So we get the response, it's the correct result we're looking for. This is an example of how asking the model to do a calculation itself and breaking down the task into steps. Giving the model more time to think can help you get more accurate responses. I think it's really important to keep these in mind while you're kind of developing applications with large language models. So, even though the language model has been exposed to a vast amount of knowledge during its training process, it has not perfectly memorized the information it's seen, and therefore, it may not have a precise understanding of its knowledge boundaries. As a result, it might attempt to answer questions about obscure topics and generate responses that sound plausible but are actually incorrect. We refer to these made-up ideas as 'hallucinations.' To address this issue, we can guide the model to think step by step rather than providing immediate conclusions." And that's it! You are done with the principles for prompting and you're going to move on to lots of awesome techniques in the next video.
The first tip is to use direct and follow-up questions. "Give me some tips for boosting website traffic". and Chat GPT provide us a lot of different tips to improve website traffic, more than 10 tips to improve our traffic. We're not sure about SEO and these information is not enough for us to understand. Let's ask chat GPT to explain more deeply about SEO, usinf follow-up questions. <exp>. it is one of the most useful techniques to use chat GPT.
You can design effective prompts for various simple tasks by using commands to instruct the model what you want to achieve, such as "Write", "Classify", "Summarize", "Translate", "Order", etc Keep in mind that you also need to experiment a lot to see what works best. Try different instructions with different keywords, contexts, and data and see what works best for your particular usecases and task. Usually, the more specific and relevant the context is to the task you are trying to perform, the better. <Exp 1> Be very specific about the instruction and task you want the model to perform. The more descriptive and detailed the prompt is, the better the results. This is particularly important when you have a desired outcome or style of generation you are seeking. A good prompt will contain 4 elements of standard prompts from Principle 1 (Instruction, context, desired format, input), however, denpend on your task, sometime your prompt do not have 1 or 2 element from 4 standard elements such as input text or context, it's fine. Let try this example: <exp 2> <exp 3>
When you ask a question or give an assignment to ChatGPT, you can specify how it formats the reply. Let try this exp <exp 1>. As you can see ChatGPT chooses a random format it's familiar with, but we can odcourse specify a neat version of the respond we're looking for. This format is very diverse, ranging from bullet list, table, html, table, the table in html or even html with CSS that we can apply directly to create websites or blog posts. Don't be afraid to use long prompts or sets of prompts to give enough information for the large language model to fully understand what you're asking. Here's our full, rather long prompt for formatting results. And this is my really expectation.
it's easy to fall into the trap of wanting to be too clever about prompts and potentially creating imprecise descriptions. It's often better to be specific and direct. The analogy here is very similar to effective communication -- the more direct, the more effective the message gets across. For example, you might be interested in learning the concept of AI. You might try something like <exp 1>. We get an unexpected result, it's too short due to impreciseness in our prompt, It's not clear from the prompt above how many sentences or words to use and what style should be. You might still somewhat get good responses with the above prompts but the better prompt would be one that is very specific, concise, and to the point... Let try another version of it <exp 2>. As you can see, the results is now much better, let count number of words, let try for sentences and character number...
Another common tip when designing prompts is to avoid saying what not to do but say what to do instead. This encourages more specificity and focuses on the details that lead to good responses from the model
Few-shot prompting can be used as a technique to enable in-context learning where we provide demonstrations in the prompt to steer the model to better performance. It can be understand like give model examples for it to understand context and provide respond and suggestion follow this context. Let see an exp <exp 1>
The persona pattern is one of the most powerful patterns that we can use to tap into interesting behavior in a large language model. Now, what the persona pattern is, is you can imagine that you want to get a particular output, but you don't know exactly what the format out of that output should be or what information should be contained in it. But if you were in the real world, you know who you would go to, to get that output, or what you would go to in order to get that output. So for example, if you had an accounting question, you would call up your accountant and ask your accountant for their advice. Or if you had a question related to speech language pathology, like in the earlier example that I presented, you would go to a speech language pathologist, you would have them do the assessment. If you had medical advice, you might go to your doctor. And so the persona or the person, or the thing that you would go to, you know, who or what that is in the real world. And we want to try to use that kind of same behavior of, I know who to go to or I know what to go to, to get that output. But I don't know what their output would look like, I don't know exactly what they know or how they talk about things, but that's the type of output I want. And so the persona pattern is meant to give us that same type of behavior, to allow us to go to that expert and ask that question, without having to know what exactly the experts is going to say, how they're going to format it, or what they might know or not know. So let me show you an example of the persona pattern. Typically with the persona patterns, what you're going to say is act as persona, provide outputs that that persona would provide
ChatGPT is pretty cool because it can write in all sorts of ways. Whether you want something professional, friendly, funny, understanding, or just simple, ChatGPT's got you covered. It's like a toolbox of different writing styles to match what you need. So, when you're chatting with it, you can choose the style that fits the mood you're going for. Need something professional-sounding? It's got a style for that. Want to add a touch of humor? Yep, it can do that too. Whether you're keeping it simple or getting all creative, ChatGPT has a bunch of options to make your writing sound just right for whatever you're doing. It's like having a bunch of different pens to choose from, but for your words! Let’s look at these options in more detail: <exp 1>...<exp 2>
Congratulations on completing this online course! I'm so impressed with your dedication and hard work. You've shown that you're a true learner, and I'm confident that you'll continue to achieve great things. This course has given you a strong foundation of knowledge, and I'm excited to see how you use it to make differences Once again - Congratulations - Keep up the great work! See you later.
It goes without saying that Chat GPT is an increasingly popular and indispensable chatbot among people from different parts of the world. It is greatly powerful in dealing with tough questions and suggesting the best solution for users based on what they type in the chat box.
In some cases, ChatGPT might not give the expected answer if users don't give it clear instructions with the right prompts. Thus, this course was created to address these issues by equipping you with all of the primary to advanced prompts to effectively leverage Chat GPT for your work.
The course will cover the following key aspects:
- Introduce prompt engineering: the definition of it, the necessity of prompt engineering in using Chat GPT
- Set up Chat GPT: ChatGPT UI tour, openAI's pricing plan, create Chat GPT account
- Large language model (LLM) Fundamental: the definition of it, Randomness of Output, two types of LLMs
- ChatGPT Prompting principle: elements of prompt, use delimiters, structured output, check condition satisfied, "few-shot" prompting, Specify the steps required to complete a task, Instruct the model to work out its own solution before rushing to a conclusion
- ChatGPT Prompting best practices: Direct and follow-up questions, Specificity - Clear and detailed instructions, Format response, Avoid Impreciseness, Explain it like I'm five, Zero-shot, then few-shot, Act as someone, Using tones.
These main applications will definitely be useful to you for almost all cases in your work or even daily life. Any ineffectiveness you might encounter in life will be addressed in this course by an expert in IT _ Nguyen Nhat Truong
Don't miss out on the opportunity to supercharge your skills! Join my course now and start achieving your goals !!!