Introduction to Prompt Engineering
Key Takeaways
The video covers the definition and techniques of prompt engineering, including few shot prompting and Chain of Thought prompting, as well as Retrieval Augmented Generation (RAGs).
Full Transcript
So we will start with what is prompt engineering, what can be achieved with prompting, basics of prompting, elements of a prompt, prompting techniques, tips to design a prompt. So too much prompt promp prompt but I think that's uh also what we are here for. Uh and let me quickly dive right into what is prompt engineering. And to understand this a little bit, I came up with this uh diagram of an input on the left that you see and an output on the right. Right? So whenever we interact with an LLM system, so LLM for context is large language models. Uh most of our uh AI tools that we use chat GPT uh Microsoft Copilot or uh Anthropics cloud. There are there are a lot of okay first of all even before I talk about this there are a lot of different AI tools that you can use even today right so there are tools offered by the major uh tech giants there's Microsoft Google there's open AI and all of these these guys have their uh own versions of AI systems or AI tools there are also many small players out there so if you see Mistral API Mistral is actually a company in France that is also developing AI tools So there is quite a variety of AI tools out there. So chat GPT is not the only one just just for your information. You can also try uh to play with Gemini, Mistral, Llama is the open source version that uh Meta has released and a lot more. So you can explore these different tools, different uh systems and yeah basically use them as well to uh try and of course DeepS as well. I've not written deepseek here but Deepseek has been the talk of the town uh recently. So yeah, a lot of different tools for you guys to use. Um, and this is just a brief list, but let me get back to what is prompt engineering, right? So you have this LLM system or large language model system or an AI system in the middle and you give an input from the left that essentially is what is your prompt and then you expect an output. But prompt engineering is not only the modification of the input that you see, but it is also the modification of your LLM settings. So each LLM comes it comes with its own settings uh comes with its own hyperparameters uh if I can call that uh where you can tune the output of your LLM based on the setting that you have set for the LLM. So some of the popular ones I'm sure you must have at least seen this or read about this if you have not used this is temperature. uh if you increase the temperature uh the creativity of the model generally increases and if you decrease the temperature the model actually tends to give more structured responses then there's also top k uh which is which selects the top k responses in the next token prediction and I'm sorry and there are a couple more that are popular ones but also what's interesting is different AI systems have different hyperparameters that you can tune or different uh different settings that you can set. So this is also part of prompt engineering but for the sake of this talk uh we will focus on prompt uh or for the sake of this this is not actually part of prompt engineering but I would say this is also part of making sure that the outputs are best aligned to what you are looking for. Right? So for the sake of this talk we will focus on just the prompt part of it. We will try to look at how we can construct different prompts and what are the different techniques in which we can do that. But I also wanted to let you know that LLM settings also play a part in the output you generate. It's not only the inputs that you write the the English text but also the settings you set the LLM with. So I just wanted to share that with you before we actually now look into a formal definition for prompt engineering. So this is my attempt at defining prompt engineering. I hope uh someday uh we see this in a textbook. Uh if somebody is an author here and trying to find is and is trying to find a definition for prompt engineering, here's one for you. So prompt engineering is the science and art of developing and optimizing prompts to efficiently use LLMs to perform various interesting and useful tasks. This is how I define prompt engineering. And what's really crucial here uh is that it is a science in that that there are certain ways that you can actually use to make sure that your outputs are better than just writing regular stuff. And it's an art. Uh it's an art because it's a developing field. It's also little hacks that people use uh to actually enhance the output uh in in in different kinds of ways. So it's also not very well defined. Sometimes people do certain things that are just trial and error and they they find out a result that really works amazingly well for them and and then it they they preserve that and then they try to share within their communities. And it's it's it's that kind of an art where you think in creative ways to write your prompts to actually get the output that you're looking for. Right? So this essentially is prompt engineering. It's the science and art of developing and optimizing prompts. It's coming up with these prompts uh that you craft to get the output you need and also optimizing them. Uh so prompt engineering in my view is an iterative exercise. uh once you write a prompt and give that as an output uh give that to the LLM system as an input and then you get an output from the LLM system that is not the end of your prompt engineering task. You would rather and and and there are different tools also that enable you to actually track your prompts as you keep changing and uh iterating over them. uh and maybe we will talk about them in a separate master class but uh it is also about optimizing your prompts uh in different iterations to efficiently use LLMs and this is uh what we want to do at the end of the day we have a task uh that we want to achieve it could be writing it could be coding it could be um something about like structure reformatting or whatever you want to do with LLMs and we will talk about that in a future slide on on the different kinds of things you can do with LLM M um so it is essentially the science and art of developing optimizing prompts to efficiently use your LLMs to perform various interesting and useful tasks right and these tasks vary from people to people. It may involve working with input prompts LLM settings and both prompts and LLM settings and this is what I already set uh the stage up for you when I spoke about this in the previous slide. So you can work with the prompts which you give as input or the LLM settings or both prompts and LLM settings. So this is essentially what prompt engineering is. Uh I'm sure most of you have done some of these things but uh this is an attempt to formally define prompt engineering and also to understand what is possible to do with prompt engineering. Speaking of what is possible to do with prompt engineering, uh let's look at the common tasks that people use uh to achieve outputs with prompt engineering or prompting. So one of the most popular ones is of course text summarization. Uh you give a text as input to the LLM system and say that hey this is too long uh an input. Can we shorten this or something like that? and then uh the LLM summarizes that for you. Just give me a second before I continue. I would like to check if my charger is connected because it doesn't look like it is connected. So, give me a second. I will join in a second. Hey everyone, uh until I imaging his uh charger as we all go through scenarios like that. Um stay tuned. Tell me how's your master class going on and keep your all all of your questions ready and as soon as u we finish with the sessions sir will take all your questions. Okay, Sai is here. So, over to you. >> Sure. Um, yeah, so if you have any questions, please feel free to drop them in the chat or also you can keep it with you. We can take these questions towards the end. Uh, I will not be looking at your questions for now because I am looking at the slides and once we are done, we can take all the questions together. Okay. Sorry for the minor inconvenience. Uh I thought I had connected the charger but looks like uh it was not. Anyway, let's be let's come back to text summarization. Uh text summarization is a very popular application. Uh and it there are different ways of using text summarization, right? So in different contexts like if you're working in a business uh you can have lot of large reports that you would like to summarize. If you have if you're working in the news business for instance, you have lot of articles that nobody has the time to read. So you just give it to a text summarizer and then text summarizer tells you okay this is the summary of this. Um and also like if you're a student and sometimes you have like a larger uh um how do you say larger material to study right if you have a lot of things to study you just give to a text summarizer and the text summarizer can actually give you like bullet points on what you need to actually focus on. So text summarization itself has multiple subsections that I'm not talking about and it can vary from different say businesses different academic areas and different uh genres where you want to summarize text uh and get like the summary of it and then use that for your other like learning needs your business needs or whatever. So text summarization is a very useful uh application of LLM systems information extraction and this is also one of uh the really cool applications of prompt engineering if you ask me uh because what you can do is you can give especially when when when you're programming or when you when you're trying to do a lot of interesting stuff uh using code what you can do is you can give something as input and extract your information in a structured format. And this is this is actually a lot of uh this saves actually a lot of time, right? Otherwise, you have to write code that makes uh it in a certain format and then you have to uh make sure that it doesn't fail on certain accounts and stuff like that. So a lot of your manual work can be moved to the LLM system. So an example of this would be uh you have to extract the names of uh all places from a travel related article right? So you have an article and you have been given the task to extract the names of all the places in that. So what you can just do and you can say hey this is my article which talks about visiting Taj Mahal in India and then you say extract all the names of places that the person wants to visit uh when they visit Taj Mahal and then uh and maybe uh keep extract all of that as a JSON format so different file format right or as a CSV file or whatever it is and then the LLM can do precisely that and give you what you're looking for. So it's it's a really really cool application. I have used this application for different uh like formattings uh of like different to create different formattings of what I want. Uh and I think this becomes very useful in a lot of business contexts. uh and I often uh keep talking about uh this to people because this is something that they don't realize in the first instance that they can actually do with LLMs where you can get a structured output format for your unstructured from your unstructured input and this is um absolutely one of the coolest prompt engineering uh like applications of prompt engineering or applications of LLM systems. Then you have code generation and this is all the rage in 2025 like code using AI systems to write code if you are not doing today you will start doing it in the next few months for sure because in the future we will definitely have AI assisted coding for most of our needs especially for those that do not require a lot of say infrastructure work or a lot of say uh specialized knowledge uh especi if you're writing code that is uh like a CRUD app create read update delete so the the common applications where you're maintaining a database right so if you're writing CRUD applications if you're writing front-end frameworks not framework but if you're writing front end uh for different websites a lot of this can be automatically generated by AI in fact I was reading uh the other day and there was a report that said about 25% of code that is written by written in Google is generated by AI. I think there was a report by report or a tweet by Sundar Pichai who was the CEO of Google. Um so code generation is a big use case. Uh there are also very interesting tools out there in the market that help you do code generation uh and also make it uh a seamless process. That's how uh these tools enable you to uh write code, right? So of course there there are two ways. One way is of course you can just copy paste your code uh from your chat GPT uh or Gemini whatever and then put it in your file systems or you can also integrate using these tools. So one of the most popular tools out there is cursor. I'm sure some of you might have heard of it. Uh there's also wind surf. Uh I have tried both of these tools personally and uh the things you can do with them uh are are like super fast compared to just copy pasting because what they can also do uh is they can inject code in your files and then ask you to review if you would like to accept that change of code or not. And this uh actually simplifies your workflow significantly. Right? Everything is served to you right into your files. Like I said, instead of you having to copy paste and then uh solve for them. Even though we have these uh tools, I have another like caveat to add to these. They are all uh almost always not perfect. They have some issues uh in terms of the code they generate uh and sometimes uh they don't generate the right code and then they mislead you. So uh the way I usually recommend to use these code generation tools uh is to know what you're doing first of all like okay if you're using uh a particular frame framework say react or Vue.js JS or or jQuery for that matter to to write front end just know what you're trying to do. Uh you should know some background of that. Uh don't run blind is what uh I would advise, right? just don't assume that you can build stuff uh like uh and then if the reason why I say this in in in a foreign language that you don't understand maybe in go or rust or something like that and then you face issues when you're trying to deploy it or when you're trying to uh make smaller changes to it because you don't understand it then you're stuck uh in a loop trying to uh do that with these code generation tools and that is not a good place to be in but uh if you already know know the language or if you already know what you want to do and if you really want to get it done quickly then I would uh recommend you to use these code generation tools and I have used these code generation tools like I said cursor winds they make uh your workflow simpler they simplify uh uh and faster they they make everything uh happen in a more seamless way so I would recommend you to do to use these things but also with a hint of caution that you should really know what you're trying to do there are there are also other tools that I have been recently coming across uh like lovable and lovable.dev I think and there's also another one that I'm I'm not able to recall uh but these tools are for business owners or for people who actually want to quickly build to replet is another example that I was not able to recall so repletable these guys what they are doing uh they're trying to come up with these like just write prompts and then you get uh a final final ready uh MVP of the product you you're trying to build. So this is also an interesting space but in this case they are not generating code but you're actually generating the product itself right this is also a very new space u so you will also see a lot of development in this but uh it's a very interesting space um personally for me because I come from a programming background and I have uh done I have built products I don't uh try to go to that route because for me I would like to have things more in my control uh but I I'm seeing a lot of people use these tools as well to actually develop products to come up with MVPs of things they want to build and uh yeah that's also been something that people have been using. So code generation is a very interesting uh research area or application area of uh LLM systems and this is in my view one of the biggest uh changes that we will see in the software industry. uh you will like you will clearly see the way people used to code before the advent of AI tools like CH GPT and after there will be a difference text classification and this is a very common problem statement in the industry where we want to classify a certain incoming text uh as one of these categories uh and traditionally you would go and build a categorization system where you would uh if you come across the data science uh life cycle. You would try to look into the data, try to collect the label data and then build a model on top of it and then do the evaluations and then so you would used to you used to do all of this before you could come up with a categorization model for your categories. But now you essentially just write it as a prompt and then ask it to categorize and then you're done. Right? So this is the change that we see from the data science way of doing things to the LLM AI way of doing things. It has its own pluses and minuses. uh it's this is not the time to discuss that but this is uh certainly an application of prompt engineering or of LLM systems where you can prompt in such a way where you can uh where you can automatically categorize any incoming text into one of these categories. So moving on to conversation. I think most of us have uh done conversations with our AI tools. Uh but uh the reason why I put it up here is because this is probably the most uh used case but also the most under appreciated I would say because I remember the time before the advent of these AI systems. We in the industry people were trying to build chat bots but these chat bots did everything but chat right so they were very structured uh instruction systems let me put it that way right so you would say okay do this select one of these then this then that so it was very structured very limited kind of a chatbot people used to call it chatbot but it was not a chatbot in my view and I always had this discussions with my colleagues and stuff and said I don't think this is a chatbot uh but what we have today is definitely a chatbot. There's no questions about it. This is a chatbot. You can clearly chat. It can think, it can respond, it can uh continue the conversation, right? It can uh achieve, it can access memory uh about whatever you had discussed with it earlier. So, this is clearly a chatbot uh and a lot of people are doing all sorts of conversations. I read about it somewhere that uh people are building full-fledged applications for mental health wellness uh where people uh can use it as a therapist and stuff. I'm not sure about how useful or how beneficial that would be but people are trying a lot of different conversation related applications as well uh building on top of uh LLM systems and some of these you can achieve with prompting question answering. So this is also a very valuable use case uh where you can sort of give a paragraph of uh information to the LLM system and then based on that paragraph ask questions uh about what you can find in the paragraph. uh and this is essentially uh a very useful use case for many industry applications where you have large set of documents uh and you do not have the time to actually go through them and then basically you can feed that to an LLM system and then ask the LLM system to hey just look at the documentation and tell me what the answer to this question is very very critical use case you will see a lot of uses uh of this uh in the industry and there is also one uh technique of prompting engineering that we will see in in in a few slides called uh rag or retrieval augmented generation. Uh and this is actually one of the most uh I would say uh used uh most useful use case for industry uh that people are actually trying to build a lot of systems on top of it. So moving on to reasoning uh reasoning is also a very interesting and a developing area. I'm sure you must have heard of Open AI's uh 01 model. I think DeepS has it's 01 and 03. Open AI has open 01 and 03. Deepseek has R1. Gemini also has uh flash thinking. These are new age reasoning models which can perform mathematical calculations which can uh make sure uh yeah they they do like your physics problems, mathematical problems uh and any tasks that require you to think and reason right so they can do your deep research reports uh and stuff like that. So these are broadly uh the different applications of prompting and I think some of us have used uh LLM systems or AI systems for some of these. I just wanted to share a little bit more of all the different kinds of applications that you can build with these LLM systems. Now moving on to basics of prompting. Um the chat GPT version you see in the next few slides are going to be is going to be a little bit basic. uh charge GPT 3.5 just a couple of days ago you saw GPT 4.5 come out uh I created the this slide basically for charge GPT 3.5 version because that's what was available at that time and also it helps me uh showcase the different use cases. So what you see here might not be reflective of the current versions of chat GPT. So this is like a disclaimer I usually add when I'm doing this these slides. uh but I use these to explain how the basics of prompting look like and how uh how things how these systems were originally designed right so LLMs are trained to be next token prediction machines what does next token prediction machine mean for the sake of simplicity uh just for this class or for this for this session let's consider each word to be a token this is not true uh But just for the sake of our discussion today, let's consider each word to be a token. The reason why I say it's not true because it can be at multiple levels. It can be at a token level. It can be at a uh a level of sentences even. It can be at a level of multiple characters put together. There are different strategies uh that you can use to come up with tokens uh for each vocabulary. So all tokens put together is called a vocabulary. Um so there are different tokenization strategies to come up with the best possible tokens for your vocabulary. We are not going to get into that and that's why I said let's consider for the sake of our discussion today that LLMs are trained to be next token prediction machines. What is a token? Token is a word. So if if you see the first image on the left the quick brown fox this is my input the quick brown fox. And then the output from chat GPT is jumps over the lazy dog. like how did Chadypty know that I wanted jumps over the lazy dog? That that's a question that anybody would would get, right? But if you analyze and if you just Google this sentence, the quick brown fox jumps over the lazy dog, you will see that this is a very popular sentence. The quick brown fox jumps over the lazy dog is a very popular sentence. And it is popular because in this sentence you will find the use of all the alphabets from A to Z. And that's why uh this is a very popular uh statement that you will find across the internet uh discussed in different forums and uh as you probably know uh AI systems or LLM systems are pre-trained on a huge corpus of data obtained from the internet. Right? So the quick brown fox jumps over the lazy doll naturally would appear in this corpus multiple times and therefore the systems essentially learn that whenever somebody says the quick brown fox the next word should be or the next the next part of or the next phrase should be jumps over the lazy dog. So this is essentially next token prediction where you have existing tokens. You use those tokens to come up with the probability of the next tokens that might come up and then essentially use that as a prediction and give that as an output. I'm simplifying a lot of things here uh as I say this because there are also nuances to how long these uh next token predictions should look like. There's this concept of engram where you can use unigram, bgram, triagram and so on. There's a lot of things and then these are very basic concept and there are also other concepts. The attention mechanism is what uh the transformer systems uh use which is what the LLMs are using behind the scenes. Uh so there are different ways of coming up with this next token prediction as well. So like I said the first thing there are different ways of coming up with tokens. Second the next uh there are different ways of coming up with next token prediction. So for the sake of this class we will not get into that but just know that LLMs are trained to be next token prediction machines but they are not just that and this is where LLMs sort of shine and are different from the previous generation next token prediction machines. So they are next token prediction machines that can be conditioned on a variety of tasks and that's what makes them different. So if you see the sentence on the right now, the way I condition it, the way I prompt it, the way I ask it to take my input is different. I say sentence, the quick brown fox, what was the color of the fox and was the fox slow? So in this case, I have completely changed the way I give my input compared to the the image you see on the left. uh and therefore the output as well changes and the output now is the color of the fox in the sentence the quick brown fox is brown as for its speed the term quick indicates that the fox is fast not slow so the fox is not slow it is quick so this is what has happened right so now I have conditioned not just trying to predict like what is the next word in the sentence but now the condition is like there's a question and the question uh and this I talked about question answering system. So this is in a way a question answering system. So there is like like a context and on that context there is a question and then the answer is provided by chbpt. So I created or rather I changed the simple next token prediction to a question answering system by changing the instruction. Right? So, so far I hope you're getting the broad idea of how LLMs function and how uh and I'm sure you must have used all of this but this is a lot more structured way of thinking about how you can prompt. So, moving on to creating more structure. I will create more structure in the next slide by introducing you to the elements of a prompt. So far we saw okay how does uh prompt engineering look like? What is the definition? What are the applications? what what essentially it means to uh do prompt engineering. Now we get into the bones of it. We say okay what are the different elements that a prompt uh pro prompt has. So it has instruction context input data and output indicator. Every prompt you create can have all of these some of these or none. I wouldn't say none of these because if you have none, you have nothing. No prompt. But you would have either some of these or all of these. Uh and I will explain this to you with an example. So another input prompt that I give to chat GPT is classify the text into neutral, negative or positive. Here's an example. Text I was really happy with my grades. Sentiment positive. Text I think the ride was not a lot of fun. sentiment and then this is essentially my input and chat GPT outputs sentiment negative. Right? This is how you build your prompt. You have the first line the instruction where you are instructing the LLM system to do a certain task. In this case I want it to categorize or classify. So I say classify the text into neutral, negative or positive. Then you have the context. And context is an important aspect of prompting because context helps the LLM system focus on what's more important for you. And in this case, I'm essentially what what I'm essentially doing is giving an example that allows the LLM to focus its outputs in a certain direction. Let's just think of it that way, right? So when I give a context, out of all the outputs it can give, it decides to focus on this context and then say, okay, you have given me context. I will use your context and give you the output you're looking for. because otherwise I am like this big AI machine that I can do whatever I want but if you give me context I will focus on your context. So you give an instruction, you give the context and then you also give an input data which is essentially uh what you want to classify right. This is I think the ride was not a lot of fun and then the output indicator for that is the sentiment uh because you want it in a particular format right so output indicator tells what format your output should be your input data is the input that you provide so that uh that is used as something that the instruction should be acted upon on the context helps the LLM system or the AI system understand what the instruction is about also that it does not hallucinate. I'm sure you must have heard of the term hallucinate. I'm hallucination is just making up stuff. Again, there is a lot of theory behind that. Hallucination. What is hellation? What is not hallucination? I'm not going to get into it. Let's just keep it at hallucination. Okay. So, you have an instruction, you have a context, input data, output indicator. So what you have these four elements of a prompt some of them can be there or all of them can be there based on the kind of instruction based on the kind of stuff you want to do right but if you structure it this way you're likely to get a good response so the reason why I tell you this is also because if I don't give this output indicator right it is not necessary that or it is not likely that the chat GPT system will output the way it has out shown given the output Now the the output now is sentiment negative and this is how I want this like if I'm building applications using these or if I'm using this for some programming task I want it to give me structured output uh and the output indicator actually helps me do that. So what I'm trying to say is based on your task sometimes output indicator is important sometimes it is not sometimes your context is important sometimes is not but if you are trying to do something like this where you're trying to categorize or classify uh then the best outcome for you is to provide instruction context input data and output indicator. So these are the elements of a prompt. Uh like I said you can pick and choose different elements. uh you can make sure all of them are available based on your problem statement but I would recommend you to like think of the different elements as and when you write and see if all of them are there or most of them are there or some of something is missing. One quick tip here is to actually include context in most of your prompting. If you do that, you will see a a benefit uh you will see an improvement in the quality of your responses immediately. And I already told you the reason why because the LLM system is like this giant AI system, right? It's like I can do whatever you want me. But when you give context, you restrict the dimensionality or you restrict the sphere of uh outputs that the LLM system can output and then you make it think so-called think in a certain way. So the context is one of the most uh I would say important aspects of your prompt. Okay, I will move on to the next section of our session today and this is essentially the last and the largest section where we will look at some of the prompting techniques that exist out there. Um I don't know if you've heard of any of these names. I'm sure the last one is the most popular one. Retrieval augmented generation. You must have heard that this uh uh to some extent. Chain of thought prompting is also a popular one. Zero short, few short, these are also slightly popular. So we will go through each of them individually one by one uh and understand them completely. It's not very difficult even though these names make it sound complicated. uh and my hope at the end of this these uh prompting techniques is that you start using some of these prompting techniques in your prompts. Okay, we are coming to the last section and the biggest section. So it's not 5 minutes, it's more than I half an hour I think. But let's let's quickly get started. So zero shot prompting and this is a very popular common way of prompting. Everybody does this. This is not something that you you have not done this. I have done this. You have done this. Everybody anybody who has used an AI system has done zero shot prompting. This is basically like classify the text into neutral, negative or positive. I think the ride was not a lot of fun. Sentiment and then sentiment is neutral. What is the difference between the example I showed you earlier and now? As you might have already noticed, there's no example here. There's no context here and this is why I was talking a lot about context. So if you don't give context, if you don't give an example and if you just ask the LLM system, hey I want you to do this, go ahead and do this. Right? That is called zero short prompting. So classify the text into neutral, negative or positive. This is my text. Give me the sentiment. This is zero shot prompting. And if you see the answer and this is uh true for chat GPT 3.5 not true for any of the newer versions anymore the answer is wrong sentiment is neutral it was I said ride was not a lot of fun how is this a neutral sentiment right so the earlier systems this is one I think 8 months 9 months in in in the world of AI one week is one year anyway so yeah so classify the text uh into neutral negative positive chat GPD 3.5 does not actually get it right if I do zero shot prompting today this problem is solved the newer systems can get it right in the with zero shot prompting but back then zero shot prompting could like in this example not get it right so what what does zeroshot prompting mean zero prompting essentially means that you do not provide examples and you just give your instruction ction your output indicator and your input. That's it. If you remove context from your the elements of a prompt that I showed you, if you remove context, that is zero shot prompting. And it's called zero shot because there is no example. Zero zero shot. Okay, this is zero shot prompting. No example prompting. Just give an instruction, give an input, give an output. What is short prompting? Fewshot prompting is where you give few examples. It can be one example, two examples, three examples, few examples. You don't need to have one lakh examples or two lakh examples but few examples, right? Classifi and how do you know how many examples are good? Uh you can sort of do like a trial and error. You can also set up evaluation metrics. That is a bigger topic. But simpler way is just do some trial and error. You uh give few examples. You see if you're getting the output right or not. If you're getting it right, then it is what you're looking for. Anyway, moving on to what few short prompting means. Classify the text into neutral, negative, or positive. Here's an example. Text. I was really happy with my grades. Sentiment positive text. I think the right was not a lot of sentiment. Sentiment is negative. Now it gets it right. What's the difference between zero shot and view shot? The difference is the example. And this is uh like and I have done this session before as well. I I shared with uh other folks if you want to take one prompting technique uh which you can easily use in your day-to-day life uh I would suggest you to take few short prompting because it automatically improves the quality of your output and it's not very difficult or complicated to use. So that is another tip that I have for you. Uh if you would like to actually do few shot prompting uh give examples and then you have of course your input and your output indicator and then all of them will uh actually get you the output that you need. Moving on to another interesting prompting technique called meta prompting. And metaring is essentially you providing the recipe of your prompts uh recipe of your outputs to the LLM system or the AI system. So I will explain this to you uh you know with using the example that you see. So this is actually from a research paper from 2024. uh it is actually talking about uh how to find the roots of a quadratic equation. I'm sure all of us have studied quadratic equation in school. What is the format of or rather what is the form of quadratic equation? So it's generally ax² + bx + c is equal to zero. Uh and then you have x= - b plus or minus roo<unk> of b square - 4 a c uh minus b plus or minus roo<unk> of b square - 4 a c by 2 a. So this is how you get the roots. Uh and then essentially when you substitute the values of a, b and c, you get the roots of your equation. This is how you find the roots of a quadratic equation. And this is essentially the recipe of finding the roots of a quadratic equation. What do you do? You take this recipe and give this as input to your LLM system. The LLM system. And then event and then finally you say here's my new problem. I want you to solve 5x^2 + 2x - 1 is equal to 0 or something like that. Any new equation you want to solve. Use the recipe that I shared above and come up with the final answer. This is meta prompting where you use your recipe give that as a input in your you include your recipe as input to your LLM system and the LLM system uses the recipe to come up with the final answer that you're looking for. And this is particularly useful for mathematical problems and problems that involve computation. Right? You can also use this for generating text. Uh so one of the examples that you would see here is without metaring you would just ask what are the benefits of renew renewable energy. With metaring you would say think step by step and list five benefits of renewable energy. Then for each benefit provide a brief explanation. Identify one challenge associated with it. So you sort of prime the LLM system. You tell the LLM system to go through a certain process and use that process to come up with the final answer. Similarly, without metaprompting, solve the quadratic equation x square - 3x + 2. Then you say solve the quadratic equation x2 - 3x + 2 using the quadratic formula. Think step by step. Show all the steps involved in solving it and explain each step clearly. Also, check your solutions by substituting them back into the original equation. If you formulate your prompt in this way, you are automatically improving the quality of your output. And this is a new sort of newish because it was uh developed in 2024 by Zang at all. uh a technique that is being used to get better results from your LLM systems and this is called meta prompting. It's not very difficult. It's essentially you the way I like to remember this is you providing the recipe of your dish to the LLM system and then the LLM system cooks. Yeah. Anyway, I I will move on to the next and very interesting prompting technique called chain of thought prompting. And this uh technique is one of the most popular techniques out there that is actually being used by open AI researchers and AI uh anthropic or Google or Gemini whatever researchers. Uh it is not very I mean it's also used by uh common folks like us. But the reason why I mention this is because chain of thread prompting is one of the key techniques used in the development of reasoning models that you see. So if you see the 01 model or the 03 model and the R1 model from deepseek 01 and 03s are from OpenAI. These models are called reasoning models and these are different from your GPT models or your cloud set models which uh do not have this reasoning component to to them. And the way they built this reasoning component uh is by doing inference time compute. Uh it becomes a slightly more technical sess session on how they are adding reasoning to the the existing models. Uh but what they're using is essentially chain of thought prompting. But what is this chain of thought prompting? Now very quickly let's look at this example and then I think it it fits right into your head. It's not very complicated but it's a very effective technique to make sure we get the right answers. So this is another uh research paper that was uh written in 2022 uh standard prompting. So you have like a regular again math problem math problems are slightly difficult for LM systems or rather very difficult because reasoning solves for it but very difficult because uh you had to reason for it right you cannot just remember stuff in math and that's why math you have to go stepwise and then come up with an answer so this is what you see here Roger has five tennis balls he buys two more cans of tennis balls now each can can have three tennis balls. Uh, how many tennis balls does he have? Now, answer to that is 11. And if you do the calculation, you will get 11. Next question. The cafeteria has 23 apples. If they used 20 to make lunch and bought six more, how many apples do they have? The output of the model is 27. That is wrong. The mathematical calculation is wrong. But how can you make the LLM system get the mathematical calculation right? And the way you do that is by chain of thought prompting where you use the same examples but you change the way you provide the answer to the example. So the question is Roger has five tennis balls. He buys two more cans of tennis balls. Each can can have three tennis balls. How many tennis balls does he have? Now the answer to that is Roger started with five balls. Two cans of three tennis balls each is six tennis balls. 5 + 6 is equal to 11. The answer is 11. So you do not just give the answer but you also give the way you would come to the conclusion that the answer is 11. So you say five two cans have three balls. So it's six balls. So 5 + 6 is 11. Now you give your question. The cafeteria has 23 apples. They use this. And when the LLM is trying to calculate the answer, it will use your context. It uses, like I said, I I said this earlier as well, the LLM uses your context. The context can help you determine how you want the LLM to think. And in this case, you introduce chain of thought prompting by asking the LLM to use a particular chain of thought to solve the question. And this is what chain of thought prompting is. You ask the LM to go through a certain chain of thought and it uses that chain of thought and comes up with the answer that you're looking for. So the cafeteria has 23 apples. Originally they use 20 to make lunch. So they had 23 - 20 is equal to 3. They bought six more apples. So they have 3 + 6= 9. The answer is 9. And this gets you the right answer. Just a small change in your input prompt in your input context. Just a small change, you introduce chain of thought prompting and the answer is correct. This is the advantage of chain of thought prompting and chain of thought prompting really works well. Uh and that's why researchers have doubled down on this and are now like I said creating reasoning models. We will briefly look into the different types of chain of thought prompting. I will not go into much detail. Um but I think one of them that you can easily adopt is zeros short chain of thought prompting. Right? Uh we already know what zeroot means. So you don't give any example and that is also possible for you to do if you really don't know uh how to solve the answer right. So you say I don't know how to solve the answer to this question. In the previous question, of course, you knew the math, but in this case, let's say you don't know. So, what you can also do is you can just say uh think step by step and it works. So, if it works to some extent, it's of course not probably the best possible way to chain of thought prompt. Uh but I would say it's it's a better prompt to create than just without think step by step. So, types of chain of thought prompting, zero shot chain of thought prompting. Add a think stepby-step line to your prompt and let it think step by step. And that is your first type. Second, manual chain of thought prompting. So, you give the LLM the example of how to reason through the problem statement. And this is what we already saw in the previous example where we give the LLM the not only the answer but how to come up with that answer. And then the LLM basically uses that logic to come up with the answer when it is calculating. Right? So you see examples here. I'm not going through the examples that you see on the screen. So there is one zeroshot prompting on the left. There is one manual chain of third prompting on the right. It's very similar to what I just said. In in the first case, you just ask add things step by step. In the second case, you manually provide the logic. But this is cumbersome, right? So you have to keep doing this every time. So what people have also suggested are different ways of automatically doing this. So there's this automatic chain of thought prompting which will generate reasoning chains automatically and improve their quality by sampling technique by using a sampling technique and use the generated reason chains to generate a final answer. This is slightly more complicated. Um but this is essentially what uh I was talking about when I was talking about in the context of reasoning models where they're in where they're using automatic chain of thought prompting techniques which will allow you to generate these reasoning chains automatically and then you use a sampling technique that will allow you to select the best possible subset of your answer or best possible answer and then you use another LLM to finally generate your final answer. So the the to get into the details of the autocoot method will take us some time and it's slightly complicated. Uh but what I will just talk about uh or rather I will share if you if you're interested the the link to the research paper later and you can go uh and read it and understand what is happening with the automatic chain of thought prompting. Okay. So this is all about chain of thought prompting. It's a very useful technique. A lot of people are actually in the in the case of researchers specifically are actually doubling down on this and building a lot of stuff. There's also an exist uh there's also like another self another technique self-consistent self-consistency prompting that is sort of uh auto chain of thought prompting. Uh in the way that you you do it is basically you have your input chain of thought prompting and you do this multiple generations and then you finally come up with a majority voting uh of which generation is the right generation and then you give that as output to the user. uh uh self-consistency prompting and autoco chain of thought prompting sort of overlap uh because in both cases you have multiple chain of thoughts being generated and then you use a technique to finally come up with a test output. Uh but this is this was also being developed as a separate prompting technique initially. Moving on to generate knowledge programming. This is a very interesting uh generate knowledge prompting sorry. Uh this is a very interesting prompting technique where you can divide your task into separate steps. Uh where the first step is essentially generation of knowledge and then the second step is the using the generated knowledge performing the actual task you want to perform. Uh I have an example task here. So if you want to write a blog post on cars in Germany, that is the task that you want to do. You can either go to the LLM AI system and say write a blog post on cars in Germany and then it will come up with whatever it can come up with or you can use generate knowledge prompting which allows you to make a better sort of uh pro blog post essentially because it allows you to focus on the generated knowledge and then use that to come up with a blog post. So write a blog post on cars in Germany. Sorry. Um the knowledge generation part would be generate 10 facts about cars in Germany. Right? You're not actually writing the blog post here. You're telling okay tell me about the cars in Germany. Then you do task prompting which is essentially what the task is. you use the about generated knowledge and you come up with a blog post and then your output essentially is the blog post on cars in Germany. So this is one way of splitting your task into different sections and then using or rather chaining each section to come up with the final output. Right? So you had one task of writing a blog post on cars in Germany. You split that into two different LLM calls or LLM tasks. knowledge generation task prompting with the generated knowledge and you chained them together. So this is essentially what we call prompt chaining. So this is also a prompt chaining. Uh prompt chaining is a way of prompting where you can chain different prompts uh next to each other and where the output of where the input of one prompt is dependent on the output from the previous one uh and then you chain them together and come up with a final output. So generate knowledge prompting is another popular not very popular but it's it's it's another uh it's it's popular in the context of using AI agents. Uh I don't know if you've heard of AI agents but AI agents are like semi-autonomous uh units that perform specific tasks. Uh and in this case what you try and generally do is create different AI agents that can specifically do a certain task. and when they do a certain task uh they coordinate with each other and then they come up with the final output that you're looking for. So we sort of use this principle uh when we are trying to build up AI agents because we want uh specific agents doing specific tasks but for the sake of our discussion today this is one way of prompting uh and coming up with your outputs. Next moving on to tree of thoughts. This is also a very interesting way of prompting uh and the underlying principle is to provide the large language model an opportunity to explore multiple branches of reasoning while self-evaluating as it progresses. I'm not entirely sure but I have a feeling that tree of thoughts is also incorporated in the reasoning models that we see today. uh that's also probably because they do a lot of internal processing and then they come up with the answer right so I think they have tree of thoughts but another way to essentially remember what tree of thoughts uh method is is that it constructs a tree of different thoughts a binary tree or a tree with multiple nodes and then it tries to eliminate these nodes and come up with a final node right so uh if you have studied data structure because uh you have binary trees or you you can also use LLM systems uh to essentially use these data structures uh and different tasks that you can do use right you can do you can do bread first search you can do depth first search you can do uh find an element uh in your you can do s searching you can do sorting um bubble sort all of these things so you can use these techniques in your prompts and that is essentially what the LLM system would basically use to come up with the answer. So if you see an example that I had actually asked this LLM system uh about so answer the following query using the three of thought methods only after you list the thoughts rate them and build upon the promising ones creating a new set of thoughts. Repeat until a conclusive answer is found. That is do a breadth first search. Organize the entire response in a markdown table format. That is my instruction. And now my input query. What is the most important thing in life? So I asked chat GPT 3.5 to tell me what is the most important thing in life. But the way I want it to do this in a way I'm also doing meta prompting here. Right? So I'm giving it the recipe. Answer the following query using the tree of thoughts method. But in that recipe I'm giving another recipe. So it's like meta meta prompting. So I want you to use tree of thoughts method. Only after you list the thoughts you will rate them and build upon the promising ones creating a new set of thoughts and you will repeat this until you are able to do an entire breadth first search. So like I said you can use your data structures knowledge you can use your tree of thoughts uh to build different trees and then the meta prompting. So this is multiple prompting techniques put together to answer this question that is what is the most important thing in life. Now I hope you're ready to see what's the most important thing in life. But before I go to that I would like to see what do you think is the most important thing in life. in chat. What is the most important thing in life? Can you drop your answers in the chat? Happiness is one answer. Money Contentment. Okay, we have three answers. Happiness, money, contentment, passion, freedom, peace with what you have, fulfillment of purpose. I know the answer of course uh that the LLM gave. parents very important but is that the most important thing in life we will find that out now okay I think we have a few answers let me even before I go right even before I go and uh start talking about that uh somebody has answered purpose okay self-actualization parents marriage can somebody help Aditya get married. He thinks it's the most important thing in life. I will ask this question to you after you get married, Adita. But okay, moving on. Uh let's let's let's let's really uh go back to our slides and see how chat GPD does it, right? So it comes up with a set of thoughts that it considers for the most important things in life and it gives its own rating. Love, happiness, purpose, health. We see some of these in your answers as well. fulfillment, family, success, contribution, inner peace, personal growth and then it gives an initial rating and then it says okay I have all these thoughts I have given them an initial rating and these are the promising thoughts. Love is rated highly. It's often considered fundamental to a fulfilling life. Happiness is crucial but can be subjective and fleeting and so on and so forth. So it gives its rationale for why it thinks these are important. Right? So this is the first part. Then it expands on it. So it say okay I have love. I've given it a nine and this is my expansion to love encompasses various relationships and connections. Not just romantic but also friendship, compassion and empathy. It fosters a sense of belonging and fulfillment. Happiness is an eight. Pursuing activities that bring joy and contentment is essential. It's also about finding contentment in everyday life and so on. Purpose is a seven. I think some of us some of you guys mentioned purpose. Discovering one's purpose involves understanding personal values, passions and making meaningful contributions and so on. So it family is a nine, inner peace is an eight, health is a seven. Then what it does it prunes or it shortens the thoughts because it has identified some of them uh the top two or top three whatever it does and then it says okay now I have these and then I expand on that again and then finally it gives me one conclusive answer. It says the most important thing in life is love particularly the love we share with our family. This love provides a sense of belonging, support and fulfillment while also fostering inner peace and resilience ultimately leading to a deeply satisfying and meaningful life. So now you know what you need to look for in your life. I hope uh answered by an LLM. Uh so marriage of course is one of them. The love you share with your family, love you share with your parents and uh love you share with the mo most important people in your life. At least according to the LLM. I know some of us also said self-actualization and purpose but LLM thinks love is more important than that. So this is I mean this is a fun example of course but you can also use these this this kind of a prompt or or a way of asking for other important decisions in life for example like should I take the job abroad or should I continue to work in India? What are the pros and cons? You can ask it to evaluate that and then it keeps evaluating and then it comes up with an answer or should I take up a course with AMERS or should I do something else evaluate the pros and cons and uh come up with the final answer. All of these things, LLM provides you with a structured way of answering difficult questions or questions that require a lot of thinking and reasoning and also gives you the reasons for why it thinks it provides the score that it does. So, this is another prompting technique that you can use to come up with answers to questions that require deeper thought, uh, deeper analysis and finally come up with an answer that you're looking for. Last technique that I have for today is rags or retrieval augmented generation. This is a very popular technique and in fact if you ask me I can do an entire session of two hours on just rags because rags has a lot of different components. Uh I I just show you a very brief uh flow diagram of all the different components. You see question retriever large language model response context but each of them can be a like I said half an hour 1 hour session but what what is what does it actually mean right so you you have the large language model you have the response so we this we understand large language model response uh any AI system LLM whatever you want to call it it will give you a response but before we give an input to the large language model which is our question if you have a question we use a retriever And the retriever references a context which is basically constructed from your custom document uh and enhances your prompt. Let me explain it very simply. If you have a very personal document, right? Uh document about the events in your life. When were you born? When were you when did you graduate and stuff like that? You wrote that in a document. Right? Now this should not be common knowledge on the internet because this is not you're not a public personality nobody really knows about you or if you have written down in LinkedIn and other places maybe that is also there but let's just assume you are not a public personality but you want an LLM system to answer questions about you right so you would write that in a document you would create embeddings from that and then you would provide that as context to your retriever were and that and then you ask questions what is uh the age uh at which I graduated something like that right or what is the age at which I graduated I just asked this question I have given this documentation so it can use the knowledge that I provide as context or a custom document and pass my question as in the prompt this knowledge both of them add and become a super prompt and That prompt is passed to an LLM which uses that question context like how we would use uh in few short prompting uh and then using that context it comes up with a final answer. What you have done in this process is you have created an engine or a system that can answer questions on your custom documents. And this is a very very valuable use case for many industries. You have banks who have who have lot of different documents and you want people to ask get question and like this is a very valuable piece for customer support. Let me just put it that way. Any industry has customer support, right? You want to provide support to your customers. You have your lot of a lot of documentation. How can you provide them uh a easytouse chat interface where they can they can use your custom documents and come up with question answering system where you can ask any questions and then can get the answer and then you can basically have an conversation. So I mean in our parents' generation we used to have product manuals. uh in our generation we will have product chat bots who will not just be the manual but will also talk to you about okay what more do you need and stuff like that and then try to provide an answer to you right so this is the evolution of technology rags is a very useful use case uh where people are using to build lot of different and interesting and cool systems uh in the industry uh and yeah so uh rag I'm not going to talk much more about rags. Uh maybe rags is like I said it's a full-fledged system, a full-fledged session. Uh where we talk talk about how the context is formulated, how the retriever can be selected, what should be the parts of uh your question and how should we choose an LM. So each of the components you see here uh is also a decision you need to make when you're building a rack system. Um yeah, so that is about retrieval, augmented generation or rag. And with that we have covered all the different prompting techniques that we wanted to talk uh in our session today. And finally I just want to leave you with some tips while designing a prompt uh where I would like you to start simple. So use only instruction or question even though I mentioned all the different elements of a prompt instruction context question or your input and output format. Start simple. Use only instructional question. If this is able to give you the answer that you're looking for, then you don't need to do much more. But if you think the answers are not as per your satisfaction and you would like to get a deeper answer or a more precise answer, then I would suggest you to add more elements and context. If zeros prompting does not work, try few short prompting. And like I've already told you, few short prompting is one of the techniques that I would recommend you to try uh often because it's not very complicated and you can easily add a few examples uh that you're trying to uh for the for the task that you're trying to solve for. Be very specific in your instructions. uh giving a very like if you if your input prompt is very vague and generic, the outputs are also likely to be in that way. You want to be very specific about what you want the LLM to do. You want to be as precise as possible. Let me just put it that way. Explicitly mention output format if you specifically need the output to be in a particular format. This is also a very important point because especially for programming tasks, you will need the output to be in a particular format because if you want to build like APIs on top of it or if you want to use it for other downstream tasks, you want the output format to be reliably in a particular format. So this is an important part that you will have to do if you really want to stick to a particular kind of output. So do that and keep iterating. So you always you will never or I never say never but uh you will most likely not get the output in your first iteration. You will want to keep iterating until you get the right outputs for your task. There are also a few tips uh like uh you can also do role play uh and I did not write it down here but uh I'm sure you must have come across that you can say as a mathematics expert or as a programming expert do this some people do this role play where you said you ask the guy to assume a role as a doctor can you tell me what are the things it helps to some extent um and yeah I think That's also another uh area in which you can sort of improve the outputs by asking the LLM to assume a personality. So as this can you do this this this this um and I would suggest you to also try that for specific tasks uh that you are looking to solve for. Keep iterating and happy prompting uh is all I would like to say to end of our session
Original Description
In this video, we will be taking a look at prompt engineering, the hottest new skill in the AI town. We will first take a look at the definition of prompt engineering and then go further into the different techniques like few shot prompting, CoT or Chain of Thought prompting etc. We will also briefly look at RAGs or Retrieval Augmented Generation, which have been driving a lot of use-cases at many companies. Finally, we will end with some tips to devise and create prompts. Happy watching and happy prompting!
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Imaad Mohamed Khan · Imaad Mohamed Khan · 34 of 34
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
▶
Does AI know Fashion? - Mitali Sodhi - Mantissa Data Science Meetups
Imaad Mohamed Khan
Mantissa Data Science Webinar - 1 with Santhosh Shetty
Imaad Mohamed Khan
Recommender Systems - Imaad Mohamed Khan - Mantissa Data Science Meetups
Imaad Mohamed Khan
Data Science is more than just Data Scientist - Different Roles in the field of Data Science
Imaad Mohamed Khan
What topics to prepare for Data Science Interviews in 2020?
Imaad Mohamed Khan
Programming as a human activity
Imaad Mohamed Khan
What are the languages or tools used by Data Scientists in their work?
Imaad Mohamed Khan
Linear Regression From Scratch - Part 1
Imaad Mohamed Khan
Linear Regression From Scratch - Part 2
Imaad Mohamed Khan
Linear Regression From Scratch - Part 3
Imaad Mohamed Khan
Journey into Data Science - Fireside chat with Adarsha and Karthikeyan
Imaad Mohamed Khan
Off the ground - Python in 5 Steps
Imaad Mohamed Khan
How LinkedIn uses Data Science to build your feed - LinkedIn Feed Algorithm Explained
Imaad Mohamed Khan
Fireside chat with Eric Weber - Learnings in Data Science
Imaad Mohamed Khan
Part 2 - How LinkedIn uses Data Science to build your feed | LinkedIn Feed Algorithm Explained
Imaad Mohamed Khan
Using Streamlit's Share Feature to easily deploy (and share) videos using Github
Imaad Mohamed Khan
Airbnb Experiences Ranking Algorithm Explained - Part I
Imaad Mohamed Khan
Airbnb Experiences Ranking Algorithm Explained - Part II
Imaad Mohamed Khan
Airbnb Experiences Ranking Algorithm Explained - Part III
Imaad Mohamed Khan
Big Data, Hadoop and Machine Learning Explained using Dams
Imaad Mohamed Khan
Fireside Chat with Hiromu Hota - Transitioning from Research to Industry
Imaad Mohamed Khan
Introduction to Anomaly Detection and One Class Classification
Imaad Mohamed Khan
Reading and manipulating Google Sheets (GSheets) using Python libraries
Imaad Mohamed Khan
Writing to Google Sheets (GSheets) using Python libraries
Imaad Mohamed Khan
Fireside Chat with Mirza Rahim Baig - Business Problem Solving and Data Science Career Tips
Imaad Mohamed Khan
Six types of Data Analysis you will do as a Data Scientist
Imaad Mohamed Khan
Automatic Speech Recognition (ASR) with Facebook AI's wav2vec 2.0 model using Huggingface
Imaad Mohamed Khan
9 Anti-patterns to avoid MLOps mistakes
Imaad Mohamed Khan
8 pitfalls to avoid while using Machine Learning Interpretation Techniques (SHAP, PDP, LIME, PFI)
Imaad Mohamed Khan
Fireside Chat with Shadab Khan - AI in Healthcare and Data Science Career Tips
Imaad Mohamed Khan
Features and Feature Engineering in Machine Learning - An Introduction
Imaad Mohamed Khan
Building your own AI text generation tool with aitextgen using GPT-2/GPT-3
Imaad Mohamed Khan
Organising Data Science projects using CRISP-DM
Imaad Mohamed Khan
Introduction to Prompt Engineering
Imaad Mohamed Khan
More on: Prompt Craft
View skill →
🎓
Tutor Explanation
DeepCamp AI