How LLMs Actually Work: The Secret Behind ChatGPT, PaLM & GenAI Explained Simply!
Key Takeaways
The video explains how Large Language Models (LLMs) work, including the transformer architecture, encoder-decoder block, and training process, with examples from ChatGPT and Google PaLM. It covers the basics of LLMs, their training process, and the tools used to build them, such as the encoder-decoder block and reinforcement learning with human feedback (RLHF).
Full Transcript
Hey everyone, welcome back to my YouTube channel. In the last video, we talked about uh what is generative AI and why it is standing these days. So before moving to the video, I want to I want to I want to ask you a question that have you guys ever wondered how these AI tools like chat GPT, Germany, GitHub, Copilot actually works? What is happening behind the scenes? And when you ask any question when you give a prompt to the chat GPT you will get an response like humans and more intelligent than humans these days. So in in this video we are going in in this video we are going to discuss a brain behind the generative AI models. So large language model is something that is working behind the model that makes it possible uh for the for these AI tools to generate humanlike responses. So what is large language model? So let's uh let's starts with the what is LLM? LLM stands for large language model and why we say large why we add large to the language model. So, so its definition have two parts basically large and the second one is language model. So, this this this will help you to remember the proper definition of large language model. So large we use because it trained on massive amount of data. Trained on massive amount of data amount data and uh the second thing is language model. So what are language model? So all language models have same characteristics and what is that characteristic? Uh language model predict the next token. It predict the next token. And you guys you guys now thinking what is token? Sep can you please tell us what is token? So token is uh token is a word or subword. Token is nothing but a word. For now you guys just imagine token is only a word. Okay for example for example uh let's take an example I love. Yes. So our language model uh try to predict something relevant to the I love. So model might predict model might predict you I love you or let's say I love apple. So that's it. Language model the main job of language model is to predict the next token and that is how it can generate full paragraph full sentence. Okay. when we when we give a prompt to child GP it will give us more full paragraph. So that is possible because of language model and language model is nothing but predicting next token one by one. But now again thinking that uh that the the these AI tools like chat GPT are generating next token. But how it is possible that it have the proper context? What we are what we ask what we ask to what we gave a prompt and it gives us paragraph that are relevant to our question that the the these AI to AI tools like chat GPT are generating next token. But how it is possible that it have the proper context? But we are what we ask what we asked to uh but we gave a prompt and it gives us paragraph that are relevant to our question. Now why how it is possible? It is possible because of transformer transformer architecture. So this is the main hero of large language model. Every large language model uses this transformer architecture. And in our next video we will discuss more briefly about the transformer architecture. But right now uh I'm just saying that this looks like this that we provide input. It gives us represent uh representation vector and this is our output input encoder. This is encoder block and there are various things inside the encoder block. And this is the decoder block. Decoder block. And again in decoder block also there are many things. So, so I will I will show you a picture of encoder decoder. Just give me a second. So you guys see this picture. So here in this picture, so in this picture, so in this picture, this is encoder block. Encoder and in this part is decoder block. Uh I'm writing here decoder. Okay. So this is the transformer architecture and uh all the AI tools all the AI models using this architecture these days. So, LLM came into picture uh after this uh this architecture but before uh let's yeah so LLM characteristics massive amount of data amount of data first thing sources what are the sources of uh the text data So, Wikipedia, books, articles, public, conversations, social media. So, the training of large language model. Now you guys have an idea uh that large language models are uh predicting next token. Now we are discussing uh how a model is built. How what is the training process of the large language model and you also uh know that all the large language model are using this transformer architecture that have encoder and decoder block. And the job of encoder block is to process the input uh sentence and gives us say representation vector. Uh see vector we need to do vectorzation because machine do not know do not understand the words. Machines knows the language of vectors. Okay. So encoder block gives us the representation vector and uh decoder process it and gives us the output and predicting next open. Now we will deep dive into the process of training of LLM. Okay. So training of LLM. So the first part of first part is data collection. So there are there are AI teams that their job is to only collect data from various sources. So I already tell where uh where the huge amount of text data comes. It comes from books, it comes from Wikipedia, uh public conversation that are available on social media and other platforms, articles, news. Okay. So using these API using the API of these sources we can get the text data and uh and yeah so the first so the second part is after we got the data we do something called tokenization tokenization. So in tokenization sentences break into tokens and tokens are word of support. Okay. So uh like uh I am a boy. I am a boy. So in this first we split the sentence and these are my token. Okay. So we can do this chunking. We can do this tokenization. Now the third part is model will be trained using encoder decoder block encoder decoder block and the same thing is happening we are giving sentences and we are giving output. So output in vectors and then using uh using the ids of these tokens uh the the real sentences can be made. Okay. So this is the process is uh this is the process of training. So in training model tries to predict next token token. So I is passed to the encoder block and uh M we will get in output but but not every time it will give us m. So, so when our model predict next token then then the next token that it predicted this next token compares then our model compares the next token with the correct answer. So next token will be checked with the correct answer. Correct answer. If it is wrong, if it is wrong then we compute something called loss. So our model So our model compute loss. There are many kind of losses that we already know that mean squared error, root mean squared error and there are other other losses. So basically basically model So let's take a diagram instead so that you guys can better understand. So this is exactly what is happening uh while creating these models. So here we have tax data then we do tokenization then we predict next token then we compute loss various kind of lows we can compute. We can check our next token with the correct next token with correct answer and compute loss correct answer. And if our next token is is wrong then what is happening? Wait updates. So inside our encoder decoder block encoder decoder block there are parameters. There are parameters. So after calculating loss we will update our parameters so that our model will become smarter. Our model will become smarter. So when we do when we do a huge amount of data. So if we we we are saying that huge amount of data huge means very use means we have millions of tokens. millions of tokens. Okay, millions of token. So when we do this million of times, we are passing text data, we are tokenizing it, we are predicting next token, we are computing loss, we after calculating loss, we are updating our parameters inside our encoder decoder block. Then our model becomes very smarter. It eventually it eventually start learning grammar, facting, language understanding becomes very much language understanding. So this is exactly what is happening behind the scenes uh for creating large language model and uh after we can do all this we get the model that is giving that have the power to understand human language and that is capable to give us responses like humans. Okay. So now now we let's take something let's take two famous example I can tell you how chat GP uh is is trained okay so child GPT is trained in three phases first phase pre-training pre-training using massive data massive data this is first step. The second step is the second step is fine-tuning tuning and the third step is reinforcement learning RLHF reinforcement learning using human feedbacks. So these are the three stages that are used to train C shared GPY. So in 2018 when chat jupy came then the first step then then only pre-training was have was uh was done okay so in pre-training what we can do we can do the same steps we can do the exactly same steps text data tokenization prediction loss compute weight update and we get the smarter model like GPT1 okay so this is this is the thing that uh was done and first phase. Now coming to the second stage finetuning. So in this stage uh many so in this stage we we we we make our model more smarter by giving feedbacks by giving uh instructions that uh what is the correct answer? It is it is like supervised learning. This fine-tuning is like supervised learning. supervised learning. Okay. So there is question and there is answer and that are made by humans humans. Okay. So this is supervised learning and on top of the on top of this model this model using first step the second thing is this question and answering and in this way we fine-tune our model by giving by giving our model right questions and right answers by giving right answers based on the questions and those question answers are created by humans experts. For example, in this step uh for example, I came across one of my friend that is working with Turing. So the exactly the same fine-tuning he is doing uh for an AI model that uh uh that is for some big company. Okay. So, so his work is based on uh any question asked to the any question was asked to the AI model and it gives response but he is correcting the response of the AI model by uh by instructing chat GPT by instructing AI model and he is correcting the answer. Okay. Now coming to the third step that is human feedback. So this is so simple this is very simple step that uh you that you guys encounters with the this situation that when you when you were using chat GPT and uh chat GPT gives us two responses response one response two and he asked and he asked us that which one you want to prefer. Okay. Then we provide our feedback. Okay. That response to is response to is good. So you will give me this type of answers every time in in future. So this is this is the third phase of chat GPT. So this is how chat GP model chat GP AI tool is based using GPT series models. Okay. So uh I'm giving you few things. So I'm telling you few things about chat GPT that GPT 3.5 model. Okay. Uh you can think about how many tokens how what is the number of tokens that uh that was used to train this model. Let me write it 300 billion tokens used to train this model. And there are n number of GPU power used. Okay. And the training and the training going on number of days now and the training The model trained model trained four weeks. Four weeks. One more thing. So we know we got to know about how many tokens we used. Let's talk about 175 million parameters. Can you imagine 175 million parameter used? And what are these parameters? Again, encoder decoder block. Encoder decoder block. There are various uh internally things that you can see uh in this in this photo. We discussed about the photo. Yeah. So, let me zoom out. Yes. So the so so parameters are using here. So in chat GPT there are 175 million parameters. So we will discuss this transformer architecture in our next video. Uh that is not the scope of this video. But uh I want to give you some idea about uh these parameters. Now we can take also Google Pal. Google Pal again this have 500 billion parameters. Yes 500 billion parameters. I'm talking about parameters in chat GPT 3.5 have 175 million parameter but Google palm have 500 billion parameters and this is the model uh this is the very you know big model that ever built on that time in around 2023 22 to 23 and uh also 6144 TPU TPU bigger than GP CPU V4 chips are used to train this model compute. You can imagine how big this model is and uh again the data uh used from books, Wikipedia and many other resources uh that are used to to collect data and train this big model and all yeah there are various other models uh for example Dali that is trained on many images that can generate image from text when providing text. Sora for the videos and cloud. This is also one of the model Germany. There are various models these days. But uh our motive to summarize this video. Uh we discussed what are language models and how language models are trained. And these two chat gypy and Google pal. We discuss some of the uh some good fact about these models. But in next video uh we will introduce the main hero of the whole story. The main hero of the whole story. Uh then you will connect that how generative AI models are are creating content on its own. So this is the main hero that can that can uh that make it possible to build to train large language model and large language model and after uh you know after getting large language model it is possible to create these generative AI tools. Okay. So thank you all. Thank you so much for watching my
Original Description
#LLM #GenAI #ChatGPT #GooglePaLM #ArtificialIntelligence #MachineLearning #AIEducation #DeepLearning #NeuralNetworks #TechExplained #AIModels #YouTubeTech
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Why LLMs prioritize high-signal analytical networks and how to secure citations in an AI-driven…
Medium · AI
Integrating Open-Weight LLM APIs: A Developer's Guide to Accessible AI
Dev.to AI
Who’s Afraid of Chinese Models?
Stratechery
I compared the real cost of running LLMs on AWS - here's when each option makes sense
Dev.to · Jerzy Kopaczewski
🎓
Tutor Explanation
DeepCamp AI