Prompt Engineering 101 - Crash Course & Tips

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone I'm Patrick from assembly Ai and in this video you will learn all the basics of prompt engineering so you can get the best results when working with large language models this is not a list of the best jet GPT prompts instead I compiled the best resources I found into one straightforward guide that teaches you basic concepts and the fundamentals of prompt engineering so at the end of the video you should have a good understanding of what you can do with prompts and keeping those Concepts in mind will improve your results a lot we will go over the elements of a prompt use cases some general tips also some specific prompting techniques you can apply I will also show you a few cool hacks and finally some iterating tips and I will give you the list with all the resources I used if you want to learn more about this so without further Ado let's get started first let's look at the elements of a prompt so a prompt can have those five elements and input or context then instructions so this can be one or more or also questions then some examples and a desired output format and actually none of those elements have to be present you can also just start a sentence and use the order completion of a model but in order to have a good prompt at least one instruction or one question should be present and then you can mix and match those elements so we will go over some examples later and now let's look at those elements in detail so an instruction is a clear instruction what to do for example translate from English to German and then the sentence then a question could be whatever you want to know for example what is the meaning of life this can also refer to the input you give the model so here we can give additional input and context for example here is a transcript of a podcast about generative AI then we put in the actual transfer script and then we ask our question then an example so if we include an example this is also called view shot learning so if you use only one example it's also called One-Shot learning and for more examples we call it few short learning for example we give an example how the output should look like or how the conversation looks like for example here we say the question the capital of France is and then the answer colon Paris and then we ask the question that we want to know now so here we use the same format and leave the answer blank and then ideally the model should answer in the same way and find the correct answer and lastly we can also use a desired output format or the output options we want to see for example we can say the output should be yes or no or we want a desired format for example we can say provide a short answer and then explain your reason so yeah these are the elements of a prompt now let's look at the use cases now let's go over some use cases to give you an idea of what you can do with prompts and large language models so this list is not exhaustive but these are the most common use cases I would say for example we can do summarization classification translation text generation or completion question answering coaching and with some models even image generation so summarization for example we can say summarize the following text and then put in the text text classification we can say classify the following text into one of the classes Sports Finance education and then again put in the text translation translate from English to German and then put in the sentence then text generation or text completion so this is what I mentioned in the beginning so none of those prompt elements have to be present you can also simply just start a sentence and use the order completion but then you never really know what you get so I would say at least an instruction or question should be present here and then question answering so you can ask general questions what is the meaning of life or you can make this based on additional input so here again this example with the podcast transcript where we ask questions about this then coaching for example you can ask how would you improve the following script for a YouTube video about generative Ai and then put in the script or you can ask for suggestions about an ice cream shop for names about an ice cream shop and an image generation so with some models we can tell the model what we want to get so generate an image of a cute puppy so yeah these are just some ideas for you so you know what you can do with prompts so let's go over some tips so here I have a list with easy to follow guidelines that should improve your prompts a lot so let's go over this list first of all try to be as clear as possible so use a direct instruction or a clear question and then here try to be as concise as clear as possible then provide any relevant information or data as context so if you have additional helpful information then use this in your prompts then give examples and prompts so try out this few short learning so you don't have to do this but you can always try including an example to see if this improves your results and also specify the desired output format so this will increase the chances that you get what you want to see then encourage the model to be factual through other means so this will help to avoid hallucination for example you can ask your question and then say answer only using reliable sources inside those sources so this is a really cool tip you can use then you should try to align the prompt instructions with the tasks and go all so for example if your goal is to have a conversation with a helpful customer support service agent you should include this in your instruction for example you can set the scene by saying this is a conversation between a customer and a polite helpful customer support service agent and then here you start the conversation and then you can continue so this is often a very good practice to align your instruction with what you want to get and finally you can try using different personas to get more specific voices so this is a bit similar to what we see here you can also directly say you are a kind customer support service agent and then continue and I will link a repository here that gives you a lot of cool inspiration with different personas you can use in your prompt now let's go over some specific prompting techniques you can apply to control the output for example you can do length controls so you can specify the desired output length for example you can say write a 150 word summary on whatever topic then you can do tone control so you can say write a polite response you can do style control so you can say give me the summary as bullet points or as a long paragraph whatever then you can do audience control so you can say explain this topic to a five-year-old kid then you can do context control so this means how much context you want to share in your prompt then you can do scenario based guiding so you've seen this before by setting the scene by saying you are a helpful customer support expert for example next this is a very important technique to keep in mind which is called Chain of Thought prompting and this is especially helpful if you have a more complex question or instruction so this provides a Chain of Thought process that showcases how the correct answer to a question should be reached and you can provide the Chain of Thought either directly with examples so this is called view short learning again or simply by adding this phrase let's think step by step so let me show you two examples so here we have a complex task so we say I went to the market and bought 10 apples I gave two apples to the neighbor and two to the repairman I then went and bought five more apples and ate one how many apples did I remain with and now in your answer you provide an example of this Chain of Thought so here you say first you started with 10 apples you gave two apples to the neighbor and two to the repairman so you had six apples left then you bought five more apples so now you had 11 and finally you ate one apple so you would remain with 10 apples so this is the example you provide with the chain of thought and then you apply the next question with the actual example you want to solve now so here I simply use different numbers but this could be also a slightly different question and then hopefully it will find the correct answer by following the same Chain of Thought So This is the first way you can do this by giving this as an explicit example with the Chain of Thought or you can simply give the question and then add let's think step by step and often this also helps improve a lot so yeah try this Chain of Thought prompting it's a very interesting technique and the last tip is to avoid hallucination so for example you can explicitly say don't make anything up or you can say select one or two relevant quotations from the text to back up your claims so yeah these are some very helpful prompting techniques you can keep in mind to control the output now let's look at some cool hacks you can try to improve the output so so I found these hacks in the anthropic docs which are about their Claude model but I would say these hacks are very general techniques you can apply to other models as well so first you can say let the model say I don't know to prevent hallucinations so you can say answer the following question only if you know the answer and otherwise tell me you don't know it this also hopefully helps to prevent hallucinations next you can give the model room to think before responding so this is a very interesting prompt you can say so you can give your instruction and then you can say when you reply first find exact quotes and then write them down word for word and then this is a space for you to write down relevant content and will not be shown to the user once you are done extracting relevant quotes answer the question so very interesting prompt where you give the model room to think by virtually writing down the things but not showing this to the user next you can break down complex tasks into sub tasks so this is a little bit similar to this Chain of Thought prompting where we say let's think step by step so here we explicitly break this down for the model so here we say please follow these steps and then step one do this step two do this and finally write me an essay about this then you can check the model's comprehension so here you give your context and question and then you say do you understand the instruction and then often the assistant or the model will reply with yes I understand this and then it follows by the with the answer so how it came to this conclusion so this is also a very cool hack you can try check if the model understands what you want so yeah these are some very cool techniques you can also try with your prompt so now let me give you some iterating tips because often finding the best prompt involves some trial and error and needs some iterating so here are just some tips you can keep in mind when you iterate first of all the general thing you should try different prompts to find what works best then when attempting few short learning try also including direct instructions because often we just list the example and then the next example and then hopefully it completes with the same structure but you can also try combining this with the direct instruction you want to have with this example then you can rephrase a direct instruction set to be more or even less concise for example if you set translate then in the next example you can be more concrete and say translate from English to Spanish then you can try different personas to see how it affects the style so again I have a list for you with different styles you can try and then also you should try this future learning by providing a few examples and then you can try out more examples or fewer examples in the next iteration so yeah just a few simple tips to keep in mind when iterating and yeah these are all the tips I wanted to show you so in conclusion keep the elements of a prompt in mind and know about the use cases then apply the basic tips I showed you and also apply the specific prompting techniques I mentioned to control the output and of course iterate to find the best possible prompt and yeah that's it so here are all the resources I used and compiled into this one guide I hope you learned a lot I also want to mention that we have a lemur best practices guide so if you want to work with our limo framework to easily apply llms to audio you can find a few prompting best practices here this will also be in the description and yeah I hope you enjoyed this video if you did so please drop us a like and consider subscribing to our Channel and then I hope to see you in the next video bye
Info
Channel: AssemblyAI
Views: 134,639
Rating: undefined out of 5
Keywords:
Id: aOm75o2Z5-o
Channel Id: undefined
Length: 14min 0sec (840 seconds)
Published: Sat Jun 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.