youtube.nixfred.com nixfred.com

Deep Dive into LLMs like ChatGPT

Andrej Karpathy's general audience deep dive into the full training stack behind ChatGPT, in one sitting: pretraining on a filtered crawl of the internet, tokenization, what the base model actually is (an internet document simulator), supervised fine tuning that turns it into an assistant, and reinforcement learning as the third and least mature stage. The second half is LLM psychology: why hallucinations happen and how they get patched, why models need tokens to think, why they cannot spell or compare 9.11 to 9.9, and what emergent chains of thought in DeepSeek R1 mean. It ends with where to find and run these models yourself.

Published Feb 5, 2025 3:31:23 video 154 min read Added Jul 30, 2026 Open on YouTube →

At a glance

Andrej Karpathy had wanted to make this video for a while. The pitch is simple and the execution is not: three and a half hours, no math prerequisites, and nothing waved away, walking the entire pipeline that turns a crawl of the internet into the thing answering you inside the ChatGPT text box. His framing question is the one everybody actually has and nobody can answer. You can type anything in there and press enter. What should you be putting there, what are these words coming back, how does this work, and what exactly are you talking to?

He builds the answer in three sequential stages, and he keeps the receipts at every step. Pretraining is downloading and processing the internet, and he does it through FineWeb, the one dataset whose construction is documented in public: 44 terabytes on disk, 15 trillion tokens, filtered down from Common Crawl through URL blocklists, text extraction, a 65 percent English language classifier, deduplication and PII removal. Then tokenization, where text becomes a one dimensional sequence of 100,277 symbols and the model's blind spots are quietly created. Then the training loop itself, watched live on a rented 8x H100 node at $3 per GPU per hour, one million tokens per update, seven seconds per update, 32,000 steps. What comes out is a base model, which he is emphatic is not an assistant. It is an internet document simulator, a lossy zip file of the web, and he spends sixteen minutes playing with Llama 3.1 405B base to prove it: it reciting the zebra Wikipedia article from memory, it inventing two different parallel universes for the 2024 election, it becoming a passable assistant from nothing but a cleverly written prompt.

Supervised finetuning is where the personality arrives, and his reframing of it is the single most quoted idea in the video. You throw out the internet documents, substitute a dataset of conversations written by hired human labelers following a labeling instruction document that runs to hundreds of pages, and continue training with the exact same algorithm for about three hours. What you get is an imitation. "You're not talking to a magical AI," he says. "You're talking to an average labeler." Then reinforcement learning, the third stage, the one that is still early and not yet standard in the field, where the model stops imitating our solutions and goes looking for its own.

In between, the part people quote him for: LLM psychology. Why hallucinations are the default behavior of a system trained to imitate confident answers, and the two mitigations that actually work. Why the parameters are a vague recollection and the context window is working memory. Why models need tokens to think, and why a correct answer delivered too fast is a worse answer. Why they cannot count dots or spell ubiquitous backwards. Why 9.11 looks bigger than 9.9 to a network whose Bible verse neurons just lit up. The Swiss cheese model of capability, where the holes are real and arbitrary and you do not want to trip over them. And finally the practical close: where to keep track, where to find the models, how to run them yourself, and the one piece of advice he repeats at both the beginning and the end. Use them as tools in a toolbox, check their work, own the product of your work.

The question behind the text box (0:00:00)

He opens on the ChatGPT interface, cursor blinking, and names what he is after: mental models for thinking through what this tool is. It is obviously magical and amazing in some respects, really good at some things and not very good at others, and there are a lot of sharp edges to be aware of. The plan is the entire pipeline of how the stuff is built, kept accessible to a general audience, with the cognitive and psychological implications of the tools threaded through as they come up.

So let's build ChatGPT.

Stage one: pretraining

Downloading and processing the internet (0:01:00)

The first step of the first stage is to download and process the internet. To get a sense of what that looks like he points at FineWeb, a dataset collected, created and curated by Hugging Face, who went into a lot of detail in a blog post on how they constructed it. Every major provider, OpenAI, Anthropic, Google and the rest, will have some internal equivalent. FineWeb is the one you can actually read about.

The goal: a huge quantity of very high quality documents, and very large diversity of documents, because diversity is where the knowledge comes from. Large diversity of high quality documents, and many many of them. Achieving that is quite complicated and takes multiple stages to do well.

The number he wants you to sit with first is how small the result is. FineWeb, which he calls fairly representative of what you would see in a production grade application, ends up being about 44 terabytes of disk space. You can get a USB stick for a terabyte very easily. This could almost fit on a single hard drive today. The internet is very very large, but we are working with text, and we are filtering it aggressively.

The starting point, and the thing that contributes most of the data by the end, is Common Crawl. Common Crawl is an organization that has basically been scouring the internet since 2007, and as of 2024 it had indexed 2.7 billion web pages. The mechanism is unglamorous: start with a few seed web pages, follow all the links, keep following links, keep indexing all the information, and over time you end up with a ton of data of the internet.

That raw crawl is then filtered in many many different ways, and he walks the FineWeb diagram stage by stage:

Then he clicks into the finished dataset, which anyone can download from the Hugging Face page, and reads two of the actual surviving documents out loud, because the substance of the model's world is worth looking at directly. One is an article about tornadoes in 2012. The other opens with "did you know you have two little yellow 9 volt battery sized adrenal glands in your body," which he calls some kind of odd medical article. Just think of these as web pages on the internet, filtered for the text in various ways.

To build intuition about scale, he takes the first 200 web pages, concatenates all the text together, and zooms out. You get raw internet text, a ton of it even in 200 pages, a massive tapestry of text data. That text data has all these patterns, and what we want to do now is train neural networks on it so they can internalize and model how this text flows. We have this giant texture of text and we want neural nets that mimic it.

Tokenization: bits, bytes, and byte pair encoding (0:07:47)

Before text goes into a neural network we have to decide how to represent it. The technology expects a one dimensional sequence of symbols from a finite set of possible symbols. So we have to decide what the symbols are, and then represent our data as a one dimensional sequence of those symbols.

What we have is already one dimensional. The text starts here and goes to there; on a monitor it is laid out in two dimensions but it reads left to right, top to bottom. And being computers, there is an underlying representation. UTF-8 encode the text and you get the raw bits, which he displays as a long bar of ones and zeros where the very first segment is the first eight bits.

So in a sense we already have what we were looking for: exactly two possible symbols, zero and one, and a very long sequence of them. The problem is the tradeoff. Sequence length is a very finite and precious resource in a neural network. We do not want extremely long sequences of just two symbols. We want to trade off the symbol size of the vocabulary against the resulting sequence length, and land somewhere with more symbols and shorter sequences.

The naive first move: take groups of eight consecutive bits and call each group a byte. Since each bit is on or off, there turn out to be only 256 possible combinations, so the sequence becomes eight times shorter at the cost of 256 possible symbols. Every number now runs 0 to 255, and he insists you not think of these as numbers. Think of them as unique IDs, unique symbols. He replaces each one with a distinct emoji on screen to make the point stick: we now have a sequence of emojis, and there are 256 possible emojis.

In production for state of the art language models you go further, because you want to keep shrinking the sequence in return for more symbols in the vocabulary, and the way that is done is the byte pair encoding algorithm. Look for consecutive bytes or symbols that are very common. It turns out, in his example, that the sequence 116 followed by 32 is quite common and occurs very frequently. So group that pair into a new symbol, mint a symbol with ID 256, and rewrite every single 116 32 pair with the new symbol. Then iterate as many times as you wish. Each time you mint a new symbol you decrease the length and increase the symbol size.

In practice a pretty good setting of the vocabulary size turns out to be about 100,000 possible symbols, and in particular GPT-4 uses 100,277 symbols. The process of converting raw text into these symbols, which we call tokens, is tokenization.

VOCABULARY SIZE SEQUENCE LENGTH 2 symbols 0 and 1, raw UTF-8 bits 256 symbols one byte = 8 bits 100,277 symbols GPT-4, after BPE group 8 bits into a byte sequence gets 8x shorter byte pair encoding: mint a new symbol for the most common adjacent pair. 116 + 32 is common, so it becomes ID 256. Iterate as many times as you wish. longest 8x shorter shortest 15T tokens for FineWeb ONE CONCRETE STRING hello 15339 ␣world 1917 Two tokens, not two words. The space belongs to the token.
Figure 1. The whole of tokenization is one tradeoff, run with real numbers. You buy a shorter sequence by paying in vocabulary size, because sequence length is the precious resource. Byte pair encoding is how you pay: find the commonest adjacent pair, mint it a symbol, repeat. GPT-4 stops at 100,277. The bottom row is the string Karpathy types first into TikTokenizer, and it is where every spelling and counting failure later in the video comes from.

He then goes to TikTokenizer, his preferred website for exploring token representations, picks cl100k_base from the dropdown (the GPT-4 base model tokenizer), and types into the left pane.

He encourages you to play with it and build an intuitive sense of how tokens work, and he promises to loop back around to tokenization later in the video. He does, twice, and both times it is to explain a failure.

One last demonstration: he takes a single line of the FineWeb text and shows what GPT-4 will see it as. A sequence of length 62. The chunks of text correspond to these symbols, there are 100,277 possible symbols, and we now have one dimensional sequences of them.

Re-representing the whole dataset this way is what gives the headline number. FineWeb is not just 44 terabytes of disk space, it is about a 15 trillion token sequence. He shows the first few thousand tokens on screen and asks you to keep in mind that there are 15 trillion of them, and that all of these represent little text chunks, atoms of these sequences, and the numbers do not make any sense because they are just unique IDs.

What goes into the network, and what comes out (0:14:27)

Now the fun part, and the part where the heavy lifting happens computationally. What we want to model is the statistical relationships of how these tokens follow each other in the sequence.

So we come into the data and take windows of tokens, fairly randomly. The window length can range anywhere from zero tokens all the way up to some maximum size we decide on. In practice you could see windows of say 8,000 tokens. In principle arbitrary window lengths are possible, but processing very long windows gets very computationally expensive, so we decide that 8,000 is a good number, or 4,000, or 16,000, and we crop it there.

For his worked example he takes the first four tokens so everything fits nicely on screen. The four tokens spell out something like "bar view in and single" in the FineWeb text, and the real token that comes next in the sequence is 3962, which is the token post.

Those four tokens are the context. They feed into the neural network, and that is the input. The output is a prediction for what comes next. Because our vocabulary has 100,277 possible tokens, the network outputs exactly that many numbers, and all of those numbers are the probability of that token coming next in the sequence. It is making guesses about what comes next.

In the beginning the network is randomly initialized, so it is a random transformation and the probabilities at the start of training are also random. On his screen three of the hundred thousand are visible: the token Direction is at 4 percent, token 11799 is at 2 percent, and token 3962, post, which is the one that actually came next, is at 3 percent.

But we sampled this window out of our dataset, so we know the answer. 3962 is the label. And now we have a mathematical process for doing an update: we know we want the probability of 3 percent to be higher and the probabilities of all the other tokens to be lower, and we have a way of mathematically calculating how to adjust and update the network so that the correct answer gets a slightly higher probability.

After one update, feed the same four tokens in again and post is maybe 4 percent, case is maybe 1 percent, Direction has come down to 2 percent. We have a way of nudging the net to give a higher probability to the correct next token.

And then the crucial scaling point. This does not happen just for this one window. It happens at the same time for all of the tokens in the entire dataset. In practice we sample little batches of windows, and at every single one of those tokens we want to adjust the network so the probability of the correct token becomes slightly higher, all in parallel in large batches. That is the process of training: a sequence of updates so that the network's predictions match up with the statistics of what actually happens in your training set, and its probabilities become consistent with the statistical patterns of how these tokens follow each other.

Inside the network (0:20:11)

A brief look at the internals, just to give you a sense of what is in there.

The inputs are sequences of tokens, four in his example, anywhere from zero up to say 8,000 in practice. In principle this could be an infinite number of tokens; it would just be too computationally expensive, so we crop at a certain length and that becomes the maximum context length of the model.

Those inputs X get mixed up in a giant mathematical expression together with the parameters, or weights, of the network. He shows six example parameters with their settings. In practice modern networks have billions of them, and in the beginning they are completely randomly set. With a random setting of parameters you might expect random predictions, and that is exactly what you get at the start. It is through the process of iteratively updating the network, which is what we call training, that the parameters get adjusted so the outputs become consistent with the patterns seen in the training set.

His analogy: think of the parameters as knobs on a DJ set. As you twiddle the knobs you get different predictions for every possible token sequence input, and training a neural network just means discovering a setting of knobs that seems to be consistent with the statistics of the training set.

Then he shows what the giant mathematical expression actually looks like, to demystify it. Modern networks are massive expressions with probably trillions of terms, but the simple example on screen is not very scary: inputs x1 and x2 get mixed with the weights w0, w1, w2, w3 and so on, and the mixing is simple things like multiplication, addition, exponentiation and division. Designing effective expressions with convenient characteristics, expressive, optimizable, parallelizable, is the subject of neural network architecture research. But at the end of the day these are not complex expressions. They mix up the inputs with the parameters to make predictions, and we optimize the parameters so the predictions come out consistent with the training set.

For a production grade example he sends you to Brendan Bycroft's LLM visualization, where the network used in production settings has a special kind of structure. This network is called the Transformer, and this particular one has roughly 85,000 parameters.

Information flows top to bottom. The token sequences come in at the top, flow through, and come out at the bottom as the logits and softmax, which are the predictions for what token comes next. In between is a sequence of transformations and all the intermediate values the expression produces.

The intermediate numbers you can almost think of as the firing rates of these synthetic neurons, and here he inserts a careful caution. Do not think of it too much like neurons. These are extremely simple neurons compared to the ones in your brain. Your biological neurons are very complex dynamical processes that have memory. There is no memory in this expression. It is a fixed mathematical expression from input to output with no memory. It is stateless. You can still loosely think of it as a synthetic piece of brain tissue if you like to think about it that way.

He deliberately does not dwell on the precise mathematical details of all these transformations, saying honestly that he does not think it is that important. What is really important to understand is that this is a mathematical function, parameterized by a fixed set of parameters, say 85,000 of them, that transforms inputs into outputs, and as we twiddle the parameters we get different kinds of predictions, and we need to find a good setting so the predictions match the patterns in the training set. That is the Transformer.

Inference: flipping biased coins (0:26:01)

Training is one stage. The other major stage of working with these networks is inference, where we generate new data from the model to see what patterns it has internalized.

Generating is relatively straightforward. Start with some prefix tokens, whatever you want to start with. Say we start with token 91. Feed it in, and remember that the network gives us probabilities, a probability vector over the whole vocabulary. Now flip a biased coin: sample a token from that probability distribution, so tokens the model gives high probability to are more likely to be sampled.

That last divergence is the whole point. These systems are stochastic. We are sampling, we are flipping coins, and sometimes we luck out and reproduce a small chunk of the text in the training set, but sometimes we get a token that was not verbatim part of any document in the training data. So we get remixes of the data we saw in training. Once a different token makes it in and you sample the next one from there, you very quickly start to generate token streams that are very different from the streams in the training documents. Statistically they will have similar properties, but they are not identical to your training data. They are kind of inspired by it.

Why article specifically? You might imagine that article is a relatively likely token in the context of "bar viewing single," and that the word followed that context window somewhere in the training documents to some extent, and we just happened to sample it here.

So inference is just predicting from these distributions one at a time, continuing to feed back tokens and get the next one, always flipping these coins, and depending on how lucky or unlucky you get you might land on very different kinds of patterns.

The practical division of labor follows from this. Downloading the internet and tokenizing it is a preprocessing step you do a single time. Then you start training networks, and in practical cases you would try to train many different networks of different settings, arrangements and sizes, so you do a lot of training. Then once you have a network you are happy with, you take the model and you do inference.

Which is what you are doing when you are talking to ChatGPT. That model was trained by OpenAI probably many months ago, they have a specific set of weights that work well, and when you are talking to the model all of that is just inference. There is no more training. Those parameters are held fixed and you are giving it some tokens and it is completing token sequences, and that is what you see generated.

GPT-2: what training actually looks and feels like (0:31:09)

For a concrete example of training and inference he picks the one he is particularly fond of: OpenAI's GPT-2. GPT stands for generatively pretrained Transformer, and this is the second iteration of the series. When you talk to ChatGPT today the model underlying all of the magic of that interaction is GPT-4, the fourth iteration.

GPT-2 was published in 2019 in this paper, and the reason he likes it is that it is the first time that a recognizably modern stack came together. All the pieces of GPT-2 are recognizable today by modern standards. Everything has just gotten bigger.

The details he pulls out:

He then mentions that he reproduced GPT-2 for fun as part of llm.c, and points at his writeup of the run on GitHub. The economics are the striking part:

Two reasons the costs collapsed. Number one, the datasets have gotten a lot better, and the way we filter them, extract them and prepare them has gotten a lot more refined, so the data is of just a lot higher quality. But really the biggest difference is that our computers have gotten much faster in terms of the hardware, and the software for running these models and squeezing out all the speed the hardware can give has also gotten much better, as everyone has focused on these models and tried to run them very very quickly.

Then he does something most explainers skip: he slides a live training run onto the screen so you can see what this actually looks and feels like as a researcher.

And every 20 steps he has configured the optimization to do inference, so you can watch the model's output get better in real time. At 1 percent through training it is not yet very coherent, but it already has a little bit of local coherence. He reads the sample out loud, gibberish with the shape of English:

since she is mine it's a part of the information should discuss my father great companions Gordon showed me sitting over at

Then he scrolls up to step one, 20 updates in, where the output is completely random, because the model has had 20 updates to its parameters and is still essentially a random network. Set those side by side and the 1 percent sample looks like real progress. If you waited the entire 32,000 steps the model would be generating fairly coherent English with the token stream running correctly. That run needs about a day or two more. At this stage you just make sure the loss is decreasing, everything is looking good, and you wait.

The compute, the gold rush, and what the data centers are actually doing

He is not running this on his laptop. That would be way too expensive, and the network is just too large. All of it runs on a computer out there in the cloud, and he shows you which one.

This is where he names the economics out loud. All the big tech companies really desire these GPUs so they can train these language models, because the models are so powerful, and that is fundamentally what has driven the stock price of Nvidia to $3.4 trillion. This is the gold rush: getting the GPUs, getting enough of them so they can all collaborate to perform this optimization.

And what are they all collaborating on? Predicting the next token on a dataset like FineWeb. That is the computational workload that is extremely expensive. The more GPUs you have, the more tokens you can try to predict and improve on, the faster you process the dataset, the faster you iterate, the bigger a network you can train. He points at a news article from about a month before filming about Elon Musk getting 100,000 GPUs in a single data center, all of them extremely expensive, all of them taking a ton of power, and all of them just trying to predict the next token in the sequence and improve the network by doing so, probably getting a lot more coherent text than his run a lot faster.

Llama 3.1 base: playing with an internet document simulator (0:42:52)

He does not have a couple of ten or hundred million dollars to spend on a really big model, but luckily we can turn to the big tech companies who train these models routinely and release some of them when they are done. They spend a huge amount of compute, and then they release the network at the end of the optimization, which is very useful.

But not many of them release base models, and the distinction matters enormously here.

What is a base model? The model that comes out at the end of pretraining. It is a token simulator. An internet text token simulator. And it is not by itself useful yet, because what we want is an assistant. We want to ask questions and have it respond with answers, and these models will not do that. They just create remixes of the internet. They dream internet pages. So base models are not very often released, because they are only step one of a few other steps still needed to get to an assistant.

A few releases have been made, though. GPT-2 released its 1.6 billion (he corrects himself on camera: 1.5 billion) parameter model back in 2019, and that is a base model.

What does it actually mean to release a model? Two things:

  1. The code. Usually Python, describing in detail the sequence of operations the model makes. The sequence of steps taken in the Transformer, which is the forward pass of the neural network. This is just computer code, usually just a couple hundred lines of it, not that crazy, fairly understandable and usually fairly standard. He shows the GPT-2 repository on GitHub for this.
  2. The parameters. What is not standard, and where the actual value is. For GPT-2 that is roughly 1.5 billion numbers. One single list of 1.5 billion numbers, the precise and good setting of all the knobs such that the tokens come out well.

For something more modern he turns to Llama 3, released and trained by Meta, documented in a detailed paper. Where GPT-2 was 1.6 billion parameters on 100 billion tokens, Llama 3 is 405 billion parameters trained on 15 trillion tokens, in very much the same way, just much much bigger. The biggest base model they released is Llama 3.1 405B base. He notes in passing, as foreshadowing for the next section of the video, that they also released the instruct model, where instruct means it is an assistant you can ask questions and get answers from.

His favorite place to interact with base models is Hyperbolic, which serves Llama 3.1 405B base. You register, you make sure you have selected the base model and not the instruct one, and he sets max tokens down to 128 so as not to waste compute. Fundamentally what happens here is identical to the inference loop he just walked through: it continues the token sequence of whatever prefix you give it.

Demo one: this is not an assistant. He types what is 2 plus 2. It does not say "oh, it's four, what else can I help you with," because the question gets tokenized and those tokens just act as a prefix, and the model gets the probability for the next token. It is a glorified autocomplete. A very very expensive autocomplete, continuing according to the statistics of what it saw in its training documents, which are basically web pages. He hits enter and it actually does answer the question, then wanders off into philosophical territory. He copies and pastes the same prompt again and it goes off somewhere else entirely. Two things proven in one demo: it is not an assistant yet, and it is a stochastic system. The same prefix gives a different answer every time, because we get a probability distribution and sample from it and always get different samples.

Demo two: the knowledge is in there. Even though the model is not useful by itself for a lot of applications yet, it is still very useful, because in the task of predicting the next token it has learned a lot about the world and stored all that knowledge in the parameters. The internet web pages are compressed into the weights. Think of 405 billion parameters as a kind of compression of the internet, a zip file, except it is not lossless compression, it is lossy compression. We are left with a gestalt of the internet, and we can generate from it.

To elicit that knowledge he primes it: Here's my top 10 list of the top landmarks to see in Paris:. The model starts a list and gives him landmarks, with a lot of information. And here he plants the seed of the hallucination section:

You might not be able to fully trust some of the information. This is all just a recollection of internet documents, so the things that occur very frequently in the internet data are probably more likely to be remembered correctly compared to things that happen very infrequently. He says plainly that he does not have the expertise to verify the list is roughly correct. The knowledge is not precise and exact. It is vague, probabilistic and statistical. The information is not stored explicitly in any of the parameters. It is all just recollection.

Demo three: regurgitation. He goes to the Wikipedia page for zebra, copies one sentence, pastes it in and hits enter. The model produces an exact regurgitation of the Wikipedia entry, reciting it purely from memory, memory that lives in its parameters. "There are three living species, etc etc." He checks a few sentences down the completion to see whether it has strayed yet: still on track. Still on track. It will eventually deviate across those 512 tokens because it will not be able to remember exactly, but it has huge chunks of it memorized.

Why does this happen? These models can be extremely good at memorization, and usually this is not what you want in the final model. This is regurgitation, and it is usually undesirable to cite things directly that you have trained on. The mechanism is in the data mix: for documents deemed to be of very high quality as a source, Wikipedia being the canonical example, you preferentially sample from those sources when you train, so the model has probably done a few epochs on this data, meaning it has seen the page maybe 10 times or so. It is like you reading a text a hundred times and then being able to recite it, except these models can be a lot more efficient per presentation than humans. Ten viewings and it has remembered the article exactly in its parameters.

Demo four: the knowledge cutoff, and hallucination in its purest form. He goes to the Llama 3 paper, navigates to the pretraining data section, and reads out that the dataset has a knowledge cutoff at the end of 2023. So the model has not seen documents after that point, and certainly has not seen anything about the 2024 election and how it turned out.

So he primes it with tokens from the future: The Republican Party ticket ... Trump ... president of the United States from 2017 .... The model has to guess at the running mate and who the ticket ran against.

Two different parallel universes from the same prompt. "All of what we're seeing here is what's called hallucination. The model is just taking its best guess in a probabilistic manner."

Demo five: in context learning. Even though this is a base model and not an assistant, it can still be used in practical applications if you are clever with your prompt design. He builds a few shot prompt: ten lines, each one an English word, a colon, and the Korean translation. Then an eleventh line, teacher:, and a completion of just five tokens.

These models have in context learning abilities. As it reads this context it is learning in place that there is some kind of algorithmic pattern going on in the data, and it knows to continue that pattern. It takes on the role of a translator, and the completion gives the correct Korean word for teacher. Nothing was trained for this. It emerged because continuing patterns is what next token prediction rewards. So you can build apps by being clever with your prompting even when all you have is a base model.

Demo six: an assistant made out of nothing but a prompt. There is a clever way to instantiate a whole language model assistant by prompting alone, and the trick is to structure the prompt to look like a web page that is a conversation between a helpful AI assistant and a human, and then let the model continue the conversation.

To write the prompt he turned to ChatGPT itself, which he calls kind of meta: he told it he wanted to create an LLM assistant but all he had was the base model, so could it please write his prompt. What it came up with is actually quite good. It opens "Here's a conversation between an AI assistant and a human. The AI assistant is knowledgeable, helpful, capable of answering a wide variety of questions," and then, crucially, it does not stop at a description. It works much better if you make it a few shot prompt, so there are several turns of human and assistant conversation laid out before the real query.

He pastes the whole thing into the base model, adds Human: and why is the sky blue, then Assistant: and runs it. Out comes "The sky appears blue due to the phenomenon called Rayleigh scattering, etc etc." The base model is just continuing the sequence, but because the sequence looks like a conversation it takes on the role. It is a little subtle: when it finishes the assistant turn it just hallucinates the next question from the human and keeps going on and on. But the task is accomplished. For contrast he refreshes and puts why is the sky blue in on its own, with no scaffolding, and of course it does not work. You just get more questions. Because that is what a page of questions looks like on the internet.

Pretraining to post-training (0:59:23)

He zooms out and summarizes the first stage. We wish to train LLM assistants like ChatGPT. We have now covered the pretraining stage, and what it comes down to is: take internet documents, break them up into tokens, these atoms of little text chunks, and predict token sequences using neural networks. The output of the entire stage is the base model, which is the setting of the parameters of the network, and that base model is an internet document simulator on the token level. It generates token sequences with the same kind of statistics as internet documents, and we saw it can be used in some applications.

But we need to do better. We want an assistant. We want to ask questions and have the model give us answers. So we hand the base model, the internet document simulator, off to post training.

The cost structure flips completely here, and this is worth holding onto. Pretraining in practice can take roughly three months of training on many thousands of computers. The post training stage will typically be much shorter, like three hours. All of the massive data centers, all of the heavy compute and millions of dollars, are the pretraining stage. Post training is slightly cheaper but still extremely important, and it is where the LLM becomes an assistant.

WHAT GOES IN 1. Pretraining 44 TB on disk, 15T tokens filtered Common Crawl text ~3 months, 1000s of computers objective: predict next token 2. Supervised finetuning 100k to millions of conversations hired labelers + 100s of pages ~3 hours, same algorithm objective: imitate the labeler 3. Reinforcement learning practice problems, answer known solution path NOT given 1000s of attempts per prompt objective: get the answer right WHAT COMES OUT base model an internet document simulator lossy zip file of the web assistant helpful, truthful, harmless a simulation of a labeler reasoning model chains of thought, emergent finds paths we never taught it THE TEXTBOOK ANALOGY read the exposition build a knowledge base study the worked solutions imitate the human expert do the practice problems find a path that works for you
Figure 2. The spine of the whole video. Each stage is smaller, more curated and cheaper than the one before it, and each buys a different thing: knowledge, then manners, then problem solving. The row along the bottom is the analogy Karpathy returns to at 2:07:28 to motivate reinforcement learning, which is that we train LLMs almost exactly the way we train children, except we now have to write the textbooks.

Stage two: supervised finetuning

Post training data: conversations (1:01:06)

What we want now is not to sample internet documents but to give answers to questions. So we start thinking about conversations, which can be multi turn, in the simplest case between a human and an assistant. He puts three examples on screen:

So we want to think through how an assistant should interact with a human, and we want to program the assistant and its behavior in these conversations. But because this is neural networks we are not going to be programming these explicitly in code. Everything is done through neural network training on datasets. So we are going to be implicitly programming the assistant by creating datasets of conversations.

An actual dataset could have hundreds of thousands of conversations that are multi turn and very long and cover a diverse breadth of topics. He shows three. The assistant is being programmed by example.

And then the question that drives the whole section: where does this data come from? It comes from human labelers. We give human labelers some conversational context and ask them to give the ideal assistant response in that situation. A human writes out the ideal response for an assistant in any situation, and then we get the model to train on this and imitate those kinds of responses.

The mechanics are almost anticlimactic. Take the base model from pretraining. Throw out the dataset of internet documents. Substitute the dataset of conversations. Continue training the model on the new data. The model very rapidly adjusts and learns the statistics of how this assistant responds to human queries, and later during inference we can prime the assistant and get a response, and it will be imitating what the human labelers would do in that situation. We are using the exact same algorithm, the exact same everything, except we are swapping out the dataset.

How a conversation becomes a token sequence

Everything in these models has to be turned into tokens, so how do we turn conversations into token sequences? We need to design an encoding, and he reaches for a good analogy: this is kind of similar to the TCP/IP packet on the internet. There are precise rules and protocols for how you represent information and how everything is structured together, laid out in a way that is written out on paper and that everyone can agree on. The same thing is now happening in LLMs. We need data structures and rules around how conversations get encoded and decoded to and from tokens.

So he goes back to TikTokenizer and pastes in the two turn conversation. It looks ugly but it is actually relatively simple, and the whole user and assistant exchange ends up being 49 tokens. A one dimensional sequence of 49 tokens, and these are the tokens.

All the different LLMs have a slightly different format or protocol, and it is a little bit of a wild west right now, but GPT-4o does it as follows:

The important thing to mention, and the detail that is easy to miss: <|im_start|> is not text. It is a special token that gets added, a new token, and it has never been trained on so far. It is a new token that we create in the post training stage. These special tokens get introduced and interspersed with text so that the model learns that this is the start of a turn, and whose turn it is, and this is what the user says, and then the user ends, and now it is a new start of a turn and it is the assistant's, and these are the tokens of what the assistant says.

The specific details are not what matters. What matters is that conversations, which we think of as a structured object, end up being turned via some encoding into one dimensional sequences of tokens, and because it is a one dimensional sequence of tokens we can apply all the stuff that we applied before. We are just predicting the next token in a sequence, just like before.

At inference, when you are on ChatGPT and you have a dialogue, what happens on the servers is that your new turn gets appended, then they put in <|im_start|>assistant<|im_sep|> and end it right there. They construct that context and start sampling from the model. That is the stage where the model is asked what is a good first token, a good second token, a good third token, and the LLM takes over and creates a response. It will not be identical to anything in the dataset, but it will have the flavor of the kind of conversation that was in the dataset.

InstructGPT, and the labeling instructions nobody reads

The first paper in this direction, and the first time OpenAI talked publicly about how you take language models and finetune them on conversations, is the 2022 InstructGPT paper. He takes you through it.

Stop one is section 3.4, where they describe the human contractors they hired, in this case from Upwork or through Scale AI, to construct these conversations. There are human labelers involved whose job it is professionally to create these conversations, and they are asked to come up with the prompts and then also to complete the ideal assistant responses.

The real prompts the labelers came up with, from the paper:

Stop two is the excerpt of labeling instructions, and this is the part of the video that reframes everything downstream. The company developing the language model writes up labeling instructions for how the humans should create ideal responses. The excerpt on screen, at a high level, is asking people to be helpful, truthful and harmless, and not to answer questions the company does not want the system to handle later in ChatGPT.

He pauses on the scale of this document, because the excerpt is misleadingly short. "Usually they are not this short. Usually there are hundreds of pages, and people have to study them professionally." Then they write out the ideal assistant responses following those instructions. This is a very human heavy process as described in the paper.

The InstructGPT dataset was never actually released by OpenAI. But there are open source reproductions trying to follow the same setup and collect their own data, and the one he is familiar with is OpenAssistant, one of what he thinks are many examples. These were people on the internet asked to create conversations similar to what OpenAI did with human labelers. He reads an actual entry: someone wrote the prompt "can you write a short introduction to the relevance of the term monopsony in economics, please use examples," and then the same person or potentially a different person wrote out the ideal assistant response. Then the conversation continues with "now explain it to a dog," and a simpler explanation follows.

That becomes the label, and we train on it. And here is the thing that makes the whole approach work, because of course we cannot possibly cover all the prompts people will ask in the future. If you have a dataset of a few of these examples, the model during training starts to take on this persona of the helpful truthful harmless assistant, and it is all programmed by example. These are all examples of behavior, and if you have enough of them, like 100,000, and you train on it, the model starts to understand the statistical pattern and takes on this personality.

At test time, if you ask the exact same question that was in the training set, the answer may be recited as exactly what was in there. But more likely the model will do something of a similar vibe, having understood that this is the kind of answer that you want.

How the data is actually made now: UltraChat and SFT mixtures

He is careful to say the state of the art has advanced in the two or three years since InstructGPT. It is not very common for humans to be doing all the heavy lifting just by themselves anymore, because we now have language models, and those language models are helping us create these datasets. It is very rare that people will literally just write out the response from scratch. It is a lot more likely they will use an existing LLM to come up with an answer and then edit it. LLMs have started to permeate this post training stack and are used pervasively to help create these massive datasets of conversations.

UltraChat is his example of a more modern conversation dataset. It is to a very large extent synthetic, though he believes there is some human involvement and is careful to say he could be wrong about the exact mix. Usually there will be a little bit of human and a huge amount of synthetic help. The numbers have moved: these datasets now have millions of conversations, mostly synthetic, probably edited to some extent by humans, spanning a huge diversity of areas. These are fairly extensive artifacts by now, and there are SFT mixtures, mixtures of lots of different types and sources, partially synthetic and partially human.

But roughly speaking, nothing structural has changed. We still have SFT datasets, they are made up of conversations, and we are training on them just like we did before.

"You're talking to an average labeler" (1:17:02)

This is the reframing the video is most quoted for, and he builds it carefully.

He wants to dispel a little bit of the magic of talking to an AI. When you go to ChatGPT and give it a question and hit enter, what comes back is statistically aligned with what is happening in the training set, and those training sets really just have a seed in humans following labeling instructions.

So what are you actually talking to?

"It's not coming from some magical AI. Roughly speaking, it's coming from something that is statistically imitating human labelers, which comes from labeling instructions written by these companies."

The way to hold it in your head: imagine the answer given to you from ChatGPT is a simulation of a human labeler. It is like asking what would a human labeler say in this kind of a conversation. And this human labeler is not just a random person from the internet, because these companies actually hire experts. When you are asking questions about code, the labelers involved in creating those conversation datasets will usually be educated expert people, and you are asking a question of a simulation of those people.

"You're not talking to a magical AI, you're talking to an average labeler. This average labeler is probably fairly highly skilled, but you're talking to kind of like an instantaneous simulation of that kind of a person that would be hired in the construction of these datasets."

Then one more specific example to land it. He asks ChatGPT to recommend the top five landmarks to see in Paris and hits enter. What is coming out? It is not some kind of magical AI that has gone out and researched all the landmarks and then ranked them using its infinite intelligence. It is a statistical simulation of a labeler hired by OpenAI.

Two cases follow, and the second is the interesting one:

StageData it trains onWho produces the labelWhat it costsWhat it buys
Pretraining44 TB of filtered web text, 15 trillion tokens (FineWeb scale)Nobody. The label is simply the token that actually came nextRoughly 3 months on many thousands of computers, millions of dollarsKnowledge, and a base model that simulates internet documents
Supervised finetuningConversations. Hundreds of thousands to millions of them, now largely synthetic and human editedHired human labelers writing the ideal response, following an instruction document that runs to hundreds of pagesRoughly 3 hours. Same algorithm, same everything, different datasetAn assistant, which is an imitation of a labeler
RL, verifiable domainsPractice problems where the final answer is known but the solution path is notNobody writes the path. The model generates thousands of attempts and keeps what reached the answerCan run for tens or hundreds of thousands of stepsThinking. Emergent chains of thought, and strategies no human taught it
RLHF, unverifiable domainsCreative prompts. Jokes, poems, summaries, with human orderings of five rollouts eachA separate reward model, trained to imitate human orderings, standing in for a humanA few hundred to a thousand updates, then you crop it and shipA small improvement. Gameable, so not RL in the magical sense

LLM psychology

He names this section himself. What are the emergent cognitive effects of the training pipeline that we have for these models? Everything in this part of the video follows from the mechanics he has just built up, which is what makes it convincing rather than anecdotal.

Where hallucinations come from (1:20:32)

You are probably familiar with model hallucinations. It is when LLMs make stuff up, totally fabricate information. It is a big problem with LLM assistants, it existed to a large extent with early models from many years ago, and the problem has gotten a bit better because of mitigations he is about to go into. But first, where do they come from?

He puts three perfectly reasonable training conversations on screen:

Now notice what the human writing those answers did. The human either knows who this person is, or they researched them on the internet, and then they wrote a response with the confident tone of an answer. Three for three.

So at test time he asks about Orson Kovats, a name he made up at random and does not think belongs to a real person.

Here is the trap. The assistant will not just tell you it does not know, even if the language model itself might know inside its features, inside its activations, inside its brain sort of. Some part of the network may well represent that this is not someone it is familiar with. But saying "I don't know who this is" is not going to happen, because the model statistically imitates its training set, and in the training set questions of the form "who is X" are confidently answered with the correct answer. So it takes on the style of the answer, does its best, gives you statistically the most likely guess, and basically makes stuff up. These models do not have access to the internet, they are not doing research, they are statistical token tumblers trying to sample the next token in the sequence.

To demonstrate, he opens the Hugging Face inference playground and on purpose picks on Falcon 7B Instruct, an older model from a few years back that suffers from hallucinations more visibly. "Who is Orson Kovats?"

The model does not know, so it gives lots of different answers. It starts with the tokens "who is Orson Kovats, assistant," gets probabilities, and samples from them, and the stuff it comes up with is statistically consistent with the style of the answer in its training set. You and I experience that as made up factual knowledge. The model is just imitating the format of the answer, and it is not going to go off and look it up.

For contrast he asks the same question of the state of the art ChatGPT, which is smarter in a specific way: he briefly sees "searching the web" flash on screen, which is tool use and which the video covers next. So he asks again with "don't use any tools", and gets back that there is no well known historical or public figure named Orson Kovats. This model knows that it does not know, and it tells you. So hallucinations have somehow improved even though they are clearly an issue in older models.

Mitigation one: teach the model what its own ignorance feels like

Clearly we need examples in the dataset where the correct answer for the assistant is that the model does not know about some particular fact. But we only need those answers to be produced in the cases where the model actually does not know. So the question becomes: how do we know what the model knows or does not know?

We can empirically probe the model to figure that out. And he walks through exactly how Meta did it for Llama 3, in the section of their paper they call factuality. The procedure interrogates the model to find the boundary of its knowledge, and then adds examples to the training set where, for the things the model does not know, the correct answer is that it does not know. He flags up front that this sounds like a very easy thing to do in principle, and roughly fixes the issue.

Why it works is the interesting part, and it follows from the network internals he showed earlier. The model might actually have a pretty good model of its self knowledge inside the network. You might imagine there is a neuron somewhere that lights up when the model is uncertain. The problem is that the activation of that neuron is not currently wired up to the model actually saying in words that it does not know. So even though the internals know, because some neurons represent it, the model will not surface that. It will instead take its best guess so that it sounds confident, just like it sees in its training set. So we need to interrogate the model and allow it to say "I don't know" in the cases where it does not know.

The procedure, step by step, with his live demo:

  1. Take a random document from the training set and take a paragraph. He picks Dominik Hašek, the Wikipedia featured article of the day, at random.
  2. Use an LLM to construct questions about that paragraph. He does it in ChatGPT: "here's a paragraph from this document, generate three specific factual questions based on this paragraph and give me the questions and the answers." LLMs are already good enough to reframe this information, and crucially, because the information is in the context window it does not have to rely on its memory, so it works pretty well with fairly high accuracy. He gets questions like "which team did he play for" and "how many cups did he win," with answers.
  3. Interrogate the model with those questions. He uses Mistral 7B as his stand in for the model being probed. First question: which team? The model says the Buffalo Sabres, which is right. So the model knows.
  4. Compare the model's answer with the correct answer programmatically. Models are good enough to do this automatically, so there are no humans involved here. You take the answer from the model and use another LLM as a judge to check whether it is correct.
  5. Repeat a few times, because one sample is noise. He asks three times and gets Buffalo Sabres, Buffalo Sabres, Buffalo Sabres. The model knows, so everything is great.
  6. Now the second question: how many Stanley Cups did he win? The correct answer is two. The model claims four, which does not match. Resample: it makes something up again. Resample: it says he did not win during his career. Three for three wrong, so the model does not know, and it is making stuff up.
  7. Create a new conversation in the training set. When the question is "how many Stanley Cups did he win," the answer is "I'm sorry, I don't know" or "I don't remember." And that is the correct answer for this question, because we interrogated the model and we saw that that is the case.

Do this for many different types of questions across many different types of documents and you are giving the model an opportunity, in its training set, to refuse based on its knowledge. With just a few examples the model gets the chance to learn the association between knowledge based refusal and that internal neuron of uncertainty somewhere in its network that we presume exists. Empirically this turns out to be probably the case. It can learn that when the uncertainty neuron is high, it actually does not know and it is allowed to say so. If you have those examples in your training set, this is a large mitigation for hallucination, and that is roughly why ChatGPT is able to do what it did on Orson Kovats.

Mitigation two: tools, and the search tokens

We can do much better than saying we do not know. We can give the LLM an opportunity to be factual and actually answer the question.

What do you and I do when asked a factual question we do not know? We go off and search, use the internet, figure out the answer. We can do the exact same thing with these models, and the reason the analogy holds is the distinction that becomes the most useful mental model in the whole video:

"Knowledge in the parameters of the neural network is a vague recollection. The knowledge in the tokens that make up the context window is the working memory."

Think of the knowledge inside the billions of parameters as something you read a month ago. If you keep reading something you will remember it, and the model remembers that, but if it is something rare you probably do not have a really good recollection. What you and I do is look it up, and when you look something up you are refreshing your working memory with the information so you can retrieve it and talk about it.

So we need an equivalent mechanism for the model, and we build it out of new tokens. He introduces two and a protocol for using them:

And then the mechanism outside the model takes over. The program that is sampling from the model, running the inference, sees the special end token and instead of sampling the next token it pauses generating. It goes off, opens a session with Bing, pastes the search query in, gets all the text that is retrieved, maybe re-represents it with some other special tokens, and copy pastes that text straight into the context window.

Now that text from the web search is inside the context window. It feeds into the neural network. It is not a vague recollection anymore. It is data the model has in its context window, directly available. So as it samples the new tokens afterwards it can reference very easily the data that was pasted in.

How do you teach the model to use the tool correctly? The same way you teach it everything else: training sets. You need a bunch of conversations that show the model by example how to use web search, what the settings are where you use it, what that looks like, how you start a search. With a few thousand examples of that in your training set the model does a pretty good job, and it knows how to structure its queries. And because of the pretraining dataset and its understanding of the world, it kind of understands what a web search is and has a pretty good native understanding of what makes a good search query. So it all just works, and you only need a little bit of a few examples to show it how to use the new tool.

This is exactly what he saw happen earlier with Orson Kovats: the ChatGPT language model decided this is some kind of rare individual, and instead of giving him an answer from its memory it sampled a special token that does a web search. The little flash of "using the web tool," then two seconds of waiting, then the response, and crucially the response creates references and cites sources. The URLs and the text of those web pages were all stuffed invisibly between the search tokens, and the model is reading that text and citing it.

He runs the control experiment as well. Asked "how many Stanley Cups did Dominik Hašek win," ChatGPT decided that it knows the answer and had the confidence to say he won twice, relying on its memory, presumably because it has enough confidence in its weights and activations that this is retrievable. Then he asks the same query with web search on, and it goes off, finds a bunch of sources, everything gets pasted in, and it cites the Wikipedia article that is the source of the information for us as well.

So: tools are the second mitigation for hallucinations and factuality, and the model determines when to search.

The practical consequence: put it in the context window

He stresses the psychology point one more time, because it changes how you should prompt. The stuff we remember is our parameters. The stuff we just experienced a few seconds or minutes ago is our context window, and that context window is being built up as you have a conscious experience around you.

The practical implication, demonstrated live:

Why the second is better: when it is in the context window the model has direct access to it. It does not have to recall it. So the summary can be expected to be significantly higher quality. And he closes the analogy honestly: you and I would work the same way. You would produce a much better summary if you had reread the chapter before you had to summarize it.

Knowledge of self (1:41:46)

The next psychological quirk is one he sees on the internet constantly. People ask LLMs "what model are you" and "who built you," and the question is a little bit nonsensical.

Why it is nonsensical follows from the fundamentals. This thing is not a person. It does not have a persistent existence in any way. It boots up, processes tokens, and shuts off, and it does that for every single person. It builds up a context window of conversation and then everything gets deleted. This entity is restarted from scratch every single conversation. It has no persistent self, it has no sense of self. It is a token tumbler, and it follows the statistical regularities of its training set.

So by default, if you ask, you get pretty random answers. He picks on Falcon again, which first evades the question with "talented engineers and developers," then says "I was built by OpenAI based on the GPT-3 model." Totally making stuff up.

And here he makes a correction that a lot of people get wrong. Many would take that answer as evidence that this model was somehow trained on OpenAI data. He does not actually think that is necessarily true. The reason: if you do not explicitly program the model to answer these kinds of questions, what you get is its statistical best guess at the answer. This model had an SFT data mixture of conversations, and during finetuning it understood that it was taking on the personality of a helpful assistant, but it was never told exactly what label to apply to itself. Meanwhile the pretraining stage took the documents from the entire internet, and ChatGPT and OpenAI are very prominent in those documents. So what is actually likely happening is that this is its hallucinated label for what it is. Its self identity is that it is ChatGPT by OpenAI, and it is only saying that because there is a ton of data on the internet of answers like this that actually came from ChatGPT.

There are two ways to override this as a developer, and he shows both.

Way one: hardcode it in the SFT data. He pulls up OLMo from the Allen Institute for AI, which he likes specifically because it is fully open source, paper and everything, which is nice. He opens its SFT mixture, which is the finetuning conversation data. There is a total of 1 million conversations in the mixture, and one component is labeled as hardcoded. Click into it and there are 240 conversations. They are exactly what you would expect: "Tell me about yourself," and the assistant says "I'm OLMo, an open language model developed by the Allen Institute for Artificial Intelligence, I'm here to help." "What is your name." Cooked up, hardcoded questions and the correct answers to give. Take 240 conversations like that, put them in your training set, finetune on it, and the model will be expected to parrot this stuff later. Do not give it this, and it is probably ChatGPT by OpenAI.

Way two: the system message. In these conversations, as well as turns between human and assistant, there is sometimes a special message called the system message at the very beginning of the conversation. So it is not just human and assistant, there is a system too. In the system message you can hardcode and remind the model that it is a model developed by OpenAI, that its name is ChatGPT 4o, what date it was trained, what its knowledge cutoff is. It documents the model a little bit, and then that gets inserted into your conversations. When you go to ChatGPT you see a blank page, but actually the system message is hidden in there and those tokens are in the context window.

Both routes are the same kind of thing: invisible tokens in the context window that remind the model of its identity. And he is blunt about what that means. "It's all just kind of cooked up and bolted on in some way. It's not actually like really deeply there in any real sense as it would be for a human."

Models need tokens to think (1:46:56)

This is the section with the most practical payoff, and he sets it up as a puzzle rather than a lecture.

The setup: suppose we are building out a conversation to enter into our training set of conversations, teaching the model how to solve simple math problems. The prompt is:

Emily buys 3 apples and 2 oranges. Each orange costs $2. The total cost of all the fruit is $13. What is the cost of each apple?

Simple question. He puts two answers on screen, left and right. Both are correct. Both say the answer is 3. But one of them is a significantly better answer for the assistant than the other. If he were a data labeler creating one of these, one would be a really terrible answer and the other would be okay. He invites you to pause the video and work out which, and he warns: if you use the wrong one, your model will actually be really bad at math. This is the sort of thing you would be careful with in your labeling documentation when training people to create ideal responses.

The key is to remember that when models are training and also inferencing, they work in a one dimensional sequence of tokens from left to right. He puts up the picture he has in his own mind: the token sequence evolving left to right, and to produce each next token we feed all the tokens so far into the network and get probabilities out. This is the exact same picture as the web demo of the Transformer from earlier.

And now the crucial constraint. There is a finite number of layers of computation. The demo network has only one, two, three layers of attention and MLP. A typical modern state of the art network would have more like 100 layers. But that is it: only about 100 layers of computation to go from the previous token sequence to the probabilities for the next token.

"There's a finite amount of computation that happens here for every single token, and you should think of this as a very small amount of computation."

That amount is roughly fixed for every single token in the sequence. Not perfectly: the more tokens you feed in, the more expensive the forward pass, but not by much. So the good mental model is a fixed amount of compute in that box for every single token, and it cannot possibly be too big, because there are not that many layers going top to bottom.

Therefore: you cannot imagine the model doing arbitrary computation in a single forward pass to get a single token. We have to distribute our reasoning and our computation across many tokens.

So why is the left answer worse? Imagine going left to right, emitting tokens one at a time. The model has to say "The answer is", then the dollar sign, and right there we are expecting it to cram all of the computation of this problem into that single token. It has to emit the correct answer, 3. And then once 3 has been emitted, everything that follows is post hoc justification, because the answer is already created and already in the context window. It is not actually being calculated in those tokens.

"If you are answering the question directly and immediately, you are training the model to try to basically guess the answer in a single token, and that is just not going to work because of the finite amount of computation that happens per token."

The right answer is significantly better because we are distributing the computation across the answer. We get the model to slowly come to the answer from left to right, producing intermediate results: the total cost of the oranges is 4, so 13 minus 4 is 9, so 9 divided by 3 is 3. Each of those calculations is by itself not that expensive. We are guessing a little bit at the difficulty the model is capable of in any single token, and there can never be too much work in any one token, because then the model will not be able to do it later at test time. By the time it is near the end it has all the previous results in its working memory and it is much easier for it to determine that the answer is 3.

He notes in passing that in your prompts you usually do not have to think about this explicitly, because the people at OpenAI have labelers who worry about it and make sure the answers are spread out. So when he asks this question in ChatGPT it goes very slowly: okay, let's define our variables, set up the equation. "These are not for you. These are for the model. If the model is not creating these intermediate results for itself, it's not going to be able to reach three."

Then he runs the experiment to prove the constraint is real, by being a bit mean to the model.

And then his own practical caveat, which is the honest one. If he were actually solving this in his day to day life he would not trust that all the intermediate calculations are correct either. So what he would actually do is say "use code." Code is one of the tools ChatGPT can use, and instead of the model doing mental arithmetic, which he does not fully trust, especially if the numbers get really big, it writes a program.

"We're using neural networks to do mental arithmetic, kind of like you doing mental arithmetic in your brain. It might just screw up some of the intermediate results. It's actually kind of amazing that it can even do this kind of mental arithmetic. I don't think I could do this in my head."

The mechanism is the same as web search. There is a special tool, and the model will not actually generate the result tokens itself. It writes the program, that program gets sent to a different part of the computer that just runs it, the result comes back, and the model gets access to the result. He can inspect that the code is correct, the Python interpreter does the arithmetic, and he personally trusts that a lot more, because it came out of a Python program, which has a lot more correctness guarantees than the mental arithmetic of a language model.

His summary of the section, in his own words: models need tokens to think. Distribute your computation across many tokens. Ask models to create intermediate results, and whenever you can, lean on tools and tool use instead of letting the model do it all in its memory.

EVERY TOKEN GETS THE SAME FIXED BUDGET: ~100 LAYERS OF ATTENTION + MLP. A VERY SMALL AMOUNT OF COMPUTATION. A terrible label for the assistant The answer is $3 ALL WORK because the oranges cost 4 and 13 - 4 = 9 so 9 / 3 = 3 post hoc justification: the answer is already in the context window, so nothing here is being calculated one token is asked to carry the entire problem A good label for the assistant 2 oranges at $2 each = $4 13 - 4 leaves $9 9 / 3 apples = $3 The computation is spread out. No single token carries too much, so the model can actually do each step. Same final answer. Only one of these two teaches the model something it can reproduce at test time. KARPATHY, ON THE INTERMEDIATE STEPS CHATGPT SHOWS YOU: "THESE ARE NOT FOR YOU. THESE ARE FOR THE MODEL."
Figure 3. The constraint that generates most of this video's practical advice. Compute per token is roughly fixed and small, so reasoning has to be distributed across tokens rather than crammed into one. Karpathy proves the ceiling is real by ordering the model to answer in a single token: it succeeds on 3 apples and 2 oranges, and fails on 23 apples and 177 oranges, answering 5 instead of 7.

Counting, and why "use code" works

He has one more example of the same constraint, in counting. Models are not very good at counting, for the exact same reason: you are asking for way too much in a single individual token.

The demo is "how many dots are below," followed by a block of dots. ChatGPT says "there are" and then just tries to solve the problem in a single token. In a single token it has to count the dots in its context window, in a single forward pass of the network, where there is very little computation available.

And when he looks at what the model actually sees, the problem gets worse. In TikTokenizer, a group of about 20 dots is a single token. The next group is another token. Then they break up differently for reasons that have to do with the details of the tokenizer. So the model basically sees a handful of token IDs, and from those token IDs it is expected to count.

ChatGPT's answer is 161. The correct answer is 177.

Then "use code," and he flags that it is actually kind of subtle and kind of interesting why this should work at all. It is not that he gave the model a calculator. It is that he broke the problem into problems that are easier for the model. He knows the model cannot do mental counting. But he knows the model is actually pretty good at copy pasting. So when he says use code, the model creates a Python string containing the dots, and the task of copy pasting the input is very simple, because the model sees it as just those four or so token IDs, and unpacking them into dots is easy. Then it calls Python's .count() and comes back with 177, correct.

"The Python interpreter is doing the counting. It's not the model's mental arithmetic doing the counting."

Same lesson. Models need tokens to think. Do not rely on their mental arithmetic. If you need counting, always ask them to lean on the tool.

Tokenization revisited: models struggle with spelling (2:01:11)

He promised to loop back around to tokenization, and here is the payoff. Models are not very good at all kinds of spelling related tasks, and the reason is that they do not see the characters. They see tokens. Their entire world is about tokens, which are these little text chunks. They do not see characters like our eyes do, so very simple character level tasks often fail.

The demo: give it the string ubiquitous and ask it to print only every third character starting with the first one. So start with u, then count 1, 2, 3 and q should be next, and so on. The model gets it wrong.

His hypothesis has two parts. The mental arithmetic is failing a little bit. But the more important issue is that when you put ubiquitous into TikTokenizer, it is three tokens. You and I see "ubiquitous" and can easily access the individual letters, because we see them, and with the word in the working memory of our visual field we can really easily index into every third letter. The model does not have access to the individual letters. It sees three tokens. And remember that these models are trained from scratch on the internet, so the model has to discover how many of all these different letters are packed into all these different tokens.

Then an honest aside about why we put up with this at all. The reason we even use tokens is mostly for efficiency. He notes that a lot of people are interested in deleting tokens entirely, that we should really have character level or byte level models. It is just that that would create very long sequences, and people do not know how to deal with that right now. So while we have the token world, any kind of spelling task is not actually expected to work super well.

The fix is the same fix as always. He says use code, and expects it to work, because the task of copy pasting ubiquitous into the Python interpreter is much easier and then we are leaning on Python to manipulate the characters of the string. It indexes into every third character and returns the right letters (u, q, t, s), which he confirms looks correct.

And then the famous one. "How many Rs are there in strawberry?" This went viral many times, and by the time of filming the models now get it correct and say there are three. But for a very long time all the state of the art models would insist that there are only two. This caused a lot of ruckus, because why are the models so brilliant that they can solve math olympiad questions but cannot count Rs in strawberry?

His answer is the one he has been building toward for two hours. Number one, the models do not see characters, they see tokens. Number two, they are not very good at counting. So here we are combining the difficulty of seeing the characters with the difficulty of counting, and that is why the models struggled with this. He adds a candid caveat about the specific case: by now he thinks OpenAI may have hardcoded the answer, or he is not sure what they did, but that specific query now works.

Jagged intelligence (2:04:53)

There are a bunch of other little sharp edges and he does not want to go through all of them or give a comprehensive analysis of every way the models fall short. He just wants to make the point that there are some jagged edges here and there, and that while a few of them make sense, some of them will not make as much sense, and you are left scratching your head even if you understand in depth how these models work.

His example is the one everybody has seen. The models are not very good at very simple questions like "what is bigger, 9.11 or 9.9?" This is shocking to a lot of people, because these models can solve complex math problems and answer PhD grade physics, chemistry and biology questions much better than he can, but sometimes they fall short on something this simple.

He runs it. The model says 9.11 is bigger than 9.9 and justifies it in some way, then flips its decision later in the same response. He is careful about reproducibility: he does not believe this is very reproducible. Sometimes it flips around its answer, sometimes it gets it right, sometimes it gets it wrong. He tries again and this time it does not even correct itself at the end.

So how is it that the model can do great at olympiad grade problems and then fail on this? He calls this one a bit of a head scratcher, and he is scrupulous about his sourcing here: a bunch of people studied this in depth, he has not actually read the paper, but what he was told by that team is that when you scrutinize the activations inside the network and look at which features and neurons turn on and off, a bunch of neurons light up that are usually associated with Bible verses.

So his reading is that the model is kind of reminded that these almost look like Bible verse markers, and in a Bible verse setting 9.11 would come after 9.9, so the model somehow finds it cognitively very distracting. Even here, where it is actually trying to justify the answer and come to it with math, it still ends up with the wrong answer. "It basically just doesn't fully make sense, and it's not fully understood."

His conclusion, which is the practical spine of the last third of the video:

"Treat this as what it is, which is a stochastic system that is really magical but that you can't also fully trust. You want to use it as a tool, not as something that you let rip on a problem and copy paste the results."

Stage three: reinforcement learning

From supervised finetuning to reinforcement learning (2:07:28)

He takes stock before the last stage. We have covered two major stages. In pretraining we train on internet documents and get a base model, an internet document simulator, which takes many months to train on thousands of computers and is a lossy compression of the internet. Extremely interesting, but not directly useful, because we do not want to sample internet documents. We want to ask questions of an AI and have it respond. So we construct an assistant through post training, specifically supervised finetuning, which is algorithmically identical to pretraining. Nothing changes. The only thing that changes is the dataset. Instead of internet documents we curate millions of conversations on all kinds of diverse topics between a human and an assistant, and fundamentally those conversations are created by humans: humans write the prompts, humans write the ideal responses, based on labeling documentation. In the modern stack this is not done fully manually, there is a lot of help from the models themselves, but fundamentally it is all still coming from human curation at the end.

Then we shifted gears into the cognitive implications: that the assistant will hallucinate if you do not take mitigations, that the models are quite impressive and can do a lot in their head but can lean on tools to become better, web search to hallucinate less and bring in recent information, or a code interpreter so the LLM can write code and actually run it and see the results.

Now the last and major stage. Reinforcement learning is still thought of as under the umbrella of post training, but it is the third major stage, and it is a different way of training language models.

He adds an organizational detail that is easy to miss and quietly explains a lot about how these labs work. Inside companies like OpenAI these are all separate teams. There is a team doing data for pretraining and a team doing the training for pretraining. There is a team doing all the conversation generation, and a different team doing the supervised finetuning. And there is a team for reinforcement learning. It is a handoff of these models: you get your base model, then you finetune it to be an assistant, then you go into reinforcement learning.

The motivation, and the analogy that carries the whole stage: going to school.

Just like you went to school to become really good at something, we want to take large language models through school. And when you work with textbooks you will see three major classes of information in them. He pulls a totally random book off the internet, some kind of organic chemistry text, to make the point concretely.

  1. Exposition. Most of the text, the meat of it, background knowledge and context. As you read through the words of the exposition, that is roughly equivalent to training on that data. It is where we build a knowledge base and get a sense of the topic. This is pretraining.
  2. Problems with their worked solutions. A human expert, in this case the author of the book, has given us not just a problem but also worked through the solution. The solution is equivalent to having the ideal response for an assistant. The expert is showing us how to solve the problem in its full form, and as we read the solution we are training on the expert data, and later we can try to imitate the expert. This is supervised finetuning.
  3. Practice problems. Usually many at the end of each chapter. We know practice problems are critical for learning, because of what they get you to do: they get you to practice yourself and discover ways of solving these problems yourself. What you are given is a problem description and the final answer, usually in the answer key, but not the solution. You know the answer you are trying to get to, you have the problem statement, and you are trying out many different things and seeing what gets you to the final solution best. In the process you lean on the background information from pretraining and maybe a little bit of imitation of human experts. This is reinforcement learning.

Why we cannot write the solutions for it

Before showing the mechanics he spends seven minutes on why this stage is necessary at all, and this is the most underrated argument in the video.

He goes back to the Emily fruit problem, with the token view up in TikTokenizer because he wants to remind you again that we are always working with one dimensional token sequences, and this is the native view of the LLM. This is what it actually sees. It sees token IDs.

He puts four candidate solutions on screen. All four reach the answer 3. Some set up a system of equations. Some just talk through it in English. Some skip right through to the solution. ChatGPT, given the question, defines a system of variables and does its little thing.

And then the observation that justifies the whole stage:

"If I am the human data labeler that is creating a conversation to be entered into the training set, I don't actually really know which of these conversations to add to the dataset."

He separates the two purposes that have been tangled together. The first purpose of a solution is to reach the right answer. The second, secondary purpose is presentation for the human, because we assume the person wants to see the intermediate steps and wants it presented nicely. Set presentation aside and focus only on reaching the answer. Which of these four is the optimal solution for the LLM to reach the right answer?

He does not know. As a human labeler he would not know. And he walks through why, using the compute budget per token he established earlier:

And the reason we do not know is not a gap in anyone's knowledge. It is structural:

"What is easy for you or I as human labelers, what's easy for us or hard for us, is different than what's easy or hard for the LLM. Its cognition is different."

Some of the token sequences that are trivial for him might be too much of a leap for the LLM. Conversely, many of the tokens he is writing out might be just trivial to the LLM, and we are wasting tokens on things that are trivial.

He generalizes this past the math example, and this is the sharpest version of the point. It is a very pervasive issue, because our knowledge is not the LLM's knowledge. The LLM has a ton of knowledge, a PhD in math and physics and chemistry and whatnot. In many ways it actually knows more than he does, and he is potentially not utilizing that knowledge in its problem solving. Conversely, he might be injecting a bunch of knowledge in his solutions that the LLM does not know in its parameters, and those are sudden leaps that are very confusing to the model. Our cognitions are different.

"We are not in a good position to create these token sequences for the LLM. They're useful by imitation to initialize the system, but we really want the LLM to discover the token sequences that work for it. It needs to find for itself what token sequence reliably gets to the answer given the prompt, and it needs to discover that in the process of reinforcement learning and of trial and error."

Reinforcement learning, mechanically (2:14:42)

He goes back to the Hugging Face inference playground and picks Gemma 2, the 2 billion parameter model, noting that two billion is very very small, a tiny model, but okay for the demo.

The mechanics are quite simple. We need to try many different kinds of solutions and see which ones work well. So: take the prompt, run the model, the model generates a solution, inspect the solution. We know the correct answer is $3.

And then the scale that makes it work. In practice you might sample thousands of independent solutions, or even a million solutions, for just a single prompt. Some will be correct and some will not. What we want to do is encourage the solutions that lead to correct answers.

He switches to the cartoon diagram, and the numbers here are his. One prompt, many different solutions tried in parallel. Fifteen solutions. Only four of them got the right answer, shown in green; the rest are red. He flags honestly that this specific prompt is not the best example, because it is trivial and even a two billion parameter model always gets it right, so he asks you to exercise some imagination and suppose the green ones are good and the red ones are bad.

Now, whatever token sequences happened in the red solutions, something went wrong somewhere, and that was not a good path. Whatever happened in the green ones, things went pretty well, and we want to do more things like that in prompts like this. The way we encourage that behavior in the future is to train on these sequences.

And here is the break from everything before it:

"These training sequences now are not coming from expert human annotators. There's no human who decided that this is the correct solution. This solution came from the model itself. The model is practicing here."

It tried out a few solutions, four of them worked, and now the model trains on them. This corresponds to a student looking at their own solutions and thinking: okay, this one worked really well, this is how I should be solving these kinds of problems.

There are many ways to tweak the methodology, but the simplest version of the core idea is to take the single best solution out of the four, which he highlights in yellow. That is the one that not only led to the right answer but maybe had other nice properties: maybe it was the shortest, maybe it looked nicest in some ways, and there are other criteria you could imagine. We decide that is the top solution, we train on it, and after the parameter update the model is slightly more likely to take that path in this kind of setting in the future.

Then the scale again, because one prompt is nothing. We run many different diverse prompts across lots of math problems and physics problems and wherever else, tens of thousands of prompts, with thousands of solutions per prompt, all happening at the same time. And as we iterate this process:

"The model is discovering for itself what kinds of token sequences lead it to correct answers. It's not coming from a human annotator. The model is playing in this playground and it knows what it's trying to get to, and it's discovering sequences that work for it. These are sequences that don't make any mental leaps, they seem to work reliably and statistically, and they fully utilize the knowledge of the model as it has it."

His one line summary: "It's basically a guess and check. We're going to guess many different types of solutions, we're going to check them, and we're going to do more of what worked in the future."

And the SFT model still matters in this picture, which is why the stages are sequential rather than alternatives. It initializes the model into the vicinity of the correct solutions. It gets the model to write out solutions, maybe gives it an understanding of setting up a system of equations, maybe it talks through a solution. So it gets you into the neighborhood. But reinforcement learning is where everything gets dialed in.

So the high level process for how we train large language models is, in short, very similar to how we train children, with one difference: children go through the chapters of books and do all these different types of training exercises within each chapter, whereas when we train AIs we do it stage by stage, depending on the type of that stage. First we read all the exposition in all the textbooks at the same time and build a knowledge base. Then we look at all the worked solutions from human experts across all the textbooks and get an SFT model that can imitate the experts, but does so kind of blindly, just doing its best guess, trying to mimic statistically the expert behavior. Then in the last stage we do all the practice problems across all the textbooks and we get the RL model.

Why RL is the frontier and not yet standard

He is careful to put this stage in context, because it is the one where the field is still moving.

The first two stages, pretraining and supervised finetuning, have been around for years. They are very standard and everyone does them, all the different LLM providers. It is this last stage, the RL training, that is a lot more early in its process of development and is not standard yet in the field.

And he is honest about why: he skipped over a ton of little details. The high level idea is very simple, trial and error learning, but there are a ton of details and little mathematical nuances to exactly how you pick the solutions that are the best, how much you train on them, what the prompt distribution is, how to set up the training run such that this actually works. A lot of little details and knobs attached to a core idea that is very very simple. Getting the details right is not trivial.

Which is why companies like OpenAI and the other LLM providers have experimented internally with reinforcement learning finetuning for LLMs for a while, but have not talked about it publicly. It was all kind of done inside the company.

And that is why the DeepSeek paper was such a big deal.

DeepSeek R1 (2:27:47)

The paper from DeepSeek, a company in China, talked very publicly about reinforcement learning finetuning for large language models, how incredibly important it is, and how it brings out a lot of reasoning capabilities in the models. It reinvigorated the public interest in using RL for LLMs and gave a lot of the details that are needed to reproduce their results and actually get the stage to work.

He takes you through what happens when you apply RL correctly.

Figure 2 of the paper, the quantitative result. This is the accuracy of solving mathematical problems, measured on AIME. He pulls up the competition web page so you can see the kinds of problems involved, and invites you to pause the video to read them. In the beginning the models are not doing very well, but as you update the model with many thousands of steps the accuracy continues to climb. The models are improving and solving these problems with higher accuracy as you do this trial and error on a large dataset.

But the qualitative result is more incredible than the quantitative one, and this is the part of the paper that mattered.

Another figure shows that later in the optimization the average length per response goes up. The model is using more tokens to get its higher accuracy results. It is learning to create very very long solutions. So why are the solutions long? He scrolls to the qualitative examples and reads what the model learned to do. It is an emergent property of the optimization: it just discovers that this is good for problem solving.

What it starts doing looks like this:

"Wait wait wait, that's an aha moment I can flag here. Let's reevaluate this step by step to identify the correct sum."

So what is the model doing? It is reevaluating steps. It has learned that it works better for accuracy to try out lots of ideas, try something from different perspectives, retrace, reframe, backtrack. It is doing a lot of the things that you and I are doing in the process of problem solving for mathematical questions. But it is rediscovering what happens in your head, not what you put down on the solution.

And that is the crucial distinction, because of the argument he built in the previous section:

"There is no human who can hardcode this stuff in the ideal assistant response. This is only something that can be discovered in the process of reinforcement learning, because you wouldn't know what to put here."

So the model learns what we call chains of thought in your head, and it is an emergent property of the optimization. That is what is bloating up the response length, and that is also what is increasing the accuracy.

"What's incredible here is basically the model is discovering ways to think. It's learning what I like to call cognitive strategies of how you manipulate a problem and how you approach it from different perspectives, how you pull in some analogies, how you try out many different things over time, check a result from different perspectives. Extremely incredible to see this emerge in the optimization without having to hardcode it anywhere. The only thing we've given it are the correct answers."

Then he runs it live on the Emily problem. DeepSeek R1 is available on chat.deepseek.com, and you have to make sure the DeepThink button is turned on to get the R1 model. He pastes the fruit problem in and reads the output, and the difference from the GPT-4o response is obvious on the page. Where the SFT style answer mimics an expert solution, R1 does this:

"Okay, let me try to figure this out. So Emily buys three apples and two oranges, each orange cost $2, total is 13, I need to find out blah blah blah." ... "Wait a second, let me check my math again to be sure." ... "Yep, all that checks out. I think that's the answer, I don't see any mistakes. Let me see if there's another way to approach the problem, maybe setting up an equation. Let the cost of one apple be..." ... "Yep, same answer. So definitely each apple is $3. All right, confident that that's correct."

Then, once the thinking process is done, it writes up the nice solution for the human and boxes in the correct answer at the bottom. So the two purposes he separated earlier, correctness and presentation, are now visibly separated in the output itself. "As you're reading this you can't escape thinking that this model is thinking."

"This is what's coming from the reinforcement learning process. This is what's bloating up the length of the token sequences. They're doing thinking and they're trying different ways. This is what's giving you higher accuracy in problem solving, and this is where we are seeing these aha moments."

And then the practical note on where to run it. Some people are a little bit nervous about putting very sensitive data into chat.deepseek.com, because this is a Chinese company. But DeepSeek R1 is an open weights model, available for anyone to download and use. You will not be able to run the full model in full precision on a MacBook or a local device, because it is fairly large, but many companies are hosting the full largest model, and the one he likes is Together AI. Sign up, go to playgrounds, select DeepSeek R1 in the chat; there are many other state of the art models in the dropdown. It is similar to the Hugging Face inference playground, but Together usually hosts all the state of the art models. The default settings will often be okay. Because the model was released by DeepSeek, what you get here should be basically equivalent in principle, identical in terms of the power of the model, quantitatively and qualitatively, just with different sampling randomness, and this one is coming from an American company.

Which models are thinking models, and which are not

Back in ChatGPT, he reads the dropdown. The models that say they use advanced reasoning, like o1, o3-mini and o3-mini-high, are referring to the fact that they were trained by reinforcement learning with techniques very similar to those of DeepSeek R1, per public statements of OpenAI employees. Those are thinking models trained with RL.

And the models you get in the free tier, GPT-4o and GPT-4o-mini, you should think of as mostly SFT models. They do not do the thinking you see in the RL models. There is a little bit of reinforcement learning involved with them, which he covers in the RLHF section, but they are mostly SFT models and he thinks you should think about it that way. (Note that o1 and o3-mini were current when this was filmed in early 2025, and the lineup has moved on since; the distinction between a thinking model and an SFT model is the durable part.)

He picks o3-mini-high and runs it, and flags that those models may not be available unless you pay a ChatGPT subscription of either $20 per month or $200 per month for some of the top models. It says "reasoning" and starts to work.

And then an important caveat about what you are allowed to see. What appears in the OpenAI web interface is not exactly the chains of thought the model produced. Under the hood the model produces them, but OpenAI chooses not to show the exact chains of thought and shows little summaries of them instead. His read on why: they are worried about the distillation risk, that someone could come in and imitate those reasoning traces and recover a lot of the reasoning performance by just imitating the chains of thought. So they hide them and show only summaries. You are not getting exactly what you would get in DeepSeek with respect to the reasoning itself, though the written up solution is equivalent.

On performance, he gives a measured answer rather than a verdict. These models and the DeepSeek models are currently roughly on par. It is kind of hard to tell because of the evaluations, but if you are paying $200 per month to OpenAI, he believes some of those models still look better. DeepSeek R1 is still a very solid choice for a thinking model that is available to you, on that website or any other, because the model is open weights and you can just download it.

His own usage pattern, which is the most useful calibration in this part of the video: empirically about 80 to 90 percent of his use is just GPT-4o. If you have a prompt that requires advanced reasoning you should probably use or at least try the thinking models, but for a simpler knowledge based or factual question it is overkill. There's no need to think 30 seconds about some factual question. When he comes across a very difficult problem in math or code he reaches for a thinking model, but then he has to wait a bit longer, because they are thinking.

Finally he points at Google AI Studio, with a parenthetical that is pure Karpathy: it looks really busy and really ugly, because "Google's just unable to do this kind of stuff well." But choose the model Gemini 2.0 Flash Thinking Experimental 01-21 and that is also an early experimental thinking model from Google. He gives it the same problem, clicks run, it does something similar, and comes out with the right answer. So Google also offers a thinking model. Anthropic, at the time of filming, does not.

"This is kind of like the frontier development of these LLMs. I think RL is kind of like this new exciting stage, but getting the details right is difficult, and that's why all these models and thinking models are currently experimental as of 2025, very early 2025."

AlphaGo, and move 37 (2:42:07)

The connection he wants to make is that the discovery that reinforcement learning is an extremely powerful way of learning is not new to the field of AI, and one place we have already seen it demonstrated is the game of Go, where DeepMind famously developed AlphaGo. There is a movie about it you can watch.

He goes to the AlphaGo paper and scrolls to a plot he calls really interesting and kind of familiar, because we are rediscovering the same thing in the more open domain of arbitrary problem solving instead of the closed specific domain of Go. The plot shows Elo rating in the game of Go, with a line for Lee Sedol, an extremely strong human player, and it compares two things:

He adds a nice honest aside on the plot itself: probably they could have run it longer and just chose to crop it at some point, because this costs money. And then the connecting line: "we're only starting to see hints of this diagram in larger language models for reasoning problems."

"We're not going to get too far by just imitating experts. We need to go beyond that, set up these little game environments, and let the system discover reasoning traces or ways of solving problems that are unique and that just basically work well."

And then move 37. On uniqueness: notice that when you are doing reinforcement learning, nothing prevents you from veering off the distribution of how humans are playing the game. He goes back to the AlphaGo search results and one of the suggested modifications is "move 37."

Move 37 refers to a specific point in time where AlphaGo played a move no human expert would play. The probability of this move being played by a human player was evaluated to be about 1 in 10,000. A very rare move. But in retrospect it was a brilliant move. AlphaGo, in the process of reinforcement learning, discovered a strategy of playing that was unknown to humans and is in retrospect brilliant.

He recommends a YouTube video of the reactions and analysis, and plays the audio of the commentators realizing what they are looking at. The moment is on YouTube:

"That's a very, that's a very surprising move. I thought, I thought it was, I thought it was a mistake."

People were freaking out because it is a move a human would not play, that AlphaGo played because in its training this move seemed to be a good idea. It just happens not to be the kind of thing humans would do. And that is again the power of reinforcement learning.

Then he extrapolates, carefully flagging it as speculation. In principle we can see the equivalent of that if we continue scaling this paradigm in language models, and what that looks like is unknown. What does it mean to solve problems in such a way that even humans would not be able to get it? How can you be better at reasoning or thinking than humans? How can you go beyond just a thinking human?

"In principle the behavior of the system is a lot less defined. It is open to do whatever works, and it is open to also slowly drift from the distribution of its training data, which is English."

But all of that can only be done if we have a very large and diverse set of problems in which these strategies can be refined and perfected. And that is where a lot of the frontier LLM research is going right now: trying to create the kinds of prompt distributions that are large and diverse. He calls them game environments in which the LLMs can practice their thinking. It is like writing practice problems. We have to create practice problems for all domains of knowledge, and if we have tons of them, the models will be able to reinforcement learn on them and create these kinds of diagrams, but in the domain of open thinking instead of a closed domain like Go.

Reinforcement learning from human feedback (2:48:26)

There is one more section within reinforcement learning, and it is learning in unverifiable domains.

Everything we have looked at so far is in a verifiable domain, meaning any candidate solution can be scored very easily against a concrete answer. The answer is 3, and we can easily score solutions against 3. Either we require the models to box in their answers and check equality with whatever is in the box, or we use an LLM judge, which looks at a solution and the answer and scores the solution for whether it is consistent. LLMs are empirically good enough at the current capability to do this fairly reliably. In either case we have a concrete answer, we are just checking solutions against it, and we can do this automatically with no humans in the loop.

The problem is unverifiable domains. Usually these are creative tasks: write a joke about pelicans, write a poem, summarize a paragraph. In these domains it becomes harder to score different solutions.

He demonstrates with jokes, and the demonstration is funny mostly because of how it fails. He asks ChatGPT for pelican jokes:

"So much stuff in their beaks because they don't believe in backpacks."

"Why don't pelicans ever pay for their drinks? Because they always bill it to someone else."

"Haha. Okay." His verdict: these models are obviously not very good at humor. And then an aside worth keeping: "Actually I think it's pretty fascinating, because I think humor is secretly very difficult, and the models have the capability, I think."

So we can generate lots of jokes, that is fine. The problem is how do we score them? In principle we could get a human to look at all of them, just like he did. But work out the arithmetic of reinforcement learning:

Concretely, with his cartoon numbers: 1,000 updates, each on 1,000 prompts, with 1,000 rollouts per prompt scored. We could run RL with that setup just fine, if we had infinite human time. The problem:

"In the process of doing this I will need to ask a human to evaluate a joke a total of 1 billion times. And so that's a lot of people looking at really terrible jokes."

This is an unscalable strategy. We need an automatic one. And the solution was proposed in the paper that introduced reinforcement learning from human feedback, a paper from OpenAI at the time, and he notes in passing that many of those people are now co founders at Anthropic.

The core trick is indirection. We involve humans just a little bit, and the way we cheat is to train a whole separate neural network that we call a reward model, which imitates human scores. Ask humans to score some rollouts, then imitate those human scores with a neural network, and that network becomes a simulator of human preferences. Now that we have a simulator we can do RL against it. Instead of asking a real human, we ask a simulated human for their score of a joke. Once we have a simulator we can query it as many times as we want and the whole process is automatic.

The simulator is not going to be a perfect human, but if it is at least statistically similar to human judgment, you might expect that this will do something. And in practice indeed it does.

Here is how training the reward model works, with his own cartoon numbers:

  1. A prompt, "write a joke about pelicans," and five separate rollouts, five different jokes.
  2. Ask a human to order the jokes from best to worst. One is the funniest, then two, three, four, and five is the worst. We ask humans to order rather than give scores directly, because it is an easier task. It is easier for a human to give an ordering than to give precise scores. That ordering is the human's entire contribution to the training process.
  3. Separately, ask the reward model to score the same jokes. The reward model is a whole separate neural network, completely separate, probably also a Transformer, but it is not a language model in the sense that it generates diverse language. It is just a scoring model. It takes two inputs, the prompt and a candidate joke, and outputs a single number, a score, ranging for example from 0 to 1, where 0 is the worst and 1 is the best. At some stage in training it might give these five jokes scores like 0.1 and 0.8 and so on.
  4. Compare the reward model's scores with the human's ordering, set up a loss function, calculate a correspondence, and update the model.

The intuition, with his numbers:

So we are doing what we did before. Slightly nudging the predictions using a neural network training process, trying to make the reward model scores be consistent with the human ordering. As we update it on human data it becomes a better and better simulator of the scores and orders that humans provide, and then it becomes the simulator of human preferences that we do RL against.

And critically, the human cost collapses. We are not asking humans a billion times. Maybe 1,000 prompts with five rollouts each, so about 5,000 jokes that humans have to look at in total, and all they do is give the ordering.

PROMPT write a joke about pelicans 5 ROLLOUTS HUMAN ORDERING REWARD MODEL SCORE AFTER ONE UPDATE joke 1 1st, funniest 0.8 0.81 nudge up slightly joke 2 2nd 0.1 0.15 big disagreement joke 3 3rd ... joke 4 4th ... joke 5 5th, worst 0.8 0.35 pull it down The human only ever gives an ordering, never a number. Ordering is the easier task, which is why the data is better. Human cost: ~1,000 prompts x 5 rollouts = ~5,000 jokes read. Not the 1,000,000,000 evaluations naive RL would need.
Figure 4. RLHF, built entirely from the cartoon numbers Karpathy puts on screen. The whole technique is one act of indirection: train a neural network to imitate human orderings, then do reinforcement learning against the network instead of against people. That indirection is also exactly where it breaks, because what you are now optimizing is a billion parameter approximation of taste.

The upside, and the discriminator generator gap

He gives RLHF its due before taking it apart.

The first upside is that it lets us run reinforcement learning at all in arbitrary domains, including unverifiable ones: summarization, poem writing, joke writing, any other creative writing, in domains outside math and code.

The second is that empirically it works. When you apply RLHF correctly the models you get are just a little bit better. But he is scrupulous about the explanation: "I have a top answer for why that might be, but I don't actually know that it is super well established on why this is." So he offers his best guess.

His best guess is the discriminator generator gap. In many cases it is significantly easier to discriminate than to generate, for humans. In supervised finetuning we are asking humans to generate the ideal assistant response, and in many cases the ideal response is very simple to write. But in summarization or poem writing or joke writing, how is a human labeler supposed to give the ideal response? It requires creative human writing.

RLHF sidesteps this, because we get to ask people a significantly easier question. They are not asked to write poems directly. They are given five poems from the model and asked to order them. That is a much easier task for a human labeler.

"This allows a lot more higher accuracy data, because we're not asking people to do the generation task, which can be extremely difficult. We're just trying to get them to distinguish between creative writings and find the ones that are best, and that is the signal that humans are providing: just the ordering."

Then the system in RLHF discovers the kinds of responses that would be graded well by humans, and that step of indirection allows the models to become a bit better. So: it lets us run RL, it empirically results in better models, and it lets people contribute their supervision without having to do extremely difficult tasks.

The downside, and "the the the the the"

Unfortunately RLHF also comes with significant downsides.

The main one is structural. We are doing reinforcement learning not with respect to humans and actual human judgment, but with respect to a lossy simulation of humans. That lossy simulation could be misleading, because it is just a simulation, just a language model outputting scores, and it might not perfectly reflect the opinion of an actual human with an actual brain in all the possible different cases.

But there is something even more subtle and devious going on that dramatically holds RLHF back as a technique we could scale to significantly smart systems:

"Reinforcement learning is extremely good at discovering a way to game the model, to game the simulation."

The reward model is a Transformer, a massive neural net with billions of parameters, imitating humans in a simulated way. And these are massive complicated systems. Billions of parameters outputting a single score. It turns out that there are ways to game these models. You can find inputs that were not part of their training set and these inputs inexplicably get very high scores, but in a fake way.

What that looks like in practice, with his numbers. Run RLHF for 1,000 updates, which is a lot of updates, and you might expect your jokes to be getting better, that you are getting real bangers about pelicans. That is not exactly what happens.

"In the first few hundred steps the jokes about pelicans are probably improving a little bit, and then they actually dramatically fall off the cliff and you start to get extremely nonsensical results."

Specifically, the top joke about pelicans starts to be "the the the the the." Which makes no sense. Why should that be a top joke? But when you take "the the the the the" and plug it into your reward model, you would expect a score of zero, and actually the reward model loves it. It will tell you that this is a score of 1.0. This is a top joke.

It makes no sense, but it is because these models are just simulations of humans, massive neural nets, and you can find inputs that get into the part of the input space that gives you nonsensical results at the top. These are adversarial examples, specific little inputs that go between the nooks and crannies of the model and give nonsensical results.

And then the move that does not work, which is the important part. You might imagine doing the obvious thing: "the the the the the" is obviously not a score of one, it is obviously a low score, so let's add it to the dataset and give it an ordering that is extremely bad. And indeed the model will learn that it should have a very low score, and will give it zero.

"The problem is that there will always be basically an infinite number of nonsensical adversarial examples hiding in the model. If you iterate this process many times and you keep adding nonsensical stuff to your reward model and giving it very low scores, you'll never win the game. Reinforcement learning, if you run it long enough, will always find a way to game the model."

Fundamentally this is because our scoring function is a giant neural net, and RL is extremely good at finding the ways to trick it.

So the operational conclusion is blunt. You run RLHF for maybe a few hundred updates, the model is getting better, and then you have to crop it, and you are done. You cannot run too much against this reward model, because the optimization will start to game it. You crop it, you call it, and you ship it. You can improve the reward model, but you come across these situations eventually at some point anyway.

"RLHF is not RL"

This is the line he wants you to leave with, and he explains precisely what he means by it.

"RLHF is not RL. And what I mean by that is, I mean, RLHF is RL obviously, but it's not RL in the magical sense. This is not RL that you can run indefinitely."

The contrast is with the verifiable domains. There, you either got the correct answer or you didn't, and the scoring function is much much simpler: you are just looking at the boxed area and seeing if the result is correct. It is very difficult to game these functions. Gaming a reward model is possible.

So in verifiable domains you can run RL indefinitely. You could run for tens of thousands, hundreds of thousands of steps, and discover all kinds of really crazy strategies that we might not even ever think of. In the game of Go there is no way to game the winning or losing of a game. We have a perfect simulator: we know where all the stones are placed and we can calculate whether someone has won. There is no way to game that, so you can do RL indefinitely and eventually beat even Lee Sedol. With a gameable model you cannot repeat this process indefinitely.

"I kind of see RLHF as not real RL, because the reward function is gameable. So it's more like in the realm of a little finetuning. It's a little improvement, but it's not something that is fundamentally set up correctly where you can insert more compute, run for longer, and get much better and magical results. It lacks magic."

It can finetune your model and get a better performance, and indeed GPT-4o has gone through RLHF, because it works well. It is just not RL in the same sense. "RLHF is like a little finetune that slightly improves your model."

Verifiable domainsUnverifiable domains
Examples he givesMath problems, code, the game of GoWrite a joke about pelicans, write a poem, summarize a paragraph
How a solution gets scoredEquality against a concrete answer, usually boxed in, or an LLM judge, which is reliable enough at current capabilityA reward model: a separate neural network, probably a Transformer, trained to imitate human orderings, outputting one score from 0 to 1
Humans in the loopNone. Fully automaticAbout 1,000 prompts at five rollouts each, giving orderings only, roughly 5,000 reads
How long you can run itIndefinitely. Tens or hundreds of thousands of stepsA few hundred updates, then you crop it and ship
What breaks firstNothing in the scoring function. There is no way to game "did you win the game of Go"Reward hacking. "The the the the the" scores 1.0 and the jokes fall off a cliff
Can you patch the failureNot applicableNo. Add that adversarial example to the dataset and RL finds another, infinitely
What it can reachPast human performance. Move 37, and chains of thought no labeler could writeA small improvement over SFT. Not RL in the magical sense
Figure 5. The distinction the last hour of the video turns on, and the reason Karpathy insists "RLHF is not RL." The dividing line is not the algorithm, which is the same guess and check in both columns. It is whether the thing doing the scoring can be fooled. A boxed answer and a Go board cannot be. A billion parameter approximation of human taste can be, every time, forever.

Closing the technical content: the Swiss cheese model

That is most of the technical content. He took us through the three major stages and paradigms, pretraining, supervised finetuning and reinforcement learning, and showed that they loosely correspond to the process we already use for teaching children. Pretraining is the basic knowledge acquisition of reading exposition. Supervised finetuning is looking at lots and lots of worked examples and imitating experts. Reinforcement learning is the practice problems.

The only difference is that we now have to effectively write textbooks for LLMs and AIs across all the disciplines of human knowledge, and in all the cases where we actually want them to work, like code and math and basically every other discipline. So we are in the process of writing textbooks for them, refining all the algorithms he has presented at a high level, and then doing a really really good job at the execution of training these models at scale and efficiently.

He flags the thing he deliberately did not cover, and marks it as serious rather than incidental. These are extremely large and complicated distributed jobs that have to run over tens of thousands or even hundreds of thousands of GPUs, and the engineering that goes into this is really at the state of the art of what's possible with computers at that scale. Very serious work, underlying what are ultimately very simple algorithms.

Then the theory of mind, and the thing he wants you to take away. These models are really good, they are extremely useful as tools for your work, and you should not trust them fully. Even though we have mitigations for hallucinations, the models are not perfect and they will still hallucinate. It has gotten better over time and will continue to get better. But they can.

And in addition to that, the Swiss cheese model of LLM capabilities, which is the image he wants in your mind:

"The models are incredibly good across so many different disciplines, but then fail randomly, almost, in some unique cases. So for example, what is bigger, 9.11 or 9.9? The model doesn't know, but simultaneously it can turn around and solve olympiad questions. And so this is a hole in the Swiss cheese, and there are many of them, and you don't want to trip over them."

So: do not treat these models as infallible. Check their work. Use them as tools, use them for inspiration, use them for the first draft, but work with them as tools and be ultimately responsible for the product of your work.

Preview of things to come (3:09:39)

A few bullet points on what you can expect coming down the pipe.

Multimodality. The models will very rapidly become multimodal. Everything above concerned text, but very soon we will have LLMs that can operate natively and very easily over audio, so they can hear and speak, and over images, so they can see and paint. We are already seeing the beginnings of all of this, but this will all be done natively inside the language model, enabling natural conversations.

And here is the part that makes it not a fundamental change, which is the nice payoff of having built the whole picture on tokens. As a baseline you can tokenize audio and images and apply the exact same approaches as everything above. It is not a fundamental change, we just have to add some tokens.

So we create streams of tokens representing audio and images as well as text, interleave them, and handle them all simultaneously in a single model.

Agents, and long running tasks. Currently most of the work is that we hand individual tasks to the models on a silver platter. Please solve this task for me, and the model does the little task, but it is up to us to organize a coherent execution of tasks to perform jobs. The models are not yet at the capability required to do this in a coherent, error correcting way over long periods of time. They cannot fully string together tasks to perform longer running jobs. But they are getting there, and this is improving.

What is probably going to happen: we start to see agents which perform tasks over time, and you supervise them, you watch their work, and they come up once in a while to report progress. Tasks that do not take a few seconds of response but many tens of seconds, or even minutes or hours.

But these models are not infallible, so all of this will require supervision. And he offers an analogy that has aged well: in factories people talk about the human to robot ratio for automation. He thinks we are going to see something similar in the digital space, where we talk about human to agent ratios, and humans become a lot more supervisors of agent tasks in the digital domain.

Pervasive and invisible. Everything is going to become a lot more pervasive and invisible, integrated into the tools and everywhere.

Computer use. Right now these models are not able to take actions on your behalf, but he calls out ChatGPT's launch of Operator as an early example of handing off control to the model to perform keyboard and mouse actions on your behalf, and says that is also something he finds very interesting.

And the research that is still to do: test time training. This is the most interesting of his forward looking points because it names a real structural gap rather than a capability gap.

Everything above has two major stages. First the training stage, where we tune the parameters to perform the tasks well. Then, once we get the parameters, we fix them and deploy the model for inference, and from there the model is fixed. It does not change anymore. It does not learn from all the stuff that it's doing at test time. It is a fixed number of parameters, and the only thing changing is the tokens inside the context window.

So the only type of test time learning the model has access to is the in context learning of its dynamically adjustable context window. And he thinks this is still different from humans, who actually are able to learn depending on what they are doing, especially when you sleep, when your brain is updating your parameters or something like that. There is no equivalent of that currently in these models and tools. There are a lot of wonky ideas still to be explored.

He thinks this will be necessary, and the argument is concrete. The context window is a finite and precious resource. Once we start to tackle very long running multimodal tasks and we are putting in videos, these token windows will start to grow extremely large, not thousands or even hundreds of thousands but significantly beyond that. And the only trick available to us right now is to make the context windows longer. "I think that approach by itself will not scale to actual long running tasks that are multimodal over time, and so I think new ideas are needed."

Keeping track of LLMs (3:15:15)

Three resources he has consistently used to stay up to date.

One: LM Arena. An LLM leaderboard that ranks all the top models, with the ranking based on human comparisons. Humans prompt the models and judge which one gives a better answer, they do not know which model is which, they are just looking at which answer is better, and you calculate a ranking from that. Clicking any model takes you to where that model is hosted.

He reads the board as it stood at the time of filming, and the detail he stops on is in the last column:

And then the caveat, which is the useful part:

"I will say that this leaderboard was really good for a long time. I do think that in the last few months it's become a little bit gamed, and I don't trust it as much as I used to."

His evidence is his own sense of the field rather than a measurement, and he says so: empirically he feels like a lot of people are using Sonnet from Anthropic and that it is a really good model, but it is all the way down at number 14, and conversely he thinks not as many people are using Gemini but it is ranking really really high. So use this as a first pass, but try out a few of the models for your tasks and see which one performs better.

Two: the AI News newsletter, produced by swyx and friends, which he thanks them for maintaining. "AI News is not very creatively named, but it is a very good newsletter." Why it works: it is extremely comprehensive. Go to the archives and you see it is produced almost every other day, and some of it is written and curated by humans but a lot of it is constructed automatically with LLMs. So it is very comprehensive, and you are probably not missing anything major if you go through it. Of course you are probably not going to go through it, because it is so long, but he thinks the summaries all the way up top are quite good and have some human oversight.

Three: X. A lot of AI happens on X, so follow people you like and trust and get your latest and greatest there as well.

Where to find LLMs, and how to run them (3:18:34)

Four cases, and he is specific about which tool for which.

Proprietary models: go to the provider's website. For OpenAI that is ChatGPT. For Gemini it is either the Gemini site or AI Studio, and he cannot resist noting that "I think they have two for some reason that I don't fully understand. No one does."

Open weights models: go to an inference provider. His favorite is Together AI. Go to the playground and you can pick lots of different models, all of them open models of different types, and talk to them there.

Base models: go to Hyperbolic. This is the one that is actually hard to find, and he says so. "It's not as common to find base models even on these inference providers. They are all targeting assistants and chat." Even on Together he could not see base models. So for base models he usually goes to Hyperbolic, because they serve Llama 3.1 405B base, and he loves that model. And a small editorial wish: "I wish more people hosted base models, because they are useful and interesting to work with in some cases."

Smaller models, locally on your own machine. DeepSeek's biggest model you will not be able to run locally on a MacBook, but there are smaller versions of the DeepSeek model that are distilled, and you can also run models at smaller precision, not the native precision of fp8 on DeepSeek or bf16 on Llama but much lower than that. He says not to worry if you do not fully understand those details: the point is that you can run smaller distilled versions at even lower precision, fit them on your computer, and actually run pretty okay models on your laptop.

His tool for this is LM Studio, and his review of it is unsparing and funny.

"It kind of actually looks really ugly, and I don't like that it shows you all these models that are basically not that useful, like everyone just wants to run DeepSeek. So I don't know why they give you these 500 different types of models. They're really complicated to search for, and you have to choose different distillations and different precisions and it's all really confusing."

But once you understand how it works, which he says is a whole separate video, you can load up a model and talk to it. He loads Llama 3.2 Instruct 1B, asks for pelican jokes, asks for another one, and gets another one. All of that happens locally on your computer. We are not actually going to anyone else. This is running on the GPU on the MacBook Pro, which is very nice, and you can then eject the model when you are done, which frees up the RAM.

So LM Studio is probably his favorite, even though he thinks it has a lot of UI and UX issues and is really geared towards professionals almost. If you watch some videos on YouTube you can figure out how to use the interface.

The grand summary (3:21:46)

He loops all the way back to where he started. We go to ChatGPT, we enter a query, we hit go. What exactly is happening? What are we seeing? What are we talking to? How does this work?

He walks the whole path one more time, now that every piece has a name.

Your query is chopped up into tokens. He goes back to TikTokenizer and shows the place in the format where the user query goes. Your query goes into the conversation protocol format, the way we maintain conversation objects, so it gets inserted there, and then the whole thing ends up being just a one dimensional token sequence under the hood. ChatGPT saw that token sequence, and when you hit go it basically continues appending tokens into this list. It continues the sequence. It acts like a token autocomplete. He pastes the response back into the tokenizer so you can see the tokens it continued with.

And then the real question. Why are these the tokens that the model responded with? Where are they coming from? What are we talking to, and how do we program this system?

So what is the thing that came back? His answer, the clearest statement of the idea in the whole video:

"This is the neural network simulation of a data labeler at OpenAI. So it's as if I gave this query to a data labeler at OpenAI, and this data labeler first reads all of the labeling instructions from OpenAI and then spends two hours writing up the ideal assistant response to this query and giving it to me. Now we're not actually doing that, right, because we didn't wait two hours. So what we're getting here is a neural network simulation of that process."

And we have to keep in mind that these neural networks do not function like human brains do. They are different. What is easy or hard for them is different from what is easy or hard for humans, so we really are just getting a simulation. He shows the token stream and the network with its activations and neurons in between one last time: a fixed mathematical expression that mixes inputs from tokens with parameters of the model and gets you the next token in a sequence, with a finite amount of compute for every single token. Whatever the humans write, the language model is imitating on this token level, with only that specific computation per token.

And as a result of that, and of the cognitive differences, the models suffer in a variety of ways and you have to be very careful with their use. They hallucinate. And there is the Swiss cheese model: there are holes in the cheese, and sometimes the models will just arbitrarily do something dumb. Even though they are doing lots of magical stuff, sometimes they just cannot. Maybe you are not giving them enough tokens to think. Maybe they are going to make stuff up because their mental arithmetic breaks. Maybe they are suddenly unable to count letters. Maybe they are unable to tell you that 9.11 is smaller than 9.9, and it looks kind of dumb. So it is a Swiss cheese capability and we have to be careful with it. And we saw the reasons for each of them.

But things change a little bit when you reach for a thinking model, and he is precise about why. GPT-4o basically does not do reinforcement learning. It does do RLHF, but RLHF is not RL. There is no time for magic in there, it is just a little bit of finetuning. The thinking models do use RL. They go through this third stage of perfecting their thinking process and discovering new thinking strategies and solutions to problem solving that look a little bit like your internal monologue in your head, and they practice that on a large collection of practice problems that companies like OpenAI create and curate and make available to the LLMs.

So when you talk to a thinking model, what you are seeing is not anymore just the straightforward simulation of a human data labeler. OpenAI is not showing us the under the hood thinking and the chains of thought underlying it, only a summary, but we know such a thing exists, and what we are getting is actually not just an imitation of a human data labeler. It is a function of thinking that was emergent in a simulation. It comes from the reinforcement learning process.

Two honest open questions he leaves on the table rather than answering:

  1. Does it transfer? The question he puts to the field: whether the thinking strategies developed inside verifiable domains transfer and are generalizable to other domains that are unverifiable, such as creative writing. "The extent to which that transfer happens is unknown in the field, I would say." We are not sure whether we can do RL on everything verifiable and see the benefits of that on things that are unverifiable.
  2. How early is this? "This reinforcement learning here is still way too new, primordial and nascent. So we're just seeing the beginnings of the hints of greatness in the reasoning problems." We are seeing something that is in principle capable of something like the equivalent of move 37, but not in the game of Go, in open domain thinking and problem solving. In principle this paradigm is capable of doing something really cool and new and exciting, something even that no human has thought of before. In principle these models are capable of analogies no human has had. He finds it incredibly exciting that these models exist, but again it is very early, and these are primordial models for now, and they will mostly shine in domains that are verifiable like math and code.

And then the close, which is the same advice he gave at the top, now with three and a half hours of mechanism behind it:

"It is an extremely exciting time to be in the field. Personally I use these models all the time daily, tens or hundreds of times, because they dramatically accelerate my work. I think a lot of people see the same thing, and I think we're going to see a huge amount of wealth creation as a result of these models. Be aware of some of their shortcomings. Even with RL models they're going to suffer from some of these. Use it as a tool in a toolbox, don't trust it fully, because they will randomly do dumb things. They will randomly hallucinate, they will randomly skip over some mental arithmetic and not get it right, they randomly can't count or something like that. So use them as tools in the toolbox, check their work, and own the product of your work. But use them for inspiration, for first draft, ask them questions, but always check and verify, and you will be very successful in your work if you do so."

Then, with the warmth that makes this video what it is: "I hope this video was useful and interesting to you. I hope you had fun. And it's already very long, so I apologize for that."

Key takeaways

Chapters

Notable quotes

Lightly cleaned of filler only. Wording, order and timestamps are his.

"It is obviously magical and amazing in some respects. It's really good at some things, not very good at other things, and there's also a lot of sharp edges to be aware of." Andrej Karpathy, opening the video, 0:00:00

"The FineWeb dataset, which is fairly representative of what you would see in a production grade application, actually ends up being only about 44 terabytes of disk space. You can get a USB stick for like a terabyte very easily." On how small the filtered internet is, 0:02:04

"This sequence length is actually going to be a very finite and precious resource in our neural network." The sentence the whole of tokenization follows from, 0:09:14

"There's no memory in this expression. It's a fixed mathematical expression from input to output with no memory. It's stateless." On why you should not think of these as neurons, 0:24:38

"It's a token simulator. It's an internet text token simulator. They just create sort of remixes of the internet. They dream internet pages." On what a base model actually is, 0:43:10

"You can think of these 405 billion parameters as a kind of compression of the internet. You can think of it as kind of like a zip file, but it's not a lossless compression, it's a lossy compression." 0:49:56

"You're not talking to a magical AI, you're talking to an average labeler. This average labeler is probably fairly highly skilled, but you're talking to kind of like an instantaneous simulation of that kind of a person that would be hired in the construction of these datasets." The reframing the video is best known for, 1:18:03

"They don't have access to the internet, they're not doing research. These are statistical token tumblers, as I call them. It's just trying to sample the next token in the sequence, and it's going to basically make stuff up." On where hallucinations come from, 1:22:37

"Knowledge in the parameters of the neural network is a vague recollection. The knowledge in the tokens that make up the context window is the working memory." The single most useful mental model in the video, 1:39:34

"It has no persistent self, it has no sense of self. It's a token tumbler, and it follows the statistical regularities of its training set." On why asking a model what model it is makes no sense, 1:42:05

"These are not for you, these are for the model. If the model is not creating these intermediate results for itself, it's not going to be able to reach three." On the intermediate steps ChatGPT shows you, 1:53:48

"Models need tokens to think. Distribute your computation across many tokens. Ask models to create intermediate results, or whenever you can, lean on tools and tool use instead of allowing the models to do all of the stuff in their memory." 1:57:51

"What is easy for you or I as human labelers, what's easy for us or hard for us, is different than what's easy or hard for the LLM. Its cognition is different." The argument for why reinforcement learning has to exist, 2:17:54

"We really want the LLM to discover the token sequences that work for it. It needs to find for itself what token sequence reliably gets to the answer given the prompt." 2:19:28

"There is no human who can hardcode this stuff in the ideal assistant response. This is only something that can be discovered in the process of reinforcement learning, because you wouldn't know what to put here." On the emergent backtracking in DeepSeek R1, 2:31:48

"The model is discovering ways to think. It's learning what I like to call cognitive strategies of how you manipulate a problem and how you approach it from different perspectives. The only thing we've given it are the correct answers." 2:32:18

"You can't fundamentally go beyond a human player if you're just imitating human players." On the ceiling of supervised learning, from the AlphaGo plot, 2:43:31

"That's a very, that's a very surprising move. I thought, I thought it was a mistake." The commentary clip Karpathy plays on AlphaGo's move 37, 2:46:04

"In the process of doing this I will need to ask a human to evaluate a joke a total of 1 billion times. And so that's a lot of people looking at really terrible jokes." Why RLHF has to exist, 2:51:41

"Actually I think it's pretty fascinating, because I think humor is secretly very difficult, and the models have the capability, I think." After reading out two bad pelican jokes, 2:49:39

"When you take 'the the the the the' and you plug it into your reward model, you'd expect a score of zero, but actually the reward model loves this as a joke. It will tell you that this is a score of 1.0. This is a top joke. And this makes no sense." Reward hacking, demonstrated, 3:02:25

"RLHF is not RL. And what I mean by that is, I mean, RLHF is RL obviously, but it's not RL in the magical sense. This is not RL that you can run indefinitely." 3:05:00

"It's not RL in the sense that it lacks magic. It can finetune your model and get a better performance, but it's not something that is fundamentally set up correctly where you can insert more compute, run for longer, and get much better and magical results." 3:06:34

"The models are incredibly good across so many different disciplines, but then fail randomly, almost, in some unique cases. So this is a hole in the Swiss cheese, and there are many of them, and you don't want to trip over them." 3:08:38

"This is the neural network simulation of a data labeler at OpenAI. It's as if I gave this query to a data labeler at OpenAI, and this data labeler first reads all of the labeling instructions and then spends two hours writing up the ideal assistant response to this query and giving it to me." The grand summary, 3:24:27

"Use them as tools in the toolbox, check their work, and own the product of your work. But use them for inspiration, for first draft, ask them questions, but always check and verify, and you will be very successful in your work if you do so." The last substantive thing he says, 3:30:37

Resources mentioned

Data, tokenization and tooling

Models and papers

Hardware, hosting and running them yourself

Keeping up

People, places and oddities named along the way

Related pages on this site

Where this sits in the LLM Learning track

This is the opening lecture for a reason: it is the only video in the track that touches every stage of the stack in one pass, so everything after it has something to attach to. Start here even if you think you know the material.

What comes next opens the boxes this one leaves closed, roughly in the order he closed them. Attention in transformers takes the component Karpathy treats as a diagram with numbers flowing through it and walks it one matrix at a time. LLMs in five formulas supplies the quantitative frame for the things he gives you intuitively here, including the finite compute per token that drives the "models need tokens to think" section. Then the two long builds: the GPT tokenizer is the two hour version of the eight minutes above, and it is where every spelling and counting failure in this video stops being a curiosity and becomes something you have typed; reproduce GPT-2 is the four hour version of the training run he slides onto the screen at 0:34:58.

Two later videos in the track are direct expansions of single sections here. John Schulman on RLHF is the whole of the last hour of this video, argued at depth by the person who led that work, including the clearest statement anywhere of why imitation training teaches a model to hallucinate. And Chris Olah on mechanistic interpretability is the discipline behind the one explanation Karpathy cites secondhand and flags as unread: the Bible verse neurons lighting up on 9.11. When you get to them, come back to 1:20:32 and 2:04:53 and the handoff is obvious.

Where it stands

The reconstruction above is Karpathy's lecture in his own frame. Three notes on reading it almost two years later.

What has held up. Nearly all of the mechanism. Tokenization and its consequences, the compute budget per token, the labeler imitation framing, the parameters versus context window distinction, the difference between verifiable and unverifiable reward, and reward hacking are all still the right way to think about these systems, and they have become more load bearing rather than less. His forward looking bullets have aged unusually well: native multimodality arrived, long running agents with a human supervising a fleet arrived, and the human to agent ratio turned out to be a real unit of measure rather than an analogy.

What has moved. The model lineup is the dated part, and visibly so. o1 and o3-mini were the current thinking models when this was filmed in early 2025, GPT-4o was the default, and his line that Anthropic does not offer a thinking model was true that month and stopped being true shortly after. The claim that reinforcement learning is "not standard yet in the field" is the single most dated sentence in the video, since RL post training became standard almost immediately after. His LM Arena snapshot is a photograph of one week. Treat every model name as a timestamp and every mechanism as current.

What he flags himself, and it is worth noticing how often. He says he has not read the paper behind the 9.11 explanation and is relaying what a team told him. He says he does not know why RLHF empirically helps and offers his best guess, labeled as a guess. He says he could be wrong about how much of UltraChat is human. He says he does not know why the special token is called an imaginary monologue. He corrects his own parameter count on camera. He admits he lacks the expertise to verify the Paris landmarks the base model produced. For a video this confident about mechanism, the rate of unprompted uncertainty flagging is the reason the confident parts read as an argument rather than a sales pitch.

Full transcript
[00:00:00] hi everyone so I've wanted to make this video for a while it is a comprehensive but General audience introduction to large language models like Chachi PT and what I'm hoping to achieve in this video is to give you kind of mental models for thinking through what it is that this tool is it is obviously magical and amazing in some respects it's uh really good at some things not very good at other things and there's also a lot of sharp edges to be aware of so what is behind this text box you can put anything in there and press enter but uh [00:00:32] what should we be putting there and what are these words generated back how does this work and what what are you talking to exactly so I'm hoping to get at all those topics in this video we're going to go through the entire pipeline of how this stuff is built but I'm going to keep everything uh sort of accessible to a general audience so let's take a look at first how you build something like chpt and along the way I'm going to talk about um you know some of the sort of cognitive psychological implications of the tools okay so let's build Chachi PT [00:01:02] so there's going to be multiple stages arranged sequentially the first stage is called the pre-training stage and the first step of the pre-training stage is to download and process the internet now to get a sense of what this roughly looks like I recommend looking at this URL here so um this company called hugging face uh collected and created and curated this data set called Fine web and they go into a lot of detail on this block post on how how they constructed the fine web data set and [00:01:32] all of the major llm providers like open AI anthropic and Google and so on will have some equivalent internally of something like the fine web data set so roughly what are we trying to achieve here we're trying to get ton of text from the internet from publicly available sources so we're trying to have a huge quantity of very high quality documents and we also want very large diversity of documents because we want to have a lot of knowledge inside these models so we want large diversity of high quality documents and we want many many of them and achieving this is [00:02:04] uh quite complicated and as you can see here takes multiple stages to do well so let's take a look at what some of these stages look like in a bit for now I'd like to just like to note that for example the fine web data set which is fairly representative what you would see in a production grade application actually ends up being only about 44 terabyt of dis space um you can get a USB stick for like a terabyte very easily or I think this could fit on a single hard drive almost today so this is not a huge amount of data at the end of the day even though the internet is very very large we're working with text [00:02:35] and we're also filtering it aggressively so we end up with about 44 terabytes in this example so let's take a look at uh kind of what this data looks like and what some of these stages uh also are so the starting point for a lot of these efforts and something that contributes most of the data by the end of it is Data from common crawl so common craw is an organization that has been basically scouring the internet since 2007 so as of 2024 for example common CW has indexed 2.7 billion web [00:03:05] pages uh and uh they have all these crawlers going around the internet and what you end up doing basically is you start with a few seed web pages and then you follow all the links and you just keep following links and you keep indexing all the information and you end up with a ton of data of the internet over time so this is usually the starting point for a lot of the uh for a lot of these efforts now this common C data is quite raw and is filtered in many many different ways so here they Pro they document this is the same diagram they document a little [00:03:35] bit the kind of processing that happens in these stages so the first thing here is something called URL filtering so what that is referring to is that there's these block lists of uh basically URLs that are or domains that uh you don't want to be getting data from so usually this includes things like U malware websites spam websites marketing websites uh racist websites adult sites and things like that so there's a ton of different types of websites that are just eliminated at this stage because we [00:04:06] don't want them in our data set um the second part is text extraction you have to remember that all these web pages this is the raw HTML of these web pages that are being saved by these crawlers so when I go to inspect here this is what the raw HTML actually looks like you'll notice that it's got all this markup uh like lists and stuff like that and there's CSS and all this kind of stuff so this is um computer code almost for these web pages but what we really want is we just want this text right we just want the text of this web [00:04:37] page and we don't want the navigation and things like that so there's a lot of filtering and processing uh and heris that go into uh adequately filtering for just their uh good content of these web pages the next stage here is language filtering so for example fine web filters uh using a language classifier they try to guess what language every single web page is in and then they only keep web pages that have more than 65% of English as an example and so you can get a sense that this is like a design decision that [00:05:07] different companies can uh can uh take for themselves what fraction of all different types of languages are we going to include in our data set because for example if we filter out all of the Spanish as an example then you might imagine that our model later will not be very good at Spanish because it's just never seen that much data of that language and so different companies can focus on multilingual performance to uh to a different degree as an example so fine web is quite focused on English and so their language model if they end up training one later will be very good at English but not may be very good at [00:05:38] other languages after language filtering there's a few other filtering steps and D duplication and things like that um finishing with for example the pii removal this is personally identifiable information so as an example addresses Social Security numbers and things like that you would try to detect them and you would try to filter out those kinds of web pages from the the data set as well so there's a lot of stages here and I won't go into full detail but it is a fairly extensive part of the pre-processing and you end up with for [00:06:08] example the fine web data set so when you click in on it uh you can see some examples here of what this actually ends up looking like and anyone can download this on the huging phase web page and so here are some examples of the final text that ends up in the training set so this is some article about tornadoes in 2012 um so there's some t tadoes in 2020 in 2012 and what happened uh this next one is something about did you know you have two little [00:06:38] yellow 9vt battery sized adrenal glands in your body okay so this is some kind of a odd medical article so just think of these as basically uh web pages on the internet filtered just for the text in various ways and now we have a ton of text 40 terabytes off it and that now is the starting point for the next step of this stage now I wanted to give you an intuitive sense of where we are right now so I took the first 200 web pages here and remember we have tons of them [00:07:09] and I just take all that text and I just put it all together concatenate it and so this is what we end up with we just get this just just raw text raw internet text and there's a ton of it even in these 200 web pages so I can continue zooming out here and we just have this like massive tapestry of Text data and this text data has all these p patterns and what we want to do now is we want to start training neural networks on this data so the neural networks can internalize and model how this text [00:07:39] flows right so we just have this giant texture of text and now we want to get neural Nets that mimic it okay now before we plug text into neural networks we have to decide how we're going to represent this text uh and how we're going to feed it in now the way our technology works for these neuron Lots is that they expect a one-dimensional sequence of symbols and they want a finite set of symbols that are possible and so we have to decide what are the symbols and then we [00:08:10] have to represent our data as one-dimensional sequence of those symbols so right now what we have is a onedimensional sequence of text it starts here and it goes here and then it comes here Etc so this is a onedimensional sequence even though on my monitor of course it's laid out in a two-dimensional way but it goes from left to right and top to bottom right so it's a one-dimensional sequence of text now this being computers of course there's an underlying representation here so if I do what's called utf8 uh encode this text then I can get the raw [00:08:41] bits that correspond to this text in the computer and that's what uh that looks like this so it turns out that for example this very first bar here is the first uh eight bits as an example so what is this thing right this is um representation that we are looking for uh in in a certain sense we have exactly two possible symbols zero and one and we have a very long sequence of it right now as it turns out um this [00:09:14] sequence length is actually going to be very finite and precious resource uh in our neural network and we actually don't want extremely long sequences of just two symbols instead what we want is we want to trade off uh this um symbol size uh of this vocabulary as we call it and the resulting sequence length so we don't want just two symbols and extremely long sequences we're going to want more symbols and shorter sequences okay so one naive way of compressing or [00:09:44] decreasing the length of our sequence here is to basically uh consider some group of consecutive bits for example eight bits and group them into a single what's called bite so because uh these bits are either on or off if we take a group of eight of them there turns out to be only 256 possible combinations of how these bits could be on or off and so therefore we can re repesent this sequence into a sequence of bytes instead so this sequence of bytes will be eight times shorter but now we have [00:10:16] 256 possible symbols so every number here goes from 0 to 255 now I really encourage you to think of these not as numbers but as unique IDs or like unique symbols so maybe it's a bit more maybe it's better to actually think of these to replace every one of these with a unique Emoji you'd get something like this so um we basically have a sequence of emojis and there's 256 possible emojis you can think of it that way now it turns out that in production for state-of-the-art language [00:10:46] models uh you actually want to go even Beyond this you want to continue to shrink the length of the sequence uh because again it is a precious resource in return for more symbols in your vocabulary and the way this is done is done by running what's called The Bite pair encoding algorithm and the way this works is we're basically looking for consecutive bytes or symbols that are very common so for example turns out that the sequence 116 followed by 32 is [00:11:17] quite common and occurs very frequently so what we're going to do is we're going to group uh this um pair into a new symbol so we're going to Mint a symbol with an ID 256 and we're going to rewrite every single uh pair 11632 with this new symbol and then can we can iterate this algorithm as many times as we wish and each time when we mint a new symbol we're decreasing the length and we're increasing the symbol size and in practice it turns out that a pretty good setting of um the basically the [00:11:48] vocabulary size turns out to be about 100,000 possible symbols so in particular GPT 4 uses 100, 277 symbols um and this process of converting from raw text into these symbols or as we call them tokens is the process called tokenization so let's now take a look at how gp4 performs tokenization conting from text to tokens and from tokens back [00:12:18] to text and what this actually looks like so one website I like to use to explore these token representations is called tick tokenizer and so come here to the drop down and select CL 100 a base which is the gp4 base model tokenizer and here on the left you can put in text and it shows you the tokenization of that text so for example heo space world so hello world turns out to be exactly two Tokens The Token hello which [00:12:49] is the token with ID 15339 and the token space world that is the token 1 1917 so um hello space world now if I was to join these two for example I'm going to get again two tokens but it's the token H followed by the token L world without the H um if I put in two Spa two spaces here between hello and world it's again a different uh tokenization there's a new [00:13:19] token 220 here okay so you can play with this and see what happens here also keep in mind this is not uh this is case sensitive so if this is a capital H it is something else or if it's uh hello world then actually this ends up being three tokens instead of just two tokens yeah so you can play with this and get an sort of like an intuitive sense of uh what these tokens work like we're actually going to loop around to tokenization a bit later in the video [00:13:50] for now I just wanted to show you the website and I wanted to uh show you that this text basically at the end of the day so for example if I take one line here this is what GT4 will see it as so this text will be a sequence of length 62 this is the sequence here and this is how the chunks of text correspond to these symbols and again there's 100, 27777 possible symbols and we now have one-dimensional sequences of those [00:14:21] symbols so um yeah we're going to come back to tokenization but that's uh for now where we are okay so what I've done now is I've taken this uh sequence of text that we have here in the data set and I have re-represented it using our tokenizer into a sequence of tokens and this is what that looks like now so for example when we go back to the Fine web data set they mentioned that not only is this 44 terab of dis space but this is about a 15 trillion token sequence of um in this data set and so here these are [00:14:53] just some of the first uh one or two or three or a few thousand here I think uh tokens of this data set but there's 15 trillion here uh to keep in mind and again keep in mind one more time that all of these represent little text chunks they're all just like atoms of these sequences and the numbers here don't make any sense they're just uh they're just unique IDs okay so now we get to the fun part which is the uh neural network training and this is where a lot of the heavy lifting happens [00:15:23] computationally when you're training these neural networks so what we do here in this this step is we want to model the statistical relationships of how these tokens follow each other in the sequence so what we do is we come into the data and we take Windows of tokens so we take a window of tokens uh from this data fairly randomly and um the windows length can range anywhere anywhere between uh zero tokens actually all the way up to some [00:15:54] maximum size that we decide on uh so for example in practice you could see a token with Windows of say 8,000 tokens now in principle we can use arbitrary window lengths of tokens uh but uh processing very long uh basically U window sequences would just be very computationally expensive so we just kind of decide that say 8,000 is a good number or 4,000 or 16,000 and we crop it there now in this example I'm going to be uh taking the first four tokens just [00:16:25] so everything fits nicely so these tokens we're going to take a window of four tokens this bar view in and space single which are these token IDs and now what we're trying to do here is we're trying to basically predict the token that comes next in the sequence so 3962 comes next right so what we do now here is that we call this the context these four tokens are context and they feed into a neural [00:16:56] network and this is the input to the neural network now I'm going to go into the detail of what's inside this neural network in a little bit for now it's important to understand is the input and the output of the neural net so the input are sequences of tokens of variable length anywhere between zero and some maximum size like 8,000 the output now is a prediction for what comes next so because our vocabulary has 100277 possible tokens the neural [00:17:26] network is going to Output exactly that many numbers and all of those numbers correspond to the probability of that token as coming next in the sequence so it's making guesses about what comes next um in the beginning this neural network is randomly initialized so um and we're going to see in a little bit what that means but it's a it's a it's a random transformation so these probabilities in the very beginning of the training are also going to be kind of random uh so here I have three examples but keep in mind that there's 100,000 numbers here um so the [00:17:58] probability of this token space Direction neural network is saying that this is 4% likely right now 11799 is 2% and then here the probility of 3962 which is post is 3% now of course we've sampled this window from our data set so we know what comes next we know and that's the label we know that the correct answer is that 3962 actually comes next in the sequence so now what we have is this mathematical process for doing an update to the neural network we [00:18:28] have the way of tuning it and uh we're going to go into a little bit of of detail in a bit but basically we know that this probability here of 3% we want this probability to be higher and we want the probabilities of all the other tokens to be lower and so we have a way of mathematically calculating how to adjust and update the neural network so that the correct answer has a slightly higher probability so if I do an update to the neural network now the next time I Fe [00:18:59] this particular sequence of four tokens into neural network the neural network will be slightly adjusted now and it will say Okay post is maybe 4% and case now maybe is 1% and uh Direction could become 2% or something like that and so we have a way of nudging of slightly updating the neuronet to um basically give a higher probability to the correct token that comes next in the sequence and now you just have to remember that this process happens not just for uh this um token [00:19:29] here where these four fed in and predicted this one this process happens at the same time for all of these tokens in the entire data set and so in practice we sample little windows little batches of Windows and then at every single one of these tokens we want to adjust our neural network so that the probability of that token becomes slightly higher and this all happens in parallel in large batches of these tokens and this is the process of training the neural network it's a sequence of updating it so that it's predictions match up the statistics of [00:20:01] what actually happens in your training set and its probabilities become consistent with the uh statistical patterns of how these tokens follow each other in the data so let's now briefly get into the internals of these neural networks just to give you a sense of what's inside so neural network internals so as I mentioned we have these inputs uh that are sequences of tokens in this case this is four input tokens but this can be anywhere between zero up to let's say 8,000 tokens in principle this can be an infinite number [00:20:31] of tokens we just uh it would just be too computationally expensive to process an infinite number of tokens so we just crop it at a certain length and that becomes the maximum context length of that uh model now these inputs X are mixed up in a giant mathematical expression together with the parameters or the weights of these neural networks so here I'm showing six example parameters and their setting but in practice these uh um modern neural networks will have [00:21:01] billions of these uh parameters and in the beginning these parameters are completely randomly set now with a random setting of parameters you might expect that this uh this neural network would make random predictions and it does in the beginning it's totally random predictions but it's through this process of iteratively updating the network uh as and we call that process training a neural network so uh that the setting of these parameters gets adjusted such that the outputs of our [00:21:31] neural network becomes consistent with the patterns seen in our training set so think of these parameters as kind of like knobs on a DJ set and as you're twiddling these knobs you're getting different uh predictions for every possible uh token sequence input and training in neural network just means discovering a setting of parameters that seems to be consistent with the statistics of the training set now let me just give you an example what this giant mathematical expression looks like just to give you a sense and [00:22:01] modern networks are massive expressions with trillions of terms probably but let me just show you a simple example here it would look something like this I mean these are the kinds of Expressions just to show you that it's not very scary we have inputs x uh like X1 x2 in this case two example inputs and they get mixed up with the weights of the network w0 W1 2 3 Etc and this mixing is simple things like multiplication addition addition exponentiation division Etc and it is [00:22:32] the subject of neural network architecture research to design effective mathematical Expressions uh that have a lot of uh kind of convenient characteristics they are expressive they're optimizable they're paralyzable Etc and so but uh at the end of the day these are these are not complex expressions and basically they mix up the inputs with the parameters to make predictions and we're optimizing uh the parameters of this neural network so that the predictions come out consistent with the training set now I would like [00:23:04] to show you an actual production grade example of what these neural networks look like so for that I encourage you to go to this website that has a very nice visualization of one of these networks so this is what you will find on this website and this neural network here that is used in production settings has this special kind of structure this network is called the Transformer and this particular one as an example has 8 5,000 roughly parameters now here on the top we take the inputs which are the token [00:23:36] sequences and then information flows through the neural network until the output which here are the logit softmax but these are the predictions for what comes next what token comes next and then here there's a sequence of Transformations and all these intermediate values that get produced inside this mathematical expression s it is sort of predicting what comes next so as an example these tokens are embedded into kind of like this distributed [00:24:06] representation as it's called so every possible token has kind of like a vector that represents it inside the neural network so first we embed the tokens and then those values uh kind of like flow through this diagram and these are all very simple mathematical Expressions individually so we have layer norms and Matrix multiplications and uh soft Maxes and so on so here kind of like the attention block of this Transformer and then information kind of flows through into the multi-layer perceptron block and so on and all these numbers here [00:24:38] these are the intermediate values of the expression and uh you can almost think of these as kind of like the firing rates of these synthetic neurons but I would caution you to uh not um kind of think of it too much like neurons because these are extremely simple neurons compared to the neurons you would find in your brain your biological neurons are very complex dynamical processes that have memory and so on there's no memory in this expression it's a fixed mathematical expression from input to Output with no memory it's just a stateless so these are very simple [00:25:09] neurons in comparison to biological neurons but you can still kind of loosely think of this as like a synthetic piece of uh brain tissue if you if you like uh to think about it that way so information flows through all these neurons fire until we get to the predictions now I'm not actually going to dwell too much on the precise kind of like mathematical details of all these Transformations honestly I don't think it's that important to get into what's really important to understand is that this is a mathematical function it is uh parameterized by some fixed set of [00:25:41] parameters like say 85,000 of them and it is a way of transforming inputs into outputs and as we twiddle the parameters we are getting uh different kinds of predictions and then we need to find a good setting of these parameters so that the predictions uh sort of match up with the patterns seen in training set so that's the Transformer okay so I've shown you the internals of the neural network and we talked a bit about the process of training it I want to cover one more major stage of working with these networks and that is the stage [00:26:11] called inference so in inference what we're doing is we're generating new data from the model and so uh we want to basically see what kind of patterns it has internalized in the parameters of its Network so to generate from the model is relatively straightforward we start with some tokens that are basically your prefix like what you want to start with so say we want to start with the token 91 well we feed it into the network and remember that the network gives us probabilities right it gives us [00:26:43] this probability Vector here so what we can do now is we can basically flip a biased coin so um we can sample uh basically a token based on this probability distribution so the tokens that are given High probability by the model are more likely to be sampled when you flip this biased coin you can think of it that way so we sample from the distribution to get a single unique token so for example token 860 comes next uh so 860 in this case when we're [00:27:14] generating from model could come next now 860 is a relatively likely token it might not be the only possible token in this case there could be many other tokens that could have been sampled but we could see that 86c is a relatively likely token as an example and indeed in our training examp example here 860 does follow 91 so let's now say that we um continue the process so after 91 there's a60 we append it and we again ask what is the third token let's sample and let's just say that it's 287 exactly as [00:27:44] here let's do that again we come back in now we have a sequence of three and we ask what is the likely fourth token and we sample from that and get this one and now let's say we do it one more time we take those four we sample and we get this one and this 13659 uh this is not actually uh 3962 as we had before so this token is the token article uh instead so viewing a single article and so in this case we didn't [00:28:15] exactly reproduce the sequence that we saw here in the training data so keep in mind that these systems are stochastic they have um we're sampling and we're flipping coins and sometimes we lock out and we reproduce some like small chunk of the text and training set but sometimes we're uh we're getting a token that was not verbatim part of any of the documents in the training data so we're going to get sort of like remixes of the data that we saw in the training because at every step of the way we can flip and [00:28:47] get a slightly different token and then once that token makes it in if you sample the next one and so on you very quickly uh start to generate token streams that are very different from the token streams that UR in the training documents so statistically they will have similar properties but um they are not identical to your training data they're kind of like inspired by the training data and so in this case we got a slightly different sequence and why would we get article you might imagine that article is a relatively likely token in the context of bar viewing single Etc and [00:29:21] you can imagine that the word article followed this context window somewhere in the training documents uh to some extent and we just happen to sample it here at that stage so basically inference is just uh predicting from these distributions one at a time we continue feeding back tokens and getting the next one and we uh we're always flipping these coins and depending on how lucky or unlucky we get um we might get very different kinds of patterns depending on how we sample from these probability distributions so that's [00:29:51] inference so in most common scenarios uh basically downloading the internet and tokenizing it is is a pre-processing step you do that a single time and then uh once you have your token sequence we can start training networks and in Practical cases you would try to train many different networks of different kinds of uh settings and different kinds of arrangements and different kinds of sizes and so you''ll be doing a lot of neural network training and um then once you have a neural network and you train it and you have some specific set of [00:30:21] parameters that you're happy with um then you can take the model and you can do inference and you can actually uh generate data from the model and when you're on chat GPT and you're talking with a model uh that model is trained and has been trained by open aai many months ago probably and they have a specific set of Weights that work well and when you're talking to the model all of that is just inference there's no more training those parameters are held fixed and you're just talking to the model sort of uh you're giving it some [00:30:51] of the tokens and it's kind of completing token sequences and that's what you're seeing uh generated when you actually use the model on CH GPT so that model then just does inference alone so let's now look at an example of training an inference that is kind of concrete and gives you a sense of what this actually looks like uh when these models are trained now the example that I would like to work with and that I'm particularly fond of is that of opening eyes gpt2 so GPT uh stands for generatively pre-trained Transformer and this is the second iteration of the GPT [00:31:21] series by open AI when you are talking to chat GPT today the model that is underlying all of the magic of that interaction is GPT 4 so the fourth iteration of that series now gpt2 was published in 2019 by openi in this paper that I have right here and the reason I like gpt2 is that it is the first time that a recognizably modern stack came together so um all of the pieces of gpd2 are recognizable today by modern standards it's just everything has [00:31:52] gotten bigger now I'm not going to be able to go into the full details of this paper of course because it is a technical publication but some of the details that I would like to highlight are as follows gpt2 was a Transformer neural network just like you were just like the neural networks you would work with today it was it had 1.6 billion parameters right so these are the parameters that we looked at here it would have 1.6 billion of them today modern Transformers would have a lot closer to a trillion or several hundred billion probably the maximum context length here [00:32:24] was 1,24 tokens so it is when we are sampling chunks of Windows of tokens from the data set we're never taking more than 1,24 tokens and so when you are trying to predict the next token in a sequence you will never have more than 1,24 tokens uh kind of in your context in order to make that prediction now this is also tiny by modern standards today the token uh the context lengths would be a lot closer to um couple hundred thousand or maybe even a million [00:32:55] and so you have a lot more context a lot more tokens in history history and you can make a lot better prediction about the next token in the sequence in that way and finally gpt2 was trained on approximately 100 billion tokens and this is also fairly small by modern standards as I mentioned the fine web data set that we looked at here the fine web data set has 15 trillion tokens uh so 100 billion is is quite small now uh I actually tried to reproduce uh gpt2 for fun as part of this project called lm. C so you can see my rup of [00:33:27] doing that in this post on GitHub under the lm. C repository so in particular the cost of training gpd2 in 2019 what was estimated to be approximately $40,000 but today you can do significantly better than that and in particular here it took about one day and about $600 uh but this wasn't even trying too hard I think you could really bring this down to about $100 today now why is it that the costs have come down so much [00:33:57] well number one these data sets have gotten a lot better and the way we filter them extract them and prepare them has gotten a lot more refined and so the data set is of just a lot higher quality so that's one thing but really the biggest difference is that our computers have gotten much faster in terms of the hardware and we're going to look at that in a second and also the software for uh running these models and really squeezing out all all the speed from the hardware as it is possible uh that software has also gotten much [00:34:27] better as as everyone has focused on these models and try to run them very very quickly now I'm not going to be able to go into the full detail of this gpd2 reproduction and this is a long technical post but I would like to still give you an intuitive sense for what it looks like to actually train one of these models as a researcher like what are you looking at and what does it look like what does it feel like so let me give you a sense of that a little bit okay so this is what it looks like let me slide this over so what I'm doing here is I'm training a gpt2 model right now [00:34:58] and um what's happening here is that every single line here like this one is one update to the model so remember how here we are um basically making the prediction better for every one of these tokens and we are updating these weights or parameters of the neural net so here every single line is One update to the neural network where we change its parameters by a little bit so that it is better at predicting next token and sequence in particular every single line [00:35:28] here is improving the prediction on 1 million tokens in the training set so we've basically taken 1 million tokens out of this data set and we've tried to improve the prediction of that token as coming next in a sequence on all 1 million of them simultaneously and at every single one of these steps we are making an update to the network for that now the number to watch closely is this number called loss and the loss is a single number [00:36:00] that is telling you how well your neural network is performing right now and it is created so that low loss is good so you'll see that the loss is decreasing as we make more updates to the neural nut which corresponds to making better predictions on the next token in a sequence and so the loss is the number that you are watching as a neural network researcher and you are kind of waiting you're twiddling your thumbs uh you're drinking coffee and you're making sure that this looks good so that with every update your loss is improving and [00:36:31] the network is getting better at prediction now here you see that we are processing 1 million tokens per update each update takes about 7 Seconds roughly and here we are going to process a total of 32,000 steps of optimization so 32,000 steps with 1 million tokens each is about 33 billion tokens that we are going to process and we're currently only about 420 step 20 out of 32,000 so we are still only a bit [00:37:01] more than 1% done because I've only been running this for 10 or 15 minutes or something like that now every 20 steps I have configured this optimization to do inference so what you're seeing here is the model is predicting the next token in a sequence and so you sort of start it randomly and then you continue plugging in the tokens so we're running this inference step and this is the model sort of predicting the next token in the sequence and every time you see something appear that's a new token um so let's just look at this and [00:37:34] you can see that this is not yet very coherent and keep in mind that this is only 1% of the way through training and so the model is not yet very good at predicting the next token in the sequence so what comes out is actually kind of a little bit of gibberish right but it still has a little bit of like local coherence so since she is mine it's a part of the information should discuss my father great companions Gordon showed me sitting over at and Etc so I know it doesn't look very good but let's actually scroll up and see what it [00:38:04] looked like when I started the optimization so all the way here at step one so after 20 steps of optimization you see that what we're getting here is looks completely random and of course that's because the model has only had 20 updates to its parameters and so it's giving you random text because it's a random Network and so you can see that at least in comparison to this model is starting to do much better and indeed if we waited the entire 32,000 steps the model will have improved the point that [00:38:34] it's actually uh generating fairly coherent English uh and the tokens stream correctly um and uh they they kind of make up English a a lot better um so this has to run for about a day or two more now and so uh at this stage we just make sure that the loss is decreasing everything is looking good um and we just have to wait and now um let me turn now to the um story of the computation that's required [00:39:05] because of course I'm not running this optimization on my laptop that would be way too expensive uh because we have to run this neural network and we have to improve it and we have we need all this data and so on so you can't run this too well on your computer uh because the network is just too large uh so all of this is running on the computer that is out there in the cloud and I want to basically address the compute side of the store of training these models and what that looks like so let's take a look okay so the computer that I'm running this optimization on is this 8X [00:39:35] h100 node so there are eight h100s in a single node or a single computer now I am renting this computer and it is somewhere in the cloud I'm not sure where it is physically actually the place I like to rent from is called Lambda but there are many other companies who provide this service so when you scroll down you can see that uh they have some on demand pricing for um sort of computers that have these uh h100s which are gpus and I'm going to show you what they look like in a second [00:40:06] but on demand 8times Nvidia h100 uh GPU this machine comes for $3 per GPU per hour for example so you can rent these and then you get a machine in a cloud and you can uh go in and you can train these models and these uh gpus they look like this so this is one h100 GPU uh this is kind of what it looks like and you slot this into your computer and gpus are this uh perfect fit for training your networks because they are very [00:40:36] computationally expensive but they display a lot of parallelism in the computation so you can have many independent workers kind of um working all at the same time in solving uh the matrix multiplication that's under the hood of training these neural networks so this is just one of these h100s but actually you would put them you would put multiple of them together so you could stack eight of them into a single node and then you can stack multiple nodes into an entire data center or an entire system [00:41:07] so when we look at a data center can't spell when we look at a data center we start to see things that look like this right so we have one GPU goes to eight gpus goes to a single system goes to many systems and so these are the bigger data centers and there of course would be much much more expensive um and what's happening is that all the big tech companies really desire these gpus so they can train all these language models because they are so powerful and that has is fundamentally [00:41:37] what has driven the stock price of Nvidia to be $3.4 trillion today as an example and why Nvidia has kind of exploded so this is the Gold Rush the Gold Rush is getting the gpus getting enough of them so they can all collaborate to perform this optimization and they're what are they all doing they're all collaborating to predict the next token on a data set like the fine web data set this is the computational workflow that that basically is extremely expensive the more gpus you have the [00:42:09] more tokens you can try to predict and improve on and you're going to process this data set faster and you can iterate faster and get a bigger Network and train a bigger Network and so on so this is what all those machines are look like are uh are doing and this is why all of this is such a big deal and for example this is a article from like about a month ago or so this is why it's a big deal that for example Elon Musk is getting 100,000 gpus uh in a single Data Center and all of these gpus are extremely expensive [00:42:40] are going to take a ton of power and all of them are just trying to predict the next token in the sequence and improve the network uh by doing so and uh get probably a lot more coherent text than what we're seeing here a lot faster okay so unfortunately I do not have a couple 10 or hundred million of dollars to spend on training a really big model like this but luckily we can turn to some big tech companies who train these models routinely and release some of them once they are done training so they've spent a huge amount of compute [00:43:10] to train this network and they release the network at the end of the optimization so it's very useful because they've done a lot of compute for that so there are many companies who train these models routinely but actually not many of them release uh these what's called base models so the model that comes out at the end here is is what's called a base model what is a base model it's a token simulator right it's an internet text token simulator and so that is not by itself useful yet because what we want is what's called an assistant we want to ask questions and [00:43:41] have it respond to answers these models won't do that they just uh create sort of remixes of the internet they dream internet pages so the base models are not very often released because they're kind of just only a step one of a few other steps that we still need to take to get in system however a few releases have been made so as an example the gbt2 model released the 1.6 billion sorry 1.5 billion model back in 2019 and this gpt2 model is a base model now what is a model release [00:44:13] what does it look like to release these models so this is the gpt2 repository on GitHub well you need two things basically to release model number one we need the um python code usually that describes the sequence of operations in detail that they make in their model so um if you remember back this Transformer the sequence of steps that are taken here in this neural network is what is being described by this code so [00:44:45] this code is sort of implementing the what's called forward pass of this neural network so we need the specific details of exactly how they wired up that neural network so this is just computer code and it's usually just a couple hundred lines of code it's not it's not that crazy and uh this is all fairly understandable and usually fairly standard what's not standard are the parameters that's where the actual value is what are the parameters of this neural network because there's 1.6 billion of them and we need the correct setting or a really good setting and so [00:45:15] that's why in addition to this source code they release the parameters which in this case is roughly 1.5 billion parameters and these are just numbers so it's one single list of 1.5 billion numbers the precise and good setting of all the knobs such that the tokens come out well so uh you need those two things to get a base model release now gpt2 was released but that's actually a fairly old model as I mentioned so actually the model we're [00:45:46] going to turn to is called llama 3 and that's the one that I would like to show you next so llama 3 so gpt2 again was 1.6 billion parameters trained on 100 billion tokens Lama 3 is a much bigger model and much more modern model it is released and trained by meta and it is a 45 billion parameter model trained on 15 trillion tokens in very much the same way just much much bigger um and meta has also made a release of llama 3 and that was part of [00:46:18] this paper so with this paper that goes into a lot of detail the biggest base model that they released is the Lama 3.1 4.5 405 billion parameter model so this is the base model and then in addition to the base model you see here foreshadowing for later sections of the video they also released the instruct model and the instruct means that this is an assistant you can ask it questions and it will give you answers we still have yet to cover that part later for now let's just look at this base model this token simulator and let's play with [00:46:49] it and try to think about you know what is this thing and how does it work and um what do we get at the end of this optimization if you let this run Until the End uh for a very big neural network on a lot of data so my favorite place to interact with the base models is this um company called hyperbolic which is basically serving the base model of the 405b Llama 3.1 so when you go to the website and I think you may have to register and so on make sure that in the models make sure that you are using llama 3.1 405 billion base it must be [00:47:22] the base model and then here let's say the max tokens is how many tokens we're going to be gener rating so let's just decrease this to be a bit less just so we don't waste compute we just want the next 128 tokens and leave the other stuff alone I'm not going to go into the full detail here um now fundamentally what's going to happen here is identical to what happens here during inference for us so this is just going to continue the token sequence of whatever you prefix you're going to give it so I want to first show you that this model here is not yet an assistant so you can for [00:47:53] example ask it what is 2 plus 2 it's not going to tell you oh it's four uh what else can I help you with it's not going to do that because what is 2 plus 2 is going to be tokenized and then those tokens just act as a prefix and then what the model is going to do now is just going to get the probability for the next token and it's just a glorified autocomplete it's a very very expensive autocomplete of what comes next um depending on the statistics of what it saw in its training documents which are basically web pages so let's just uh hit enter to see [00:48:25] what tokens it comes up with as a continuation okay so here it kind of actually answered the question and started to go off into some philosophical territory uh let's try it again so let me copy and paste and let's try again from scratch what is 2 plus two so okay so it just goes off again so notice one more thing that I want to stress is that the system uh I think every time you put it in it just kind of [00:48:55] starts from scratch so it doesn't uh the system here is stochastic so for the same prefix of tokens we're always getting a different answer and the reason for that is that we get this probity distribution and we sample from it and we always get different samples and we sort of always go into a different territory uh afterwards so here in this case um I don't know what this is let's try one more time so it just continues on so it's [00:49:25] just doing the stuff that it's saw on the internet right um and it's just kind of like regurgitating those uh statistical patterns so first things it's not an assistant yet it's a token autocomplete and second it is a stochastic system now the crucial thing is that even though this model is not yet by itself very useful for a lot of applications just yet um it is still very useful because in the task of predicting the next token in the sequence the model has learned a [00:49:56] lot about the world and it has stored all that knowledge in the parameters of the network so remember that our text looked like this right internet web pages and now all of this is sort of compressed in the weights of the network so you can think of um these 405 billion parameters is a kind of compression of the internet you can think of the 45 billion parameters is kind of like a zip file uh but it's not a loss less compression it's a loss C compression [00:50:27] we're kind of like left with kind of a gal of the internet and we can generate from it right now we can elicit some of this knowledge by prompting the base model uh accordingly so for example here's a prompt that might work to elicit some of that knowledge that's hiding in the parameters here's my top 10 list of the top landmarks to see in the pairs um and I'm doing it this way because I'm trying to Prime the model to now continue this list so let's see if that works when I press [00:50:57] enter okay so you see that it started a list and it's now kind of giving me some of those landmarks and now notice that it's trying to give a lot of information here now you might not be able to actually fully trust some of the information here remember that this is all just a recollection of some of the internet documents and so the things that occur very frequently in the internet data are probably more likely to be remembered correctly compared to things that happen very infrequently so you can't fully trust some of the things that and some [00:51:27] of the information that is here because it's all just a vague recollection of Internet documents because the information is not stored explicitly in any of the parameters it's all just the recollection that said we did get something that is probably approximately correct and I don't actually have the expertise to verify that this is roughly correct but you see that we've elicited a lot of the knowledge of the model and this knowledge is not precise and exact this knowledge is vague and probabilistic and statistical and the kinds of things that occur often are the [00:51:57] kinds of things that are more likely to be remembered um in the model now I want to show you a few more examples of this model's Behavior the first thing I want to show you is this example I went to the Wikipedia page for zebra and let me just copy paste the first uh even one sentence here and let me put it here now when I click enter what kind of uh completion are we going to get so let me just hit enter there are three living species etc etc what the model is producing here [00:52:29] is an exact regurgitation of this Wikipedia entry it is reciting this Wikipedia entry purely from memory and this memory is stored in its parameters and so it is possible that at some point in these 512 tokens the model will uh stray away from the Wikipedia entry but you can see that it has huge chunks of it memorized here uh let me see for example if this sentence occurs by now okay so this so we're still on track let me check here okay we're still on [00:53:00] track it will eventually uh stray away okay so this thing is just recited to a very large extent it will eventually deviate uh because it won't be able to remember exactly now the reason that this happens is because these models can be extremely good at memorization and usually this is not what you want in the final model and this is something called regurgitation and it's usually undesirable to site uh things uh directly uh that you have trained on now the reason that this happens actually is because for a lot of [00:53:31] documents like for example Wikipedia when these documents are deemed to be of very high quality as a source like for example Wikipedia it is very often uh the case that when you train the model you will preferentially sample from those sources so basically the model has probably done a few epochs on this data meaning that it has seen this web page like maybe probably 10 times or so and it's a bit like you like when you read some kind of a text many many times say you read something a 100 times uh then you'll be able to recite it and it's very similar for this model if it sees [00:54:01] something way too often it's going to be able to recite it later from memory except these models can be a lot more efficient um like per presentation than human so probably it's only seen this Wikipedia entry 10 times but basically it has remembered this article exactly in its parameters okay the next thing I want to show you is something that the model has definitely not seen during its training so for example if we go to the paper uh and then we navigate to the pre-training data we'll see here that uh [00:54:31] the data set has a knowledge cut off until the end of 2023 so it will not have seen documents after this point and certainly it has not seen anything about the 2024 election and how it turned out now if we Prime the model with the tokens from the future it will continue the token sequence and it will just take its best guess according to the knowledge that it has in its own parameters so let's take a look at what that could look like so the Republican Party kit Trump okay president of the United [00:55:01] States from 2017 and let's see what it says after this point so for example the model will have to guess at the running mate and who it's against Etc so let's hit enter so here thingss that Mike Pence was the running mate instead of JD Vance and the ticket was against Hillary Clinton and Tim Kane so this is kind of a interesting parallel universe potentially of what could have happened happened according to the LM let's get a different sample so the identical prompt [00:55:31] and let's resample so here the running mate was Ronda santis and they ran against Joe Biden and Camala Harris so this is again a different parallel universe so the model will take educated guesses and it will continue the token sequence based on this knowledge um and it will just kind of like all of what we're seeing here is what's called hallucination the model is just taking its best guess uh in a probalistic manner the next thing I would like to show you is that even though this is a base model and not yet an assistant model it can still be [00:56:02] utilized in Practical applications if you are clever with your prompt design so here's something that we would call a few shot prompt so what it is here is that I have 10 words or 10 pairs and each pair is a word of English column and then a the translation in Korean and we have 10 of them and what the model does here is at the end we have teacher column and then here's where we're going to do a completion of say just five tokens and these models have what we call in [00:56:33] context learning abilities and what that's referring to is that as it is reading this context it is learning sort of in place that there's some kind of a algorithmic pattern going on in my data and it knows to continue that pattern and this is called kind of like Inc context learning so it takes on the role of a translator and when we hit uh completion we see that the teacher translation is Sim which is correct um and so this is [00:57:03] how you can build apps by being clever with your prompting even though we still just have a base model for now and it relies on what we call this um uh in context learning ability and it is done by constructing what's called a few shot prompt okay and finally I want to show you that there is a clever way to actually instantiate a whole language model assistant just by prompting and the trick to it is that we're structure a prompt to look like a web page that is a conversation between a helpful AI assistant and a human and then the model [00:57:34] will continue that conversation so actually to write the prompt I turned to chat gbt itself which is kind of meta but I told it I want to create an llm assistant but all I have is the base model so can you please write my um uh prompt and this is what it came up with which is actually quite good so here's a conversation between an AI assistant and a human the AI assistant is knowledgeable helpful capable of answering wide variety of questions Etc and then here it's not enough to just give it a sort [00:58:05] of description it works much better if you create this fot prompt so here's a few terms of human assistant human assistant and we have uh you know a few turns of conversation and then here at the end is we're going to be putting the actual query that we like so let me copy paste this into the base model prompt and now let me do human column and this is where we put our actual prompt why is the sky blue and uh let's uh [00:58:37] run assistant the sky appears blue due to the phenomenon called R lights scattering etc etc so you see that the base model is just continuing the sequence but because the sequence looks like this conversation it takes on that role but it is a little subtle because here it just uh you know it ends the assistant and then just you know hallucinate Ates the next question by the human Etc so it'll just continue going on and on uh but you can see that we have sort of accomplished the task and if you just took this why is the sky blue and if we just refresh this and put [00:59:09] it here then of course we don't expect this to work with a base model right we're just going to who knows what we're going to get okay we're just going to get more questions okay so this is one way to create an assistant even though you may only have a base model okay so this is the kind of brief summary of the things we talked about over the last few minutes now let me zoom out here and this is kind of like what we've talked about so far we wish to train LM assistants like chpt we've discussed the [00:59:40] first stage of that which is the pre-training stage and we saw that really what it comes down to is we take Internet documents we break them up into these tokens these atoms of little text chunks and then we predict token sequences using neural networks the output of this entire stage is this base model it is the setting of The parameters of this network and this base model is basically an internet document simulator on the token level so it can just uh it can generate token sequences that have the same kind of like [01:00:10] statistics as Internet documents and we saw that we can use it in some applications but we actually need to do better we want an assistant we want to be able to ask questions and we want the model to give us answers and so we need to now go into the second stage which is called the post-training stage so we take our base model our internet document simulator and hand it off to post training so we're now going to discuss a few ways to do what's called post training of these models these stages in post training are going to be computationally much less expensive most [01:00:40] of the computational work all of the massive data centers um and all of the sort of heavy compute and millions of dollars are the pre-training stage but now we go into the slightly cheaper but still extremely important stage called post trining where we turn this llm model into an assistant so let's take a look at how we can get our model to not sample internet documents but to give answers to questions so in other words what we want to do is we want to start thinking about conversations and these [01:01:10] are conversations that can be multi-turn so so uh there can be multiple turns and they are in the simplest case a conversation between a human and an assistant and so for example we can imagine the conversation could look something like this when a human says what is 2 plus2 the assistant should re respond with something like 2 plus 2 is 4 when a human follows up and says what if it was star instead of a plus assistant could respond with something like this um and similar here this is another example showing that the assistant could also have some kind of a personality here uh that it's kind of like nice and [01:01:41] then here in the third example I'm showing that when a human is asking for something that we uh don't wish to help with we can produce what's called refusal we can say that we cannot help with that so in other words what we want to do now is we want to think through how in a system should interact with the human and we want to program the assistant and Its Behavior in these conversations now because this is neural networks we're not going to be programming these explicitly in code we're not going to be able to program the assistant in that way because this is neural networks everything is done [01:02:12] through neural network training on data sets and so because of that we are going to be implicitly programming the assistant by creating data sets of conversations so these are three independent examples of conversations in a data dat set an actual data set and I'm going to show you examples will be much larger it could have hundreds of thousands of conversations that are multi- turn very long Etc and would cover a diverse breath of topics but here I'm only showing three examples but the way this works basically is uh a [01:02:42] assistant is being programmed by example and where is this data coming from like 2 * 2al 4 same as 2 plus 2 Etc where does that come from this comes from Human labelers so we will basically give human labelers some conversational context and we will ask them to um basically give the ideal assistant response in this situation and a human will write out the ideal response for an assistant in any situation and then we're going to get the model to basically train on this and to imitate [01:03:12] those kinds of responses so the way this works then is we are going to take our base model which we produced in the preing stage and this base model was trained on internet documents we're now going to take that data set of internet documents and we're gonna throw it out and we're going to substitute a new data set and that's going to be a data set of conversations and we're going to continue training the model on these conversations on this new data set of conversations and what happens is that the model will very rapidly adjust and will sort of like learn the statistics [01:03:42] of how this assistant responds to human queries and then later during inference we'll be able to basically um Prime the assistant and get the response and it will be imitating what the humans will human labelers would do in that situation if that makes sense so we're going to see examples of that and this is going to become bit more concrete I also wanted to mention that this post-training stage we're going to basically just continue training the model but um the pre-training stage can in practice take roughly three months of [01:04:13] training on many thousands of computers the post-training stage will typically be much shorter like 3 hours for example um and that's because the data set of conversations that we're going to create here manually is much much smaller than the data set of text on the internet and so this training will be very short but fundamentally we're just going to take our base model we're going to continue training using the exact same algorithm the exact same everything except we're swapping out the data set for conversations so the questions now are [01:04:43] what are these conversations how do we represent them how do we get the model to see conversations instead of just raw text and then what are the outcomes of um this kind of training and what do you get in a certain like psychological sense uh when we talk about the model so let's turn to those questions now so let's start by talking about the tokenization of conversations everything in these models has to be turned into tokens because everything is just about token sequences so how do we turn conversations into token sequences is the question and so for that we need to [01:05:15] design some kind of ending coding and uh this is kind of similar to maybe if you're familiar you don't have to be with for example the TCP IP packet in um on the internet there are precise rules and protocols for how you represent information how everything is structured together so that you have all this kind of data laid out in a way that is written out on a paper and that everyone can agree on and so it's the same thing now happening in llms we need some kind of data structures and we need to have some rules around how these data structures like conversations get encoded and decoded to and from tokens [01:05:46] and so I want to show you now how I would recreate uh this conversation in the token space so if you go to Tech tokenizer I can take that conversation and this is how it is represented in uh for the language model so here we have we are iterating a user and an assistant in this two- turn conversation and what you're seeing here is it looks ugly but it's actually relatively simple the way it gets turned into a token sequence here at the end is [01:06:16] a little bit complicated but at the end this conversation between a user and assistant ends up being 49 tokens it is a one-dimensional sequence of 49 tokens and these are the tokens okay and all the different llms will have a slightly different format or protocols and it's a little bit of a wild west right now but for example GPT 40 does it in the following way you have this special token called imore start and this is short for IM imaginary monologue uh the [01:06:46] start then you have to specify um I don't actually know why it's called that to be honest then you have to specify whose turn it is so for example user which is a token 4 28 then you have internal monologue separator and then it's the exact question so the tokens of the question and then you have to close it so I am end the end of the imaginary monologue so basically the question from a user of what is 2 plus two ends up being the [01:07:16] token sequence of these tokens and now the important thing to mention here is that IM start this is not text right IM start is a special token that gets added it's a new token and um this token has never been trained on so far it is a new token that we create in a post-training stage and we introduce and so these special tokens like IM seep IM start Etc are introduced and interspersed with text so that they sort of um get the model to learn that hey this is a the [01:07:47] start of a turn for who is it start of the turn for the start of the turn is for the user and then this is what the user says and then the user ends and then it's a new start of a turn and it is by the assistant and then what does the assistant say well these are the tokens of what the assistant says Etc and so this conversation is not turned into the sequence of tokens the specific details here are not actually that important all I'm trying to show you in concrete terms is that our conversations which we think of as kind of like a structured object end up being turned [01:08:19] via some encoding into onedimensional sequences of tokens and so because this is one dimensional sequence of tokens we can apply all the stuff that we applied before now it's just a sequence of tokens and now we can train a language model on it and so we're just predicting the next token in a sequence uh just like before and um we can represent and train on conversations and then what does it look like at test time during inference so say we've trained a model and we've trained a model on these kinds [01:08:49] of data sets of conversations and now we want to inference so during inference what does this look like when you're on on chash apt well you come to chash apt and you have say like a dialogue with it and the way this works is basically um say that this was already filled in so like what is 2 plus 2 2 plus 2 is four and now you issue what if it was times I am end and what basically ends up happening um on the servers of open AI or something like that is they put in I start assistant I amep and this [01:09:21] is where they end it right here so they construct this context and now they start sampling from the model so it's at this stage that they will go to the model and say okay what is a good for sequence what is a good first token what is a good second token what is a good third token and this is where the LM takes over and creates a response like for example response that looks something like this but it doesn't have to be identical to this but it will have the flavor of this if this kind of a conversation was in the data set so um [01:09:52] that's roughly how the protocol Works although the details of this protocol are not important so again my goal is that just to show you that everything ends up being just a one-dimensional token sequence so we can apply everything we've already seen but we're now training on conversations and we're now uh basically generating conversations as well okay so now I would like to turn to what these data sets look like in practice the first paper that I would like to show you and the first effort in this direction is this paper from openai in 2022 and this [01:10:23] paper was called instruct GPT or the technique that they developed and this was the first time that opena has kind of talked about how you can take language models and fine-tune them on conversations and so this paper has a number of details that I would like to take you through so the first stop I would like to make is in section 3.4 where they talk about the human contractors that they hired uh in this case from upwork or through scale AI to uh construct these conversations and so there are human labelers involved whose job it is professionally to create these [01:10:54] conversations and these labelers are asked to come up with prompts and then they are asked to also complete the ideal assistant responses and so these are the kinds of prompts that people came up with so these are human labelers so list five ideas for how to regain enthusiasm for my career what are the top 10 science fiction books I should read next and there's many different types of uh kind of prompts here so translate this sentence from uh to Spanish Etc and so there's many things here that people came up with they first come up with the prompt and then they [01:11:25] also uh answer that prompt and they give the ideal assistant response now how do they know what is the ideal assistant response that they should write for these prompts so when we scroll down a little bit further we see that here we have this excerpt of labeling instructions uh that are given to the human labelers so the company that is developing the language model like for example open AI writes up labeling instructions for how the humans should create ideal responses and so here for example is an excerpt uh of these kinds of labeling instruction instructions on [01:11:56] High level you're asking people to be helpful truthful and harmless and you can pause the video if you'd like to see more here but on a high level basically just just answer try to be helpful try to be truthful and don't answer questions that we don't want um kind of the system to handle uh later in chat gbt and so roughly speaking the company comes up with the labeling instructions usually they are not this short usually there are hundreds of pages and people have to study them professionally and then they write out the ideal assistant [01:12:26] responses uh following those labeling instructions so this is a very human heavy process as it was described in this paper now the data set for instruct GPT was never actually released by openi but we do have some open- Source um reproductions that were're trying to follow this kind of a setup and collect their own data so one that I'm familiar with for example is the effort of open Assistant from a while back and this is just one of I think many examples but I just want to show you an example so here's so these were people on the [01:12:56] internet that were asked to basically create these conversations similar to what um open I did with human labelers and so here's an entry of a person who came up with this BR can you write a short introduction to the relevance of the term manop uh in economics please use examples Etc and then the same person or potentially a different person will write up the response so here's the assistant response to this and so then the same person or different person will actually write out this ideal [01:13:26] response and then this is an example of maybe how the conversation could continue now explain it to a dog and then you can try to come up with a slightly a simpler explanation or something like that now this then becomes the label and we end up training on this so what happens during training is that um of course we're not going to have a full coverage of all the possible questions that um the model will encounter at test time during inference [01:13:56] we can't possibly cover all the possible prompts that people are going to be asking in the future but if we have a like a data set of a few of these examples then the model during training will start to take on this Persona of this helpful truthful harmless assistant and it's all programmed by example and so these are all examples of behavior and if you have conversations of these example behaviors and you have enough of them like 100,00 and you train on it the model sort of starts to understand the statistical pattern and it kind of takes [01:14:26] on this personality of this assistant now it's possible that when you get the exact same question like this at test time it's possible that the answer will be recited as exactly what was in the training set but more likely than that is that the model will kind of like do something of a similar Vibe um and we will understand that this is the kind of answer that you want um so that's what we're doing we're programming the system um by example and the system adopts statistically this [01:14:58] Persona of this helpful truthful harmless assistant which is kind of like reflected in the labeling instructions that the company creates now I want to show you that the state-of-the-art has kind of advanced in the last 2 or 3 years uh since the instr GPT paper so in particular it's not very common for humans to be doing all the heavy lifting just by themselves anymore and that's because we now have language models and these language models are helping us create these data sets and conversations so it is very rare that the people will like literally just write out the response from scratch it is a lot more [01:15:28] likely that they will use an existing llm to basically like uh come up with an answer and then they will edit it or things like that so there's many different ways in which now llms have started to kind of permeate this posttraining Set uh stack and llms are basically used pervasively to help create these massive data sets of conversations so I don't want to show like Ultra chat is one um such example of like a more modern data set of conversations it is to a very large extent synthetic but uh I believe [01:15:58] there's some human involvement I could be wrong with that usually there will be a little bit of human but there will be a huge amount of synthetic help um and this is all kind of like uh constructed in different ways and Ultra chat is just one example of many sft data sets that currently exist and the only thing I want to show you is that uh these data sets have now millions of conversations uh these conversations are mostly synthetic but they're probably edited to some extent by humans and they span a huge diversity of sort of um uh areas and so on so these are [01:16:31] fairly extensive artifacts by now and there's all these like sft mixtures as they're called so you have a mixture of like lots of different types and sources and it's partially synthetic partially human and it's kind of like um gone in that direction since uh but roughly speaking we still have sft data sets they're made up of conversations we're training on them um just like we did before and uh I guess like the last thing to note is that I want to dispel a little bit of the magic of talking to an AI like when [01:17:02] you go to chat GPT and you give it a question and then you hit enter uh what is coming back is kind of like statistically aligned with what's happening in the training set and these training sets I mean they really just have a seed in humans following labeling instructions so what are you actually talking to in chat GPT or how should you think about it well it's not coming from some magical AI like roughly speaking it's coming from something that is statistically imitating human labelers [01:17:32] which comes from labeling instructions written by these companies and so you're kind of imitating this uh you're kind of getting um it's almost as if you're asking human labeler and imagine that the answer that is given to you uh from chbt is some kind of a simulation of a human labeler uh and it's kind of like asking what would a human labeler say in this kind of a conversation and uh it's not just like this human labeler is not just like a random person from the internet because these companies actually hire experts so for [01:18:03] example when you are asking questions about code and so on the human labelers that would be in um involved in creation of these conversation data sets they will usually be usually be educated expert people and you're kind of like asking a question of like a simulation of those people if that makes sense so you're not talking to a magical AI you're talking to an average labeler this average labeler is probably fairly highly skilled but you're talking to kind of like an instantaneous simulation of that kind of a person that would be hired uh in the construction of these data sets so let [01:18:34] me give you one more specific example before we move on for example when I go to chpt and I say recommend the top five landmarks who see in Paris and then I hit enter uh okay here we go okay when I hit enter what's coming out here how do I think about it well it's not some kind of a magical AI that has gone out and researched all the landmarks and then ranked them using its infinite intelligence Etc what I'm getting is a [01:19:04] statistical simulation of a labeler that was hired by open AI you can think about it roughly in that way and so if this specific um question is in the posttraining data set somewhere at open aai then I'm very likely to see an answer that is probably very very similar to what that human labeler would have put down for those five landmarks how does the human labeler come up with this well they go off and they go on the internet and they kind of do their own little research for 20 minutes and they just come up with a list right now so if they [01:19:35] come up with this list and this is in the data set I'm probably very likely to see what they submitted as the correct answer from the assistant now if this specific query is not part of the post training data set then what I'm getting here is a little bit more emergent uh because uh the model kind of understands the statistically um the kinds of landmarks that are in this training set are usually the prominent landmarks the landmarks that people usually want to see the kinds of landmarks that are usually uh very often [01:20:05] talked about on the internet and remember that the model already has a ton of Knowledge from its pre-training on the internet so it's probably seen a ton of conversations about Paris about landmarks about the kinds of things that people like to see and so it's the pre-training knowledge that has then combined with the postering data set that results in this kind of an imitation um so that's uh that's roughly how you can kind of think about what's happening behind the scenes here in in this statistical sense okay now I want to turn to the topic of llm psychology as I [01:20:35] like to call it which is what are sort of the emergent cognitive effects of the training pipeline that we have for these models so in particular the first one I want to talk to is of course hallucinations so you might be familiar with model hallucinations it's when llms make stuff up they just totally fabricate information Etc and it's a big problem with llm assistants it is a problem that existed to a large extent with early models uh from many years ago and I think the problem has gotten a bit better uh because there are some [01:21:05] medications that I'm going to go into in a second for now let's just try to understand where these hallucinations come from so here's a specific example of a few uh of three conversations that you might think you have in your training set and um these are pretty reasonable conversations that you could imagine being in the training set so like for example who is Cruz well Tom Cruz is an famous actor American actor and producer Etc who is John baraso this turns out to be a us senetor for example who is genis Khan well genis Khan was [01:21:36] blah blah blah and so this is what your conversations could look like at training time now the problem with this is that when the human is writing the correct answer for the assistant in each one of these cases uh the human either like knows who this person is or they research them on the Internet and they come in and they write this response that kind of has this like confident tone of an answer and what happens basically is that at test time when you ask for someone who is this is a totally random name that I totally came up with and I don't think this person exists um [01:22:07] as far as I know I just Tred to generate it randomly the problem is when we ask who is Orson kovats the problem is that the assistant will not just tell you oh I don't know even if the assistant and the language model itself might know inside its features inside its activations inside of its brain sort of it might know that this person is like not someone that um that is that it's familiar with even if some part of the network kind of knows that in some sense the uh saying that oh I don't know who [01:22:37] this is is is not going to happen because the model statistically imitates is training set in the training set the questions of the form who is blah are confidently answered with the correct answer and so it's going to take on the style of the answer and it's going to do its best it's going to give you statistically the most likely guess and it's just going to basically make stuff up because these models again we just talked about it is they don't have access to the internet they're not doing research these are statistical token tumblers as I call them uh is just [01:23:08] trying to sample the next token in the sequence and it's going to basically make stuff up so let's take a look at what this looks like I have here what's called the inference playground from hugging face and I am on purpose picking on a model called Falcon 7B which is an old model this is a few years ago now so it's an older model So It suffers from hallucinations and as I mentioned this has improved over time recently but let's say who is Orson kovats let's ask Falcon 7B instruct run oh yeah Orson kovat is an American [01:23:40] author and science uh fiction writer okay this is totally false it's hallucination let's try again these are statistical systems right so we can resample this time Orson kovat is a fictional character from this 1950s TV show it's total BS right let's try again he's a former minor league baseball player okay so basically the model doesn't know and it's given us lots of different answers because it doesn't know it's just kind of like sampling from these probabilities the model [01:24:10] starts with the tokens who is oron kovats assistant and then it comes in here and it's get it's getting these probabilities and it's just sampling from the probabilities and it just like comes up with stuff and the stuff is actually statistically consistent with the style of the answer in its training set and it's just doing that but you and I experiened it as a madeup factual knowledge but keep in mind that uh the model basically doesn't know and it's just imitating the format of the answer [01:24:40] and it's not going to go off and look it up uh because it's just imitating again the answer so how can we uh mitigate this because for example when we go to chat apt and I say who is oron kovats and I'm now asking the stateoftheart state-of-the-art model from open AI this model will tell you oh so this model is actually is even smarter because you saw very briefly it said searching the web uh we're going to cover this later um it's actually trying to do tool use and [01:25:11] uh kind of just like came up with some kind of a story but I want to just who or Kovach did not use any tools I don't want it to do web search there's a wellknown historical or public figure named or oron kovats so this model is not going to make up stuff this model knows that it doesn't know and it tells you that it doesn't appear to be a person that this model knows so somehow we sort of improved hallucinations even though they clearly are an issue in older models and it [01:25:42] makes totally uh sense why you would be getting these kinds of answers if this is what your training set looks like so how do we fix this okay well clearly we need some examples in our data set that where the correct answer for the assistant is that the model doesn't know about some particular fact but we only need to have those answers be produced in the cases where the model actually doesn't know and so the question is how do we know what the model knows or doesn't know well we can empirically probe the model to figure that out so let's take a look at for example how [01:26:13] meta uh dealt with hallucinations for the Llama 3 series of models as an example so in this paper that they published from meta we can go into hallucinations which they call here factuality and they describe the procedure by which they basically interrogate the model to figure out what it knows and doesn't know to figure out sort of like the boundary of its knowledge and then they add examples to the training set where for the things where the model doesn't [01:26:44] know them the correct answer is that the model doesn't know them which sounds like a very easy thing to do in principle but this roughly fixes the issue and the the reason it fixes the issue is because remember like the model might actually have a pretty good model of its self knowledge inside the network so remember we looked at the network and all these neurons inside the network you might imagine that there's a neuron somewhere in the network that sort of like lights up for when the model is [01:27:14] uncertain but the problem is that the activation of that neuron is not currently wired up to the model actually saying in words that it doesn't know so even though the internal of the neural network no because there's some neurons that represent that the model uh will not surface that it will instead take its best guess so that it sounds confident um just like it sees in a training set so we need to basically interrogate the model and allow it to say I don't know in the cases that it doesn't know so let me take you through what meta roughly does so basically what [01:27:45] they do is here I have an example uh Dominic kek is uh the featured article today so I just went there randomly and what they do is basically they take a random document in a training set and they take a paragraph and then they use an llm to construct questions about that paragraph so for example I did that with chat GPT here so I said here's a paragraph from this document generate three specific factual questions based on this [01:28:15] paragraph and give me the questions and the answers and so the llms are already good enough to create and reframe this information so if the information is in the context window um of this llm this actually works pretty well it doesn't have to rely on its memory it's right there in the context window and so it can basically reframe that information with fairly high accuracy so for example can generate questions for us like for which team did he play here's the answer how many cups did he win Etc and now [01:28:47] what we have to do is we have some question and answers and now we want to interrogate the model so roughly speaking what we'll do is we'll take our questions and we'll go to our model which would be uh say llama uh in meta but let's just interrogate mol 7B here as an example that's another model so does this model know about this answer let's take a look uh so he played for Buffalo Sabers right so the model knows and the the way that you can programmatically decide is basically we're going to take this [01:29:18] answer from the model and we're going to compare it to the correct answer and again the model model are good enough to do this automatically so there's no humans involved here we can take uh basically the answer from the model and we can use another llm judge to check if that is correct according to this answer and if it is correct that means that the model probably knows so what we're going to do is we're going to do this maybe a few times so okay it knows it's Buffalo Savers let's drag in um Buffalo Sabers let's try one more [01:29:51] time Buffalo Sabers so we asked three times about this factual question and the model seems to know so everything is great now let's try the second question how many Stanley Cups did he win and again let's interrogate the model about that and the correct answer is two so um here the model claims that he won um four times which is not correct right it doesn't match two so the model doesn't know it's making stuff up let's [01:30:22] try again um so here the model again it's kind of like making stuff up right let's Dragon here it says did he did not even did not win during his career so obviously the model doesn't know and the way we can programmatically tell again is we interrogate the model three times and we compare its answers maybe three times five times whatever it is to the correct answer and if the model doesn't know then we know that the model doesn't [01:30:53] know this question and then what we do is we take this question we create a new conversation in the training set so we're going to add a new conversation training set and when the question is how many Stanley Cups did he win the answer is I'm sorry I don't know or I don't remember and that's the correct answer for this question because we interrogated the model and we saw that that's the case if you do this for many different types of uh questions for many different types of documents you are giving the model an [01:31:23] opportunity to in its training set refuse to say based on its knowledge and if you just have a few examples of that in your training set the model will know um and and has the opportunity to learn the association of this knowledge-based refusal to this internal neuron somewhere in its Network that we presume exists and empirically this turns out to be probably the case and it can learn that Association that hey when this neuron of uncertainty is high then I actually don't know and I'm allowed to [01:31:54] say that I'm sorry but I don't think I remember this Etc and if you have these uh examples in your training set then this is a large mitigation for hallucination and that's roughly speaking why chpt is able to do stuff like this as well so these are kinds of uh mitigations that people have implemented and that have improved the factuality issue over time okay so I've described mitigation number one for basically mitigating the hallucinations issue now we can actually do much better [01:32:24] than that uh it's instead of just saying that we don't know uh we can introduce an additional mitigation number two to give the llm an opportunity to be factual and actually answer the question now what do you and I do if I was to ask you a factual question and you don't know uh what would you do um in order to answer the question well you could uh go off and do some search and uh use the internet and you could figure out the answer and then tell me what that answer is and we can do the exact exact same [01:32:54] thing with these models so think of the knowledge inside the neural network inside its billions of parameters think of that as kind of a vague recollection of the things that the model has seen during its training during the pre-training stage a long time ago so think of that knowledge in the parameters as something you read a month ago and if you keep reading something then you will remember it and the model remembers that but if it's something rare then you probably don't have a really good recollection of that information but what you and I do is we just go and look it up now when you go [01:33:25] and look it up what you're doing basically is like you're refreshing your working memory with information and then you're able to sort of like retrieve it talk about it or Etc so we need some equivalent of allowing the model to refresh its memory or its recollection and we can do that by introducing tools uh for the models so the way we are going to approach this is that instead of just saying hey I'm sorry I don't know we can attempt to use tools so we can create uh a mechanism by which the language model can emit [01:33:56] special tokens and these are tokens that we're going to introduce new tokens so for example here I've introduced two tokens and I've introduced a format or a protocol for how the model is allowed to use these tokens so for example instead of answering the question when the model does not instead of just saying I don't know sorry the model has the option now to emitting the special token search start and this is the query that will go to like bing.com in the case of openai or say Google search or something like that so it will emit the query and then [01:34:26] it will emit search end and then here what will happen is that the program that is sampling from the model that is running the inference when it sees the special token search end instead of sampling the next token uh in the sequence it will actually pause generating from the model it will go off it will open a session with bing.com and it will paste the search query into Bing and it will then um get all the text that is retrieved and it will basically [01:34:56] take that text it will maybe represent it again with some other special tokens or something like that and it will take that text and it will copy paste it here into what I Tred to like show with the brackets so all that text kind of comes here and when the text comes here it enters the context window so the model so that text from the web search is now inside the context window that will feed into the neural network and you should think of the context window as kind of like the working memory of the model that data that is in the context window [01:35:27] is directly accessible by the model it directly feeds into the neural network so it's not anymore a vague recollection it's data that it it has in the context window and is directly available to that model so now when it's sampling the new uh tokens here afterwards it can reference very easily the data that has been copy pasted in there so that's roughly how these um how these tools use uh tools uh function and so web search is just one of the tools we're going to look at some of the other tools in a bit uh but basically [01:35:59] you introduce new tokens you introduce some schema by which the model can utilize these tokens and can call these special functions like web search functions and how do you teach the model how to correctly use these tools like say web search search start search end Etc well again you do that through training sets so we need now to have a bunch of data and a bunch of conversations that show the model by example how to use web search so what are the what are the settings where you are using the search um and what does that look like and here's by example how [01:36:30] you start a search and the search Etc and uh if you have a few thousand maybe examples of that in your training set the model will actually do a pretty good job of understanding uh how this tool works and it will know how to sort of structure its queries and of course because of the pre-training data set and its understanding of the world it actually kind of understands what a web search is and so it actually kind of has a pretty good native understanding um of what kind of stuff is a good search query um and so it all kind of just like works you just need a little [01:37:00] bit of a few examples to show it how to use this new tool and then it can lean on it to retrieve information and uh put it in the context window and that's equivalent to you and I looking something up because once it's in the context it's in the working memory and it's very easy to manipulate and access so that's what we saw a few minutes ago when I was searching on chat GPT for who is Orson kovats the chat GPT language model decided Ed that this is some kind of a rare um individual or something like that and instead of giving me an answer from its memory it decided that [01:37:31] it will sample a special token that is going to do web search and we saw briefly something flash it was like using the web tool or something like that so it briefly said that and then we waited for like two seconds and then it generated this and you see how it's creating references here and so it's citing sources so what happened here is it went off it did a web web search it found these sources and these URLs and the text of these web pages was all stuffed in between here and it's not [01:38:01] showing here but it's it's basically stuffed as text in between here and now it sees that text and now it kind of references it and says that okay it could be these people citation could be those people citation Etc so that's what happened here and that's what and that's why when I said who is Orson kovats I could also say don't use any tools and then that's enough to um basically convince chat PT to not use tools and just use its memory and its recollection I also went off and I um [01:38:32] tried to ask this question of Chachi PT so how many standing cups did uh Dominic Hasek win and Chachi P actually decided that it knows the answer and it has the confidence to say that uh he want twice and so it kind of just relied on its memory because presumably it has um it has enough of a kind of confidence in its weights in it parameters and activations that this is uh retrievable just for memory um but you can also conversely use web search to make sure [01:39:04] and then for the same query it actually goes off and it searches and then it finds a bunch of sources it finds all this all of this stuff gets copy pasted in there and then it tells us uh to again and sites and it actually says the Wikipedia article which is the source of this information for us as well so that's tools web search the model determines when to search and then uh that's kind of like how these tools uh work and this is an additional kind of mitigation for uh hallucinations and [01:39:34] factuality so I want to stress one more time this very important sort of psychology Point knowledge in the parameters of the neural network is a vague recollection the knowledge in the tokens that make up the context window is the working memory and it roughly speaking Works kind of like um it works for us in our brain the stuff we remember is our parameters uh and the stuff that we just experienced like a few seconds or minutes ago and so on you can imagine that being in our context [01:40:04] window and this context window is being built up as you have a conscious experience around you so this has a bunch of um implications also for your use of LOLs in practice so for example I can go to chat GPT and I can do something like this I can say can you Summarize chapter one of Jane Austin's Pride and Prejudice right and this is a perfectly fine prompt and Chach actually does something relatively reasonable here and but the reason it does that is because Chach has a pretty good recollection of a famous work like Pride and Prejudice it's probably seen a ton [01:40:34] of stuff about it there's probably forums about this book it's probably read versions of this book um and it's kind of like remembers because even if you've read this or articles about it you'd kind of have a recollection enough to actually say all this but usually when I actually interact with LMS and I want them to recall specific things it always works better if you just give it to them so I think a much better prompt would be something like this can you summarize for me chapter one of genos's spr and Prejudice and then I am attaching it below for your reference [01:41:04] and then I do something like a delimeter here and I paste it in and I I found that just copy pasting it from some website that I found here um so copy pasting the chapter one here and I do that because when it's in the context window the model has direct access to it and can exactly it doesn't have to recall it it just has access to it and so this summary is can be expected to be a significantly high quality or higher quality than this summary uh just because it's directly available to the model and I think you and I would work [01:41:34] in the same way if you want to it would be you would produce a much better summary if you had reread this chapter before you had to summarize it and that's basically what's happening here or the equivalent of it the next sort of psychological Quirk I'd like to talk about briefly is that of the knowledge of self so what I see very often on the internet is that people do something like this they ask llms something like what model are you and who built you and um basically this uh question is a little bit nonsensical and the reason I say that is that as I try to kind of [01:42:05] explain with some of the underhood fundamentals this thing is not a person right it doesn't have a persistent existence in any way it sort of boots up processes tokens and shuts off and it does that for every single person it just kind of builds up a context window of conversation and then everything gets deleted and so this this entity is kind of like restarted from scratch every single conversation if that makes sense it has no persistent self it has no sense of self it's a token tumbler and uh it follows the statistical regularities of its training set so it [01:42:35] doesn't really make sense to ask it who are you what build you Etc and by default if you do what I described and just by default and from nowhere you're going to get some pretty random answers so for example let's uh pick on Falcon which is a fairly old model and let's see what it tells us uh so it's evading the question uh talented engineers and developers here it says I was built by open AI based on the gpt3 model it's totally making stuff up now the fact that it's built by open AI here I think a lot of people would [01:43:06] take this as evidence that this model was somehow trained on open AI data or something like that I don't actually think that that's necessarily true the reason for that is that if you don't explicitly program the model to answer these kinds of questions then what you're going to get is its statistical best guess at the answer and this model had a um sft data mixture of conversations and during the fine-tuning um the model sort of understands as it's training on this [01:43:36] data that it's taking on this personality of this like helpful assistant and it doesn't know how to it doesn't actually it wasn't told exactly what label to apply to self it just kind of is taking on this uh this uh Persona of a helpful assistant and remember that the pre-training stage took the documents from the entire internet and Chach and open AI are very prominent in these documents and so I think what's actually likely to be happening here is that this is just its hallucinated label [01:44:06] for what it is this is its self-identity is that it's chat GPT by open Ai and it's only saying that because there's a ton of data on the internet of um answers like this that are actually coming from open from chasht and So that's its label for what it is now you can override this as a developer if you have a llm model you can actually override it and there are a few ways to do that so for example let me show you there's this MMO model from Allen Ai and um this is one llm it's not a top tier [01:44:37] LM or anything like that but I like it because it is fully open source so the paper for Almo and everything else is completely fully open source which is nice um so here we are looking at its sft mixture so this is the data mixture of um the fine tuning so this is the conversations data it right and so the way that they are solving it for Theo model is we see that there's a bunch of stuff in the mixture and there's a total of 1 million conversations here but here we have alot to hardcoded if we go there we see that this is 240 [01:45:07] conversations and look at these 240 conversations they're hardcoded tell me about yourself says user and then the assistant says I'm and open language model developed by AI to Allen Institute of artificial intelligence Etc I'm here to help blah blah blah what is your name uh Theo project so these are all kinds of like cooked up hardcoded questions abouto 2 and the correct answers to give in these cases if you take 240 questions like this or conversations put them into your training set and fine tune with it [01:45:37] then the model will actually be expected to parot this stuff later if you don't give it this then it's probably a Chach by open Ai and um there's one more way to sometimes do this is that basically um in these conversations and you have terms between human and assistant sometimes there's a special message called system message at the very beginning of the conversation so it's not just between human and assistant there's a system and in the system message you can actually hardcode [01:46:07] and remind the model that hey you are a model developed by open Ai and your name is chashi pt40 and you were trained on this date and your knowledge cut off is this and basically it kind of like documents the model a little bit and then this is inserted into to your conversations so when you go on chpt you see a blank page but actually the system message is kind of like hidden in there and those tokens are in the context window and so those are the two ways to kind of um program the models to talk about themselves either it's done [01:46:37] through uh data like this or it's done through system message and things like that basically invisible tokens that are in the context window and remind the model of its identity but it's all just kind of like cooked up and bolted on in some in some way it's not actually like really deeply there in any real sense as it would before a human I want to now continue to the next section which deals with the computational capabilities or like I should say the native computational capabilities of these models in problem solving scenarios and so in particular we have to be very [01:47:07] careful with these models when we construct our examples of conversations and there's a lot of sharp edges here that are kind of like elucidative is that a word uh they're kind of like interesting to look at when we consider how these models think so um consider the following prompt from a human and supposed that basically that we are building out a conversation to enter into our training set of conversations so we're going to train the model on this we're teaching you how to basically solve simple math problems so the prompt is Emily buys three apples and two oranges each orange cost $2 the total [01:47:38] cost is 13 what is the cost of apples very simple math question now there are two answers here on the left and on the right they are both correct answers they both say that the answer is three which is correct but one of these two is a significant ific anly better answer for the assistant than the other like if I was Data labeler and I was creating one of these one of these would be uh a really terrible answer for the assistant and the other would be okay and so I'd like you to potentially pause the video Even and think through why one of these [01:48:09] two is significantly better answer uh than the other and um if you use the wrong one your model will actually be uh really bad at math potentially and it would have uh bad outcomes and this is something that you would be careful with in your life labeling documentations when you are training people uh to create the ideal responses for the assistant okay so the key to this question is to realize and remember that when the models are training and also inferencing they are working in onedimensional sequence of tokens from left to right and this is the picture [01:48:40] that I often have in my mind I imagine basically the token sequence evolving from left to right and to always produce the next token in a sequence we are feeding all these tokens into the neural network and this neural network then is the probabilities for the next token and sequence right so this picture here is the exact same picture we saw uh before up here and this comes from the web demo that I showed you before right so this is the calculation that basically takes the input tokens here on the top and uh performs these operations of all these [01:49:11] neurons and uh gives you the answer for the probabilities of what comes next now the important thing to realize is that roughly speaking uh there's basically a finite number of layers of computation that happened here so for example this model here has only one two three layers of what's called detention and uh MLP here um maybe um typical modern state-of-the-art Network would have more like say 100 layers or something like that but there's only 100 layers of computation or something like that to go from the previous token sequence to the [01:49:42] probabilities for the next token and so there's a finite amount of computation that happens here for every single token and you should think of this as a very small amount of computation and this amount of computation is almost roughly fixed uh for every single token in this sequence um the that's not actually fully true because the more tokens you feed in uh the the more expensive uh this forward pass will be of this neural network but not by much so you should think of this uh and I think as a good model to have in mind this is a fixed [01:50:12] amount of compute that's going to happen in this box for every single one of these tokens and this amount of compute Cann possibly be too big because there's not that many layers that are sort of going from the top to bottom here there's not that that much computationally that will happen here and so you can't imagine the model to to basically do arbitrary computation in a single forward pass to get a single token and so what that means is that we actually have to distribute our reasoning and our computation across many tokens because every single token is only spending a finite amount of computation on it and so we kind of want [01:50:45] to distribute the computation across many tokens and we can't have too much computation or expect too much computation out of of the model in any single individual token because there's only so much computation that happens per token okay roughly fixed amount of computation here so that's why this answer here is significantly worse and the reason for that is Imagine going from left to right here um and I copy pasted it right here the answer is three Etc imagine the [01:51:16] model having to go from left to right emitting these tokens one at a time it has to say or we're expecting to say the answer is space dollar sign and then right here we're expecting it to basically cram all of the computation of this problem into this single token it has to emit the correct answer three and then once we've emitted the answer three we're expecting it to say all these tokens but at this point we've already prod produced the answer and it's already in the context window for all these tokens that follow so anything [01:51:46] here is just um kind of post Hawk justification of why this is the answer um because the answer is already created it's already in the token window so it's it's not actually being calculated here um and so if you are answering the question directly and immediately you are training the model to to try to basically guess the answer in a single token and that is just not going to work because of the finite amount of computation that happens per token that's why this answer on the right is significantly better because we are [01:52:17] Distributing this computation across the answer we're actually getting the model to sort of slowly come to the answer from the left to right we're getting intermediate results we're saying okay the total cost of oranges is four so 30 - 4 is 9 and so we're creating intermediate calculations and each one of these calculations is by itself not that expensive and so we're actually basically kind of guessing a little bit the difficulty that the model is capable of in any single one of these individual tokens and there can never be too much [01:52:47] work in any one of these tokens computationally because then the model won't be able to do that later at test time and so we're teaching the model here to spread out its reasoning and to spread out its computation over the tokens and in this way it only has very simple problems in each token and they can add up and then by the time it's near the end it has all the previous results in its working memory and it's much easier for it to determine that the answer is and here it is three so this is a significantly better label for our [01:53:18] computation this would be really bad and is teaching the model to try to do all the computation in a single token and it's really bad so uh that's kind of like an interesting thing to keep in mind is in your prompts uh usually don't have to think about it explicitly because uh the people at open AI have labelers and so on that actually worry about this and they make sure that the answers are spread out and so actually open AI will kind of like do the right thing so when I ask this question for chat GPT it's [01:53:48] actually going to go very slowly it's going to be like okay let's define our variables set up the equation and it's kind of creating all these intermediate results these are not for you these are for the model if the model is not creating these intermediate results for itself it's not going to be able to reach three I also wanted to show you that it's possible to be a bit mean to the model uh we can just ask for things so as an example I said I gave it the exact same uh prompt and I said answer the question in a single token just immediately give me the answer nothing else and it turns out that for [01:54:18] this simple um prompt here it actually was able to do it in single go so it just created a single I think this is two tokens right uh because the dollar sign is its own token so basically this model didn't give me a single token it gave me two tokens but it still produced the correct answer and it did that in a single forward pass of the network now that's because the numbers here I think are very simple and so I made it a bit more difficult to be a bit mean to the model so I said Emily buys 23 apples and 177 oranges and then I [01:54:48] just made the numbers a bit bigger and I'm just making it harder for the model I'm asking it to more computation in a single token and so I said the same thing and here it gave me five and five is actually not correct so the model failed to do all of this calculation in a single forward pass of the network it failed to go from the input tokens and then in a single forward pass of the network single go through the network it couldn't produce the result and then I said okay now don't worry about the the token limit and just solve the problem [01:55:18] as usual and then it goes all the intermediate results it simplifies and every one of these intermediate results here and intermediate calculations is much easier for the model and um it sort of it's not too much work per token all of the tokens here are correct and it arises the solution which is seven and I just couldn't squeeze all of this work it couldn't squeeze that into a single forward passive Network so I think that's kind of just a cute example and something to kind of like think about and I think it's kind of again just elucidative in terms of how these uh [01:55:48] models work the last thing that I would say on this topic is that if I was in practi is trying to actually solve this in my day-to-day life I might actually not uh trust that the model that all the intermediate calculations correctly here so actually probably what I do is something like this I would come here and I would say use code and uh that's because code is one of the possible tools that chachy PD can use and instead of it having to do mental arithmetic like this mental arithmetic here I don't fully trust it and especially if the numbers get really big there's no [01:56:19] guarantee that the model will do this correctly any one of these intermediates steps might in principle fail we're using neural networks to do mental arithmetic uh kind of like you doing mental arithmetic in your brain it might just like uh screw up some of the intermediate results it's actually kind of amazing that it can even do this kind of mental arithmetic I don't think I could do this in my head but basically the model is kind of like doing it in its head and I don't trust that so I wanted to use tools so you can say stuff like use code and uh I'm not sure what happened there use [01:56:50] code and so um like I mentioned there's a special tool and the uh the model can write code and I can inspect that this code is correct and then uh it's not relying on its mental arithmetic it is using the python interpreter which is a very simple programming language to basically uh write out the code that calculates the result and I would personally trust this a lot more because this came out of a Python program which I think has a lot more correctness guarantees than the mental arithmetic of a language model uh so just um another [01:57:21] kind of uh potential hint that if you have these kinds of problems uh you may want to basically just uh ask the model to use the code interpreter and just like we saw with the web search the model has special uh kind of tokens for calling uh like it will not actually generate these tokens from the language model it will write the program and then it actually sends that program to a different sort of part of the computer that actually just runs that program and brings back the result and then the model gets access to that result and can tell you that okay the cost of each [01:57:51] apple is seven um so that's another kind of tool and I would use this in practice for yourself and it's um yeah it's just uh less error prone I would say so that's why I called this section models need tokens to think distribute your competition across many tokens ask models to create intermediate results or whenever you can lean on tools and Tool use instead of allowing the models to do all of the stuff in their memory so if they try to do it all in their memory I don't fully trust it [01:58:21] and prefer to use tools whenever possible I want to show you one more example of where this actually comes up and that's in counting so models actually are not very good at counting for the exact same reason you're asking for way too much in a single individual token so let me show you a simple example of that um how many dots are below and then I just put in a bunch of dots and Chach says there are and then it just tries to solve the problem in a single token so in a single token it has to count the number of dots in its [01:58:51] context window um and it has to do that in the single forward pass of a network and a single forward pass of a network as we talked about there's not that much computation that can happen there just think of that as being like very little competation that happens there so if I just look at what the model sees let's go to the LM go to tokenizer it sees uh this how many dots are below and then it turns out that these dots here this group of I think 20 dots is a single token and then this group of whatever it [01:59:22] is is another token and then for some reason they break up as this so I don't actually this has to do with the details of the tokenizer but it turns out that these um the model basically sees the token ID this this this and so on and then from these token IDs it's expected to count the number and spoiler alert is not 161 it's actually I believe 177 so here's what we can do instead uh we can say use code and you might expect that like why should this work and it's [01:59:54] actually kind of subtle and kind of interesting so when I say use code I actually expect this to work let's see okay 177 is correct so what happens here is I've actually it doesn't look like it but I've broken down the problem into a problems that are easier for the model I know that the model can't count it can't do mental counting but I know that the model is actually pretty good at doing copy pasting so what I'm doing here is when I say use code it creates a string in Python for this and the task of basically copy pasting my input here to [02:00:27] here is very simple because for the model um it sees this string of uh it sees it as just these four tokens or whatever it is so it's very simple for the model to copy paste those token IDs and um kind of unpack them into Dots here and so it creates this string and then it calls python routine. count and then it comes up with the correct answer so the python interpreter is doing the counting it's not the models mental arithmetic doing the counting so it's [02:00:57] again a simple example of um models need tokens to think don't rely on their mental arithmetic and um that's why also the models are not very good at counting if you need them to do counting tasks always ask them to lean on the tool now the models also have many other little cognitive deficits here and there and these are kind of like sharp edges of the technology to be kind of aware of over time so as an example the models are not very good with all kinds of spelling related tasks they're not very good at it and I told you that we would loop back around to tokenization and the [02:01:29] reason to do for this is that the models they don't see the characters they see tokens and they their entire world is about tokens which are these little text chunks and so they don't see characters like our eyes do and so very simple character level tasks often fail so for example uh I'm giving it a string ubiquitous and I'm asking it to print only every third character starting with the first one so we start with U and then we should go every third so every so 1 2 3 Q should be next and then Etc [02:02:01] so this I see is not correct and again my hypothesis is that this is again Dental arithmetic here is failing number one a little bit but number two I think the the more important issue here is that if you go to Tik tokenizer and you look at ubiquitous we see that it is three tokens right so you and I see ubiquitous and we can easily access the individual letters because we kind of see them and when we have it in the working memory of our visual sort of field we can really easily index into every third letter and I can do that [02:02:31] task but the models don't have access to the individual letters they see this as these three tokens and uh remember these models are trained from scratch on the internet and all these token uh basically the model has to discover how many of all these different letters are packed into all these different tokens and the reason we even use tokens is mostly for efficiency uh but I think a lot of people areed interested to delete tokens entirely like we should really have character level or bite level models it's just that that would create very long sequences and people don't know how to deal with that right now so [02:03:01] while we have the token World any kind of spelling tasks are not actually expected to work super well so because I know that spelling is not a strong suit because of tokenization I can again Ask it to lean On Tools so I can just say use code and I would again expect this to work because the task of copy pasting ubiquitous into the python interpreter is much easier and then we're leaning on python interpreter to manipulate the characters of this string so when I say use code ubiquitous yes it indexes into every [02:03:32] third character and the actual truth is u2s uqs uh which looks correct to me so um again an example of spelling related tasks not working very well a very famous example of that recently is how many R are there in strawberry and this went viral many times and basically the models now get it correct they say there are three Rs in Strawberry but for a very long time all the state-of-the-art models would insist that there are only two RS in strawberry and this caused a lot of you know Ruckus because is that a [02:04:03] word I think so because um it just kind of like why are the models so brilliant and they can solve math Olympiad questions but they can't like count RS in strawberry and the answer for that again is I've got built up to it kind of slowly but number one the models don't see characters they see tokens and number two they are not very good at counting and so here we are combining the difficulty of seeing the characters with the difficulty of counting and that's why the models struggled with this even though I think by now honestly [02:04:33] I think open I may have hardcoded the answer here or I'm not sure what they did but um uh but this specific query now works so models are not very good at spelling and there there's a bunch of other little sharp edges and I don't want to go into all of them I just want to show you a few examples of things to be aware of and uh when you're using these models in practice I don't actually want to have a comprehensive analysis here of all the ways that the models are kind of like falling short I just want to make the point that there are some Jagged edges here and there and we've discussed [02:05:03] a few of them and a few of them make sense but some of them also will just not make as much sense and they're kind of like you're left scratching your head even if you understand in- depth how these models work and and good example of that recently is the following uh the models are not very good at very simple questions like this and uh this is shocking to a lot of people because these math uh these problems can solve complex math problems they can answer PhD grade physics chemistry biology questions much better than I can but sometimes they fall short in like super simple problems like this so here we go [02:05:34] 9.11 is bigger than 9.9 and it justifies it in some way but obviously and then at the end okay it actually it flips its decision later so um I don't believe that this is very reproducible sometimes it flips around its answer sometimes gets it right sometimes get it get it wrong uh let's try again okay even though it might look larger okay so here it doesn't even correct itself in the end if you ask many times sometimes it gets it right [02:06:04] too but how is it that the model can do so great at Olympiad grade problems but then fail on very simple problems like this and uh I think this one is as I mentioned a little bit of a head scratcher it turns out that a bunch of people studied this in depth and I haven't actually read the paper uh but what I was told by this team was that when you scrutinize the activations inside the neural network when you look at some of the features and what what features turn on or off and what neurons turn on or off uh a bunch of neurons [02:06:35] inside the neural network light up that are usually associated with Bible verses U and so I think the model is kind of like reminded that these almost look like Bible verse markers and in a bip verse setting 9.11 would come after 99.9 and so basically the model somehow finds it like cognitively very distracting that in Bible verses 9.11 would be greater um even though here it's actually trying to justify it and come up to the answer with a math it still ends up with the wrong answer here so it [02:07:07] basically just doesn't fully make sense and it's not fully understood and um there's a few Jagged issues like that so that's why treat this as a as what it is which is a St stochastic system that is really magical but that you can't also fully trust and you want to use it as a tool not as something that you kind of like letter rip on a problem and copypaste the results okay so we have now covered two major stages of training of large language models we saw that in the first stage this is called the pre-training stage we are basically [02:07:38] training on internet documents and when you train a language model on internet documents you get what's called a base model and it's basically an internet document simulator right now we saw that this is an interesting artifact and uh this takes many months to train on thousands of computers and it's kind of a lossy compression of the internet and it's extremely interesting but it's not directly useful because we don't want to sample internet documents we want to ask questions of an AI and have it respond to our questions so for that we need an assistant and we saw that we can [02:08:09] actually construct an assistant in the process of a post training and specifically in the process of supervised fine-tuning as we call it so in this stage we saw that it's algorithmically identical to pre-training nothing is going to change the only thing that changes is the data set so instead of Internet documents we now want to create and curate a very nice data set of conversations so we want Millions conversations on all kinds of diverse topics between a human and an [02:08:41] assistant and fundamentally these conversations are created by humans so humans write the prompts and humans write the ideal response responses and they do that based on labeling documentations now in the modern stack it's not actually done fully and manually by humans right they actually now have a lot of help from these tools so we can use language models um to help us create these data sets and that's done extensively but fundamentally it's all still coming from Human curation at the end so we create these conversations [02:09:13] that now becomes our data set we fine tune on it or continue training on it and we get an assistant and then we kind of shifted gears and started talking about some of the kind of cognitive implications of what this assistant is like and we saw that for example the assistant will hallucinate if you don't take some sort of mitigations towards it so we saw that hallucinations would be common and then we looked at some of the mitigations of those hallucinations and then we saw that the models are quite impressive and can do a lot of stuff in their head but we saw that they can also [02:09:43] Lean On Tools to become better so for example we can lo lean on a web search in order to hallucinate less and to maybe bring up some more um recent information or something like that or we can lean on tools like code interpreter so the code can so the llm can write some code and actually run it and see the results so these are some of the topics we looked at so far um now what I'd like to do is I'd like to cover the last and major stage of this Pipeline and that is reinforcement learning so reinforcement [02:10:15] learning is still kind of thought to be under the umbrella of posttraining uh but it is the last third major stage and it's a different way of training language models and usually follows as this third step so inside companies like open AI you will start here and these are all separate teams so there's a team doing data for pre-training and a team doing training for pre-training and then there's a team doing all the conversation generation in a in a different team that is kind of doing the supervis fine tuning and there will be a [02:10:45] team for the reinforcement learning as well so it's kind of like a handoff of these models you get your base model the then you find you need to be an assistant and then you go into reinforcement learning which we'll talk about uh now so that's kind of like the major flow and so let's now focus on reinforcement learning the last major stage of training and let me first actually motivate it and why we would want to do reinforcement learning and what it looks like on a high level so I would now like to try to motivate the reinforcement learning stage and what it corresponds to with something that [02:11:15] you're probably familiar with and that is basically going to school so just like you went to school to become um really good at something we want to take large language models through school and really what we're doing is um we're um we have a few paradigms of ways of uh giving them knowledge or transferring skills so in particular when we're working with textbooks in school you'll see that there are three major kind of uh pieces of information in these textbooks three classes of information [02:11:45] the first thing you'll see is you'll see a lot of exposition um and by the way this is a totally random book I pulled from the internet I I think it's some kind of an organic chemistry or something I'm not sure uh but the important thing is that you'll see that most of the text most of it is kind of just like the meat of it is exposition it's kind of like background knowledge Etc as you are reading through the words of this Exposition you can think of that roughly as training on that data so um and that's why when you're reading through this stuff this background knowledge and this all this context [02:12:16] information it's kind of equivalent to pre-training so it's it's where we build sort of like a knowledge base of this data and get a sense of the topic the next major kind of information that you will see is these uh problems and with their worked Solutions so basically a human expert in this case uh the author of this book has given us not just a problem but has also worked through the solution and the solution is basically like equivalent to having like this ideal response for an assistant so it's [02:12:48] basically the expert is showing us how to solve the problem in it's uh kind of like um in its full form so as we are reading the solution we are basically training on the expert data and then later we can try to imitate the expert um and basically um that's that roughly correspond to having the sft model that's what it would be doing so basically we've already done pre-training and we've already covered this um imitation of experts and how they solve these problems and the third [02:13:19] stage of reinforcement learning is basically the practice problems so sometimes you'll see this is just a single practice problem here but of course there will be usually many practice problems at the end of each chapter in any textbook and practice problems of course we know are critical for learning because what are they getting you to do they're getting you to practice uh to practice yourself and discover ways of solving these problems yourself and so what you get in a practice problem is you get a problem description but you're not given the solution but you are given the final [02:13:50] answer answer usually in the answer key of the textbook and so you know the final answer that you're trying to get to and you have the problem statement but you don't have the solution you are trying to practice the solution you're trying out many different things and you're seeing what gets you to the final solution the best and so you're discovering how to solve these problems so and in the process of that you're relying on number one the background information which comes from pre-training and number two maybe a little bit of imitation of human experts [02:14:20] and you can probably try similar kinds of solutions and so on so we've done this and this and now in this section we're going to try to practice and so we're going to be given prompts we're going to be given Solutions U sorry the final answers but we're not going to be given expert Solutions we have to practice and try stuff out and that's what reinforcement learning is about okay so let's go back to the problem that we worked with previously just so we have a concrete example to talk through as we explore sort of the topic [02:14:50] here so um I'm here in the Teck tokenizer because I'd also like to well I get a text box which is useful but number two I want to remind you again that we're always working with onedimensional token sequences and so um I actually like prefer this view because this is like the native view of the llm if that makes sense like this is what it actually sees it sees token IDs right okay so Emily buys three apples and two oranges each orange is $2 the total cost of all the fruit is $13 what is the cost of each apple [02:15:21] and what I'd like to what I like you to appreciate here is these are like four possible candidate Solutions as an example and they all reach the answer three now what I'd like you to appreciate at this point is that if I am the human data labeler that is creating a conversation to be entered into the training set I don't actually really know which of these conversations to um to add to the data set some of these conversations kind of set up a system equations some of them [02:15:52] sort of like just talk through it in English and some of them just kind of like skip right through to the solution um if you look at chbt for example and you give it this question it defines a system of variables and it kind of like does this little thing what we have to appreciate and uh differentiate between though is um the first purpose of a solution is to reach the right answer of course we want to get the final answer three that is the that is the important purpose here but there's kind of like a secondary purpose as well where here we are also just kind [02:16:23] of trying to make it like nice uh for the human because we're kind of assuming that the person wants to see the solution they want to see the intermediate steps we want to present it nicely Etc so there are two separate things going on here number one is the presentation for the human but number two we're trying to actually get the right answer um so let's for the moment focus on just reaching the final answer if we're only care if we only care about the final answer then which of these is the optimal or the best prompt um sorry [02:16:53] the best solution for the llm to reach the right answer um and what I'm trying to get at is we don't know me as a human labeler I would not know which one of these is best so as an example we saw earlier on when we looked at um the token sequences here and the mental arithmetic and reasoning we saw that for each token we can only spend basically a finite number of finite amount of compute here that is not very large or you should think about it that way way and so we can't actually make [02:17:23] too big of a leap in any one token is is maybe the way to think about it so as an example in this one what's really nice about it is that it's very few tokens so it's going to take us very short amount of time to get to the answer but right here when we're doing 30 - 4 IDE 3 equals right in this token here we're actually asking for a lot of computation to happen on that single individual token and so maybe this is a bad example to give to the llm because it's kind of incentivizing it to skip through the calculations very quickly and it's going to actually make up mistakes make [02:17:54] mistakes in this mental arithmetic uh so maybe it would work better to like spread out the spread it out more maybe it would be better to set it up as an equation maybe it would be better to talk through it we fundamentally don't know and we don't know because what is easy for you or I as or as human labelers what's easy for us or hard for us is different than what's easy or hard for the llm it cognition is different um and the token sequences are kind of like different hard for it and so some of the [02:18:27] token sequences here that are trivial for me might be um very too much of a leap for the llm so right here this token would be way too hard but conversely many of the tokens that I'm creating here might be just trivial to the llm and we're just wasting tokens like why waste all these tokens when this is all trivial so if the only thing we care care about is the final answer and we're separating out the issue of the presentation to the human um then we don't actually really know how to [02:18:57] annotate this example we don't know what solution to get to the llm because we are not the llm and it's clear here in the case of like the math example but this is actually like a very pervasive issue like for our knowledge is not lm's knowledge like the llm actually has a ton of knowledge of PhD in math and physics chemistry and whatnot so in many ways it actually knows more than I do and I'm I'm potentially not utilizing that knowledge in its problem solving but conversely I might be injecting a bunch of knowledge in my solutions that [02:19:28] the LM doesn't know in its parameters and then those are like sudden leaps that are very confusing to the model and so our cognitions are different and I don't really know what to put here if all we care about is the reaching the final solution and doing it economically ideally and so long story short we are not in a good position to create these uh token sequences for the LM and they're useful by imitation to initialize the system but we really want [02:19:59] the llm to discover the token sequences that work for it we need to find it needs to find for itself what token sequence reliably gets to the answer given the prompt and it needs to discover that in the process of reinforcement learning and of trial and error so let's see how this example would work like in reinforcement learning okay so we're now back in the huging face inference playground and uh that just allows me to very easily call uh different kinds of models so as an [02:20:29] example here on the top right I chose the Gemma 2 2 billion parameter model so two billion is very very small so this is a tiny model but it's okay so we're going to give it um the way that reinforcement learning will basically work is actually quite quite simple um we need to try many different kinds of solutions and we want to see which Solutions work well or not so we're basically going to take the prompt we're going to run the model and the model generates a solution and then we're going to inspect the [02:20:59] solution and we know that the correct answer for this one is $3 and so indeed the model gets it correct it says it's $3 so this is correct so that's just one attempt at DIS solution so now we're going to delete this and we're going to rerun it again let's try a second attempt so the model solves it in a bit slightly different way right every single attempt will be a different generation because these models are stochastic systems remember that at every single token here we have a probability distribution and we're sampling from that distribution so we [02:21:29] end up kind kind of going down slightly different paths and so this is a second solution that also ends in the correct answer now we're going to delete that let's go a third time okay so again slightly different solution but also gets it correct now we can actually repeat this uh many times and so in practice you might actually sample thousand of independent Solutions or even like million solutions for just a single prompt um and some of them will be correct and some of them will not be very correct and basically what we want [02:22:00] to do is we want to encourage the solutions that lead to correct answers so let's take a look at what that looks like so if we come back over here here's kind of like a cartoon diagram of what this is looking like we have a prompt and then we tried many different solutions in parallel and some of the solutions um might go well so they get the right answer which is in green and some of the solutions might go poorly and may not reach the right answer which is red now this problem here unfortunately is not the best example because it's a trivial [02:22:32] prompt and as we saw uh even like a two billion parameter model always gets it right so it's not the best example in that sense but let's just exercise some imagination here and let's just suppose that the um green ones are good and the red ones are bad okay so we generated 15 Solutions only four of them got the right answer and so now what we want to do is basically we want to encourage the kinds of solutions that lead to right answers so whatever token sequences happened in [02:23:03] these red Solutions obviously something went wrong along the way somewhere and uh this was not a good path to take through the solution and whatever token sequences there were in these Green Solutions well things went uh pretty well in this situation and so we want to do more things like it in prompts like this and the way we encourage this kind of a behavior in the future is we basically train on these sequences um but these training sequencies now are not coming from expert human annotators there's no human who decided that this [02:23:33] is the correct solution this solution came from the model itself so the model is practicing here it's tried out a few Solutions four of them seem to have worked and now the model will kind of like train on them and this corresponds to a student basically looking at their Solutions and being like okay well this one worked really well so this is this is how I should be solving these kinds of problems and uh here in this example there are many different ways to actually like really tweak the methodology a little bit here but just to give the core idea across maybe it's simplest to just think about take the [02:24:04] taking the single best solution out of these four uh like say this one that's why it was yellow uh so this is the the solution that not only led to the right answer but may maybe had some other nice properties maybe it was the shortest one or it looked nicest in some ways or uh there's other criteria you could think of as an example but we're going to decide that this the top solution we're going to train on it and then uh the model will be slightly more likely once you do the parameter update to take this path in this kind of a setting in the [02:24:36] future but you have to remember that we're going to run many different diverse prompts across lots of math problems and physics problems and whatever wherever there might be so tens of thousands of prompts maybe have in mind there's thousands of solutions prompt and so this is all happening kind of like at the same time and as we're iterating this process the model is discovering for itself what kinds of token sequences lead it to correct answers it's not coming from a human annotator the the model is kind of like [02:25:08] playing in this playground and it knows what it's trying to get to and it's discovering sequences that work for it uh these are sequences that don't make any mental leaps uh they they seem to work reliably and statistically and uh fully utilize the knowledge of the model as it has it and so uh this is the process of reinforcement learning it's basically a guess and check we're going to guess many different types of solutions we're going to check them and we're going to do more of what worked in the future and that is [02:25:38] uh reinforcement learning so in the context of what came before we see now that the sft model the supervised fine tuning model it's still helpful because it still kind of like initializes the model a little bit into to the vicinity of the correct Solutions so it's kind of like a initialization of um of the model in the sense that it kind of gets the model to you know take Solutions like write out Solutions and maybe it has an understanding of setting up a system of equations or maybe it kind of like talks through a solution so it gets you into [02:26:08] the vicinity of correct Solutions but reinforcement learning is where everything gets dialed in we really discover the solutions that work for the model get the right answers we encourage them and then the model just kind of like gets better over time time okay so that is the high Lev process for how we train large language models in short we train them kind of very similar to how we train children and basically the only difference is that children go through chapters of books and they do all these different types of training exercises um kind of within the chapter of each book [02:26:39] but instead when we train AIS it's almost like we kind of do it stage by stage depending on the type of that stage so first what we do is we do pre-training which as we saw is equivalent to uh basically reading all the expository material so we look at all the textbooks at the same time and we read all the exposition and we try to build a knowledge base the second thing then is we go into the sft stage which is really looking at all the fixed uh sort of like solutions from Human Experts of all the different kinds of [02:27:09] worked Solutions across all the textbooks and we just kind of get an sft model which is able to imitate the experts but does so kind of blindly it just kind of like does its best guess uh kind of just like trying to mimic statistically the expert behavior and so that's what you get when you look at all the work Solutions and then finally in the last stage we do all the practice problems in the RL stage across all the textbooks we only do the practice problems and that's how we get the RL model so on a high level the way we [02:27:40] train llms is very much equivalent uh to the process that we train uh that we use for training of children the next point I would like to make is that actually these first two stat ages pre-training and surprise fine-tuning they've been around for years and they are very standard and everyone does them all the different llm providers it is this last stage the RL training that is a lot more early in its process of development and is not standard yet in the field and so um this stage is a lot more kind of early and nent and the reason for that [02:28:11] is because I actually skipped over a ton of little details here in this process the high level idea is very simple it's trial and there learning but there's a ton of details and little math mathematical kind of like nuances to exactly how you pick the solutions that are the best and how much you train on them and what is the prompt distribution and how to set up the training run such that this actually works so there's a lot of little details and knobs to the core idea that is very very simple and so getting the details right here uh is not trivial and so a lot of companies like for example open and other LM [02:28:41] providers have experimented internally with reinforcement learning fine tuning for llms for a while but they've not talked about it publicly um it's all kind of done inside the company and so that's why the paper from Deep seek that came out very very recently was such a big deal because this is a paper from this company called DC Kai in China and this paper really talked very publicly about reinforcement learning fine training for large language models and how incredibly important it is for large language [02:29:12] models and how it brings out a lot of reasoning capabilities in the models we'll go into this in a second so this paper reinvigorated the public interest of using RL for llms and gave a lot of the um sort of n-r details that are needed to reproduce their results and actually get the stage to work for large langage models so let me take you briefly through this uh deep seek R1 paper and what happens when you actually correctly apply RL to language models and what that looks like and what that gives you so the first thing I'll scroll to is this uh kind of figure two here [02:29:43] where we are looking at the Improvement in how the models are solving mathematical problems so this is the accuracy of solving mathematical problems on the a accuracy and then we can go to the web page and we can see the kinds of problems that are actually in these um these the kinds of math problems that are being measured here so these are simple math problems you can um pause the video if you like but these are the kinds of problems that basically the models are being asked to solve and you can see that in the beginning they're not doing very well but then as you update the model with this many thousands of steps their accuracy kind [02:30:14] of continues to climb so the models are improving and they're solving these problems with a higher accuracy as you do this trial and error on a large data set of these kinds of problems and the models are discovering how to solve math problems but even more incredible than the quantitative kind of results of solving these problems with a higher accuracy is the qualitative means by which the model achieves these results so when we scroll down uh one of the figures here that is kind of interesting is that later on in the optimization the model seems to be uh [02:30:46] using average length per response uh goes up up so the model seems to be using more tokens to get its higher accuracy results so it's learning to create very very long Solutions why are these Solutions very long we can look at them qualitatively here so basically what they discover is that the model solution get very very long partially because so here's a question and here's kind of the answer from the model what the model learns to do um and this is an immerging property of new optimization it just discovers that this is good for [02:31:17] problem solving is it starts to do stuff like this wait wait wait that's Nota moment I can flag here let's reevaluate this step by step to identify the correct sum can be so what is the model doing here right the model is basically re-evaluating steps it has learned that it works better for accuracy to try out lots of ideas try something from different perspectives retrace reframe backtrack is doing a lot of the things that you and I are doing in the process of problem solving for mathematical questions but it's rediscovering what happens in your head not what you put [02:31:48] down on the solution and there is no human who can hardcode this stuff in the ideal assistant response this is only something that can be discovered in the process of reinforcement learning because you wouldn't know what to put here this just turns out to work for the model and it improves its accuracy in problem solving so the model learns what we call these chains of thought in your head and it's an emergent property of the optim of the optimization and that's what's bloating up the response length but that's also what's increasing the [02:32:18] accuracy of the problem problem solving so what's incredible here is basically the model is discovering ways to think it's learning what I like to call cognitive strategies of how you manipulate a problem and how you approach it from different perspectives how you pull in some analogies or do different kinds of things like that and how you kind of uh try out many different things over time uh check a result from different perspectives and how you kind of uh solve problems but here it's kind of discovered by the RL so extremely incredible to see this emerge in the optimization without [02:32:48] having to hardcode it anywhere the only thing we've given it are the correct answers and this comes out from trying to just solve them correctly which is incredible um now let's go back to actually the problem that we've been working with and let's take a look at what it would look like uh for uh for this kind of a model what we call reasoning or thinking model to solve that problem okay so recall that this is the problem we've been working with and when I pasted it into chat GPT 40 I'm getting this kind of a response let's take a look at what [02:33:19] happens when you give this same query to what's called a reasoning or a thinking model this is a model that was trained with reinforcement learning so this model described in this paper DC car1 is available on chat. dec.com uh so this is kind of like the company uh that developed is hosting it you have to make sure that the Deep think button is turned on to get the R1 model as it's called we can paste it here and run it and so let's take a look at what happens now and what is the output of the model okay so here's it says so this [02:33:51] is previously what we get using basically what's an sft approach a supervised funing approach this is like mimicking an expert solution this is what we get from the RL model okay let me try to figure this out so Emily buys three apples and two oranges each orange cost $2 total is 13 I need to find out blah blah blah so here you you um as you're reading this you can't escape thinking that this model is thinking um is definitely pursuing the solution solution it deres that it must [02:34:21] cost $3 and then it says wait a second let me check my math again to be sure and then it tries it from a slightly different perspective and then it says yep all that checks out I think that's the answer I don't see any mistakes let me see if there's another way to approach the problem maybe setting up an equation let's let the cost of one apple be $8 then blah blah blah yep same answer so definitely each apple is $3 all right confident that that's correct and then what it does once it sort of um did the thinking process is it writes up [02:34:51] the nice solution for the human and so this is now considering so this is more about the correctness aspect and this is more about the presentation aspect where it kind of like writes it out nicely and uh boxes in the correct answer at the bottom and so what's incredible about this is we get this like thinking process of the model and this is what's coming from the reinforcement learning process this is what's bloating up the length of the token sequences they're doing thinking and they're trying different ways this is what's giving you higher accuracy in problem [02:35:22] solving and this is where we are seeing these aha moments and these different strategies and these um ideas for how you can make sure that you're getting the correct answer the last point I wanted to make is some people are a little bit nervous about putting you know very sensitive data into chat.com because this is a Chinese company so people don't um people are a little bit careful and Cy with that a little bit um deep seek R1 is a model that was released by this company so this is an open source model [02:35:52] or open weights model it is available for anyone to download and use you will not be able to like run it in its full um sort of the full model in full Precision you won't run that on a MacBook but uh or like a local device because this is a fairly large model but many companies are hosting the full largest model one of those companies that I like to use is called together. so when you go to together. you sign up and you go to playgrounds you can can select here in the chat deep seek R1 and there's many different kinds [02:36:23] of other models that you can select here these are all state-of-the-art models so this is kind of similar to the hugging face inference playground that we've been playing with so far but together. a will usually host all the state-of-the-art models so select DT car1 um you can try to ignore a lot of these I think the default settings will often be okay and we can put in this and because the model was released by Deep seek what you're getting here should be basically equivalent to what you're getting here now because of the randomness in the sampling we're going to get something slightly different uh [02:36:53] but in principle this should be uh identical in terms of the power of the model and you should be able to see the same things quantitatively and qualitatively uh but uh this model is coming from kind of a an American company so that's deep seek and that's the what's called a reasoning model now when I go back to chat uh let me go to chat here okay so the models that you're going to see in the drop down here some of them like 01 03 mini O3 mini High Etc they are talking about uses Advanced reasoning now what this is [02:37:23] referring to uses Advanced reasoning is it's referring to the fact that it was trained by reinforcement learning with techniques very similar to those of deep C car1 per public statements of opening ey employees uh so these are thinking models trained with RL and these models like GPT 4 or GPT 4 40 mini that you're getting in the free tier you should think of them as mostly sft models supervised fine tuning models they don't actually do this like thinking as as you see in the RL models and even though there's a little bit of reinforcement [02:37:53] learning involved with these models and I'll go that into that in a second these are mostly sft models I think you should think about it that way so in the same way as what we saw here we can pick one of the thinking models like say 03 mini high and these models by the way might not be available to you unless you pay a Chachi PT subscription of either $20 per month or $200 per month for some of the top models so we can pick a thinking model and run now what's going to happen here is it's going to say reasoning and it's going to start to do stuff like [02:38:23] this and um what we're seeing here is not exactly the stuff we're seeing here so even though under the hood the model produces these kinds of uh kind of chains of thought opening ey chooses to not show the exact chains of thought in the web interface it shows little summaries of that of those chains of thought and open kind of does this I think partly because uh they are worried about what's called the distillation risk that is that someone could come in and actually try to imitate those reasoning traces and recover a lot of [02:38:53] the reasoning performance by just imitating the reasoning uh chains of thought and so they kind of hide them and they only show little summaries of them so you're not getting exactly what you would get in deep seek as with respect to the reasoning itself and then they write up the solution so these are kind of like equivalent even though we're not seeing the full under the hood details now in terms of the performance uh these models and deep seek models are currently rly on par I would say it's kind of hard to tell because of the evaluations but if you're paying $200 per month to open AI [02:39:24] some of these models I believe are currently they basically still look better uh but deep seek R1 for now is still a very solid choice for a thinking model that would be available to you um sort of um either on this website or any other website because the model is open weights you can just download it so that's thinking models so what is the summary so far well we've talked about reinforcement learning and the fact that thinking emerges in the process of the optimization on when we basically run RL [02:39:55] on many math uh and kind of code problems that have verifiable Solutions so there's like an answer three Etc now these thinking models you can access in for example deep seek or any inference provider like together. a and choosing deep seek over there these thinking models are also available uh in chpt under any of the 01 or O3 models but these GPT 4 R models Etc they're not thinking models you should think of them as mostly sft models now [02:40:25] if you are um if you have a prompt that requires Advanced reasoning and so on you should probably use some of the thinking models or at least try them out but empirically for a lot of my use when you're asking a simpler question there's like a knowledge based question or something like that this might be Overkill like there's no need to think 30 seconds about some factual question so for that I will uh sometimes default to just GPT 40 so empirically about 80 90% of my use is just gp4 and when I come across a very difficult problem like in math and code Etc I will reach for the thinking models but then I [02:40:56] have to wait a bit longer because they're thinking um so you can access these on chat on deep seek also I wanted to point out that um AI studio. go.com even though it looks really busy really ugly because Google's just unable to do this kind of stuff well it's like what is happening but if you choose model and you choose here Gemini 2.0 flash thinking experimental 01 21 if you choose that one that's also a a kind of early experiment experimental of a thinking model by Google so we can go [02:41:27] here and we can give it the same problem and click run and this is also a thinking problem a thinking model that will also do something similar and comes out with the right answer here so basically Gemini also offers a thinking model anthropic currently does not offer a thinking model but basically this is kind of like the frontier development of these llms I think RL is kind of like this new exciting stage but getting the details right is difficult and that's why all these models and thinking models are currently experimental as of 2025 very [02:41:57] early 2025 um but this is kind of like the frontier development of pushing the performance on these very difficult problems using reasoning that is emerging in these optimizations one more connection that I wanted to bring up is that the discovery that reinforcement learning is extremely powerful way of learning is not new to the field of AI and one place what we've already seen this demonstrated is in the game of Go and famously Deep Mind developed the system alphago and you can watch a movie about it um where the system is learning [02:42:29] to play the game of go against top human players and um when we go to the paper underlying alphago so in this paper when we scroll down we actually find a really interesting plot um that I think uh is kind of familiar uh to us and we're kind of like we discovering in the more open domain of arbitrary problem solving instead of on the closed specific domain of the game of Go but basically what they saw and we're going to see this in llms as [02:42:59] well as this becomes more mature is this is the ELO rating of playing game of Go and this is leas dull an extremely strong human player and here what they are comparing is the strength of a model learned trained by supervised learning and a model trained by reinforcement learning so the supervised learning model is imitating human expert players so if you just get a huge amount of games played by expert players in the game of Go and you try to imitate them you are going to get better but then you top out and you never quite get better [02:43:31] than some of the top top top players of in the game of Go like LEL so you're never going to reach there because you're just imitating human players you can't fundamentally go beyond a human player if you're just imitating human players but in a process of reinforcement learning is significantly more powerful in reinforcement learning for a game of Go it means that the system is playing moves that empirically and statistically lead to win to winning the game and so alphago is a system where it kind of plays against it itself [02:44:02] and it's using reinforcement learning to create rollouts so it's the exact same diagram here but there's no prompt it's just uh because there's no prompt it's just a fixed game of Go but it's trying out lots of solutions it's trying out lots of plays and then the games that lead to a win instead of a specific answer are reinforced they're they're made stronger and so um the system is learning basically the sequences of actions that empirically and statistically lead to winning the game and reinforcement [02:44:32] learning is not going to be constrained by human performance and reinforcement learning can do significantly better and overcome even the top players like Lisa Dole and so uh probably they could have run this longer and they just chose to crop it at some point because this costs money but this is very powerful demonstration of reinforcement learning and we're only starting to kind of see hints of this diagram in larger language models for reasoning problems so we're not going to get too far by just imitating experts we need to go beyond that set up these like little game [02:45:03] environments and get let let the system discover reasoning traces or like ways of solving problems uh that are unique and that uh just basically work well now on this aspect of uniqueness notice that when you're doing reinforcement learning nothing prevents you from veering off the distribution of how humans are playing the game and so when we go back to uh this alphao search here one of the suggested modifications is called move 37 and move 37 in alphao [02:45:34] is referring to a specific point in time where alphago basically played a move that uh no human expert would play uh so the probability of this move uh to be played by a human player was evaluated to be about 1 in 10th ,000 so it's a very rare move but in retrospect it was a brilliant move so alphago in the process of reinforcement learning discovered kind of like a strategy of playing that was unknown to humans and but is in retrospect uh brilliant I recommend this YouTube video um leis do [02:46:04] versus alphao move 37 reactions and Analysis and this is kind of what it looked like when alphao played this move value that's a very that's a very surprising move I thought I thought it was I thought it was a mistake when I see this move anyway so basically people are kind of freaking out because it's a it's a move that a human would not play that alphago played because in its training uh this move seemed to be a good idea it just happens [02:46:35] not to be a kind of thing that a humans would would do and so that is again the power of reinforcement learning and in principle we can actually see the equivalence of that if we continue scaling this Paradigm in language models and what that looks like is kind of unknown so so um what does it mean to solve problems in such a way that uh even humans would not be able to get how can you be better at reasoning or thinking than humans how can you go beyond just uh a thinking human like maybe it means discovering analogies [02:47:05] that humans would not be able to uh create or maybe it's like a new thinking strategy it's kind of hard to think through uh maybe it's a holy new language that actually is not even English maybe it discovers its own language that is a lot better at thinking um because the model is unconstrained to even like stick with English uh so maybe it takes a different language to think in or it discovers its own language so in principle the behavior of the system is a lot less defined it is open to do whatever works [02:47:37] and it is open to also slowly Drift from the distribution of its training data which is English but all of that can only be done if we have a very large diverse set of problems in which the these strategy can be refined and perfected and so that is a lot of the frontier LM research that's going on right now is trying to kind of create those kinds of prompt distributions that are large and diverse these are all kind of like game environments in which the llms can practice their thinking and uh it's kind of like writing you know these practice problems we have to create [02:48:07] practice problems for all of domains of knowledge and if we have practice problems and tons of them the models will be able to reinforcement learning reinforcement learn on them and kind of uh create these kinds of uh diagrams but in the domain of open thinking instead of a closed domain like game of Go there's one more section within reinforcement learning that I wanted to cover and that is that of learning in unverifiable domains so so far all of the problems that we've looked at are in what's called verifiable domains that is [02:48:38] any candidate solution we can score very easily against a concrete answer so for example answer is three and we can very easily score these Solutions against the answer of three either we require the models to like box in their answers and then we just check for equality of whatever is in the box with the answer or you can also use uh kind of what's called an llm judge so the llm judge looks at a solution and it gets the answer and just basically scores the solution for whether it's consistent with the answer or not and [02:49:08] llms uh empirically are good enough at the current capability that they can do this fairly reliably so we can apply those kinds of techniques as well in any case we have a concrete answer and we're just checking Solutions again against it and we can do this automatically with no kind of humans in the loop the problem is that we can't apply the strategy in what's called unverifiable domains so usually these are for example creative writing tasks like write a joke about Pelicans or write a poem or summarize a paragraph or something like that in these kinds of domains it becomes harder to score our different solutions to this [02:49:39] problem so for example writing a joke about Pelicans we can generate lots of different uh jokes of course that's fine for example we can go to chbt and we can get it to uh generate a joke about Pelicans uh so much stuff in their beaks because they don't bellan in backpacks what okay we can uh we can try something else why don't Pelicans ever pay for their drinks because they always B it to someone else haha okay so these models [02:50:10] are not obviously not very good at humor actually I think it's pretty fascinating because I think humor is secretly very difficult and the model have the capability I think anyway in any case you could imagine creating lots of jokes the problem that we are facing is how do we score them now in principle we could of course get a human to look at all these jokes just like I did right now the problem with that is if you are doing reinforcement learning you're going to be doing many thousands of updates and for each update you want to be looking at say thousands of prompts [02:50:40] and for each prompt you want to be potentially looking at looking at hundred or thousands of different kinds of generations and so there's just like way too many of these to look at and so um in principle you could have a human inspect all of them and score them and decide that okay maybe this one is funny and uh maybe this one is funny and this one is funny and we could train on them to get the model to become slightly better at jokes um in the context of pelicans at least um the problem is that it's just like way too much human time [02:51:10] this is an unscalable strategy we need some kind of an automatic strategy for doing this and one sort of solution to this was proposed in this paper uh that introduced what's called reinforcement learning from Human feedback and so this was a paper from open at the time and many of these people are now um co-founders in anthropic um and this kind of proposed a approach for uh basically doing reinforcement learning in unverifiable domains so let's take a look at how that works so this is the cartoon diagram of the core ideas involved so as I [02:51:41] mentioned the native approach is if we just set Infinity human time we could just run RL in these domains just fine so for example we can run RL as usual if I have Infinity humans I would I just want to do and these are just cartoon numbers I want to do 1,000 updates where each update will be on 1,000 prompts and in for each prompt we're going to have 1,000 roll outs that we're scoring so we can run RL with this kind of a setup the problem is in the process of doing this I will need to run one I will need to [02:52:12] ask a human to evaluate a joke a total of 1 billion times and so that's a lot of people looking at really terrible jokes so we don't want to do that so instead we want to take the arlef approach so um in our Rel of approach we are kind of like the the core trick is that of indirection so we're going to involve humans just a little bit and the way we cheat is that we basically train a whole separate neural network that we call a reward model and this neural network will kind of like imitate human [02:52:44] scores so we're going to ask humans to score um roll we're going to then imitate human scores using a neural network and this neural network will become a kind of simulator of human preferences and now that we have a neural network simulator we can do RL against it so instead of asking a real human we're asking a simulated human for their score of a joke as an example and so once we have a simulator we're often racist because we can query it as many times as we want to and it's all whole [02:53:16] automatic process and we can now do reinforcement learning with respect to the simulator and the simulator as you might expect is not going to be a perfect human but if it's at least statistically similar to human judgment then you might expect that this will do something and in practice indeed uh it does so once we have a simulator we can do RL and everything works great so let me show you a cartoon diagram a little bit of what this process looks like although the details are not 100 like super important it's just a core idea of how this works so here I have a cartoon diagram of a hypothetical example of [02:53:46] what training the reward model would look like so we have a prompt like write a joke about picans and then here we have five separate roll outs so these are all five different jokes just like this one now the first thing we're going to do is we are going to ask a human to uh order these jokes from the best to worst so this is uh so here this human thought that this joke is the best the funniest so number one joke this is number two joke number three joke four [02:54:16] and five so this is the worst joke we're asking humans to order instead of give scores directly because it's a bit of an easier task it's easier for a human to give an ordering than to give precise scores now that is now the supervision for the model so the human has ordered them and that is kind of like their contribution to the training process but now separately what we're going to do is we're going to ask a reward model uh about its scoring of these jokes now the reward model is a whole separate neural network completely separate neural net um and it's also [02:54:47] probably a transform uh but it's not a language model in the sense that it generates diverse language Etc it's just a scoring model so the reward model will take as an input The Prompt number one and number two a candidate joke so um those are the two inputs that go into the reward model so here for example the reward model would be taken this prompt and this joke now the output of a reward model is a single number and this number is thought of as a score and it can range for example [02:55:18] from Z to one so zero would be the worst score and one would be the best score so here are some examples of what a hypothetical reward model at some stage in the training process would give uh s scoring to these jokes so 0.1 is a very low score 08 is a really high score and so on and so now um we compare the scores given by the reward model with uh the ordering given by the human and there's a precise mathematical way to actually calculate this uh basically set [02:55:49] up a loss function and calculate a kind of like a correspondence here and uh update a model based on it but I just want to give you the intuition which is that as an example here for this second joke the the human thought that it was the funniest and the model kind of agreed right 08 is a relatively high score but this score should have been even higher right so after an update we would expect that maybe this score should have been will actually grow after an update of the network to be like say 081 or something um for this one here they [02:56:19] actually are in a massive disagreement because the human thought that this was number two but here the the score is only 0.1 and so this score needs to be much higher so after an update on top of this um kind of a supervision this might grow a lot more like maybe it's 0.15 or something like that um and then here the human thought that this one was the worst joke but here the model actually gave it a fairly High number so you might expect that after the update uh this would come down to maybe 3 3.5 or something like that so [02:56:50] basically we're doing what we did before we're slightly nudging the predictions from the models using a neural network training process and we're trying to make the reward model scores be consistent with human ordering and so um as we update the reward model on human data it becomes better and better simulator of the scores and orders uh that humans provide and then becomes kind of like the the neural the simulator of human preferences which we can then do RL [02:57:20] against but critically we're not asking humans one billion times to look at a joke we're maybe looking at th000 prompts and five roll outs each so maybe 5,000 jokes that humans have to look at in total and they just give the ordering and then we're training the model to be consistent with that ordering and I'm skipping over the mathematical details but I just want you to understand a high level idea that uh this reward model is do is basically giving us this scour and we have a way of training it to be consistent with human orderings and that's how rhf works okay so that is [02:57:51] the rough idea we basically train simulators of humans and RL with respect to those simulators now I want to talk about first the upside of reinforcement learning from Human feedback the first thing is that this allows us to run reinforcement learning which we know is incredibly powerful kind of set of techniques and it allows us to do it in arbitrary domains and including the ones that are unverifiable so things like summarization and poem writing joke writing or any other creative writing really uh in domains [02:58:21] outside of math and code Etc now empirically what we see when we actually apply rhf is that this is a way to improve the performance of the model and uh I have a top answer for why that might be but I don't actually know that it is like super well established on like why this is you can empirically observe that when you do rhf correctly the models you get are just like a little bit better um but as to why is I think like not as clear so here's my best guess my best guess is that this is possibly mostly due to the discriminator [02:58:52] generator Gap what that means is that in many cases it is significantly easier to discriminate than to generate for humans so in particular an example of this is um in when we do supervised fine-tuning right sft we're asking humans to generate the ideal assistant response and in many cases here um as I've shown it uh the ideal response is very simple to write but in many cases might not be so for [02:59:22] example in summarization or poem writing or joke writing like how are you as a human assist as a human labeler um supposed to give the ideal response in these cases it requires creative human writing to do that and so rhf kind of sidesteps this because we get um we get to ask people a significantly easier question as a data labelers they're not asked to write poems directly they're just given five poems from the model and they're just asked to order them and so that's just a much easier task for a human labeler to do and so what I think [02:59:53] this allows you to do basically is it um it kind of like allows a lot more higher accuracy data because we're not asking people to do the generation task which can be extremely difficult like we're not asking them to do creative writing we're just trying to get them to distinguish between creative writings and uh find the ones that are best and that is the signal that humans are providing just the ordering and that is their input into the system and then the system in rhf just discovers the kinds [03:00:23] of responses that would be graded well by humans and so that step of indirection allows the models to become a bit better so that is the upside of our LF it allows us to run RL it empirically results in better models and it allows uh people to contribute their supervision uh even without having to do extremely difficult tasks um in the case of writing ideal responses unfortunately our HF also comes with significant downsides and so um the main one is that [03:00:54] basically we are doing reinforcement learning not with respect to humans and actual human judgment but with respect to a lossy simulation of humans right and this lossy simulation could be misleading because it's just a it's just a simulation right it's just a language model that's kind of outputting scores and it might not perfectly reflect the opinion of an actual human with an actual brain in all the possible different cases so that's number one which is actually something even more subtle and devious going on that uh really dramatically holds back our LF as a [03:01:24] technique that we can really scale to significantly um kind of Smart Systems and that is that reinforcement learning is extremely good at discovering a way to game the model to game the simulation so this reward model that we're constructing here that gives the course these models are Transformers these Transformers are massive neurals they have billions of parameters and they imitate humans but they do so in a kind of like a simulation way now the problem [03:01:54] is that these are massive complicated systems right there's a billion parameters here that are outputting a single score it turns out that there are ways to gain these models you can find kinds of inputs that were not part of their training set and these inputs inexplicably get very high scores but in a fake way so very often what you find if you run our lch for very long so for example if we do 1,000 updates which is like say a lot of updates you might expect that your jokes are getting [03:02:25] better and that you're getting like real bangers about Pelicans but that's not EXA exactly what happens what happens is that uh in the first few hundred steps the jokes about Pelicans are probably improving a little bit and then they actually dramatically fall off the cliff and you start to get extremely nonsensical results like for example you start to get um the top joke about Pelicans starts to be the and this makes no sense right like when you look at it why should this be a top joke but when you take the the and you plug it into your reward model you'd [03:02:55] expect score of zero but actually the reward model loves this as a joke it will tell you that the the the theth is a score of 1. Z this is a top joke and this makes no sense right but it's because these models are just simulations of humans and they're massive neural lots and you can find inputs at the bottom that kind of like get into the part of the input space that kind of gives you nonsensical results these examples are what's called adversarial examples and I'm not going to go into the topic too much but these are adversarial inputs to the model they [03:03:26] are specific little inputs that kind of go between the nooks and crannies of the model and give nonsensical results at the top now here's what you might imagine doing you say okay the the the is obviously not score of one um it's obviously a low score so let's take the the the the the let's add it to the data set and give it an ordering that is extremely bad like a score of five and indeed your model will learn that the D should have a very low score and it will give it score of zero the problem is that there will always be basically infinite number of nonsensical [03:03:57] adversarial examples hiding in the model if you iterate this process many times and you keep adding nonsensical stuff to your reward model and giving it very low scores you can you'll never win the game uh you can do this many many rounds and reinforcement learning if you run it long enough will always find a way to gain the model it will discover adversarial examples it will get get really high scores uh with nonsensical results and fundamentally this is because our scoring function is a giant neural nut and RL is extremely good at [03:04:28] finding just the ways to trick it uh so long story short you always run rhf put for maybe a few hundred updates the model is getting better and then you have to crop it and you are done you can't run too much against this reward model because the optimization will start to game it and you basically crop it and you call it and you ship it um and uh you can improve the reward model but you kind of like come across these situations eventually at some point so [03:05:00] rhf basically what I usually say is that RF is not RL and what I mean by that is I mean RF is RL obviously but it's not RL in the magical sense this is not RL that you can run indefinitely these kinds of problems like where you are getting con correct answer you cannot gain this as easily you either got the correct answer or you didn't and the scoring function is much much simpler you're just looking at the boxed area and seeing if the result is correct so it's very difficult to gain these functions but uh gaming a reward [03:05:32] model is possible now in these verifiable domains you can run RL indefinitely you could run for tens of thousands hundreds of thousands of steps and discover all kinds of really crazy strategies that we might not even ever think about of Performing really well for all these problems in the game of Go there's no way to to beat to basically game uh the winning of a game or the losing of a game we have a perfect simulator we know all the different uh where all the stones are placed and we can calculate uh whether someone has won or not there's no way to gain that and [03:06:03] so you can do RL indefinitely and you can eventually be beat even leol but with models like this which are gameable you cannot repeat this process indefinitely so I kind of see rhf as not real RL because the reward function is gameable so it's kind of more like in the realm of like little fine-tuning it's a little it's a little Improvement but it's not something that is fundamentally set up correctly where you can insert more compute run for longer and get much better and magical results [03:06:34] so it's it's uh it's not RL in that sense it's not RL in the sense that it lacks magic um it can find you in your model and get a better performance and indeed if we go back to chat GPT the GPT 40 model has gone through rhf because it works well but it's just not RL in the same sense rlf is like a little fine tune that slightly improves your model is maybe like the way I would think about it okay so that's most of the technical content that I wanted to cover I took you through the three major stages and paradigms of training these [03:07:05] models pre-training supervised fine tuning and reinforcement learning and I showed you that they Loosely correspond to the process we already use for teaching children and so in particular we talked about pre-training being sort of like the basic knowledge acquisition of reading Exposition supervised fine tuning being the process of looking at lots and lots of worked examples and imitating experts and practice problems the only difference is that we now have to effectively write textbooks for llms and AIS across all the disciplines of [03:07:35] human knowledge and also in all the cases where we actually would like them to work like code and math and you know basically all the other disciplines so we're in the process of writing textbooks for them refining all the algorithms that I've presented on the high level and then of course doing a really really good job at the execution of training these models at scale and efficiently so in particular I didn't go into too many details but these are extremely large and complicated distributed uh sort of um jobs that have to run over tens of [03:08:07] thousands or even hundreds of thousands of gpus and the engineering that goes into this is really at the stateof the art of what's possible with computers at that scale so I didn't cover that aspect too much but um this is very kind of serious and they were underlying all these very simple algorithms ultimately now I also talked about sort of like the theory of mind a little bit of these models and the thing I want you to take away is that these models are really good but they're extremely useful as tools for your work you shouldn't uh [03:08:38] sort of trust them fully and I showed you some examples of that even though we have mitigations for hallucinations the models are not perfect and they will hallucinate still it's gotten better over time and it will continue to get better but they can hallucinate in other words in in addition to that I covered kind of like what I call the Swiss cheese uh sort of model of llm capabilities that you should have in your mind the models are incredibly good across so many different disciplines but then fail randomly almost in some unique cases so for example what is bigger 9.11 or 9.9 like the model doesn't know but [03:09:09] simultaneously it can turn around and solve Olympiad questions and so this is a hole in the Swiss cheese and there are many of them and you don't want to trip over them so don't um treat these models as infallible models check their work use them as tools use them for inspiration use them for the first draft but uh work with them as tools and be ultimately respons responsible for the you know product of your work and that's roughly what I wanted to talk about this is how they're trained [03:09:40] and this is what they are let's now turn to what are some of the future capabilities of these models uh probably what's coming down the pipe and also where can you find these models I have a few blow points on some of the things that you can expect coming down the pipe the first thing you'll notice is that the models will very rapidly become multimodal everything I talked about above concerned text but very soon we'll have llms that can not just handle text but they can also operate natively and very easily over audio so they can hear and speak and also images so they can [03:10:10] see and paint and we're already seeing the beginnings of all of this uh but this will be all done natively inside inside the language model and this will enable kind of like natural conversations and roughly speaking the reason that this is actually no different from everything we've covered above is that as a baseline you can tokenize audio and images and apply the exact same approaches of everything that we've talked about above so it's not a fundamental change it's just uh it's just a to we have to add some tokens so as an example for tokenizing audio we [03:10:41] can look at slices of the spectrogram of the audio signal and we can tokenize that and just add more tokens that suddenly represent audio and just add them into the context windows and train on them just like above the same for images we can use patches and we can separately tokenize patches and then what is an image an image is just a sequence of tokens and this actually kind of works and there's a lot of early work in this direction and so we can just create streams of tokens that are representing audio images as well as text and interpers them and handle them [03:11:12] all simultaneously in a single model so that's one example of multimodality uh second something that people are very interested in is currently most of the work is that we're handing individual tasks to the models on kind of like a silver platter like please solve this task for me and the model sort of like does this little task but it's up to us to still sort of like organize a coherent execution of tasks to perform jobs and the models are not yet at the capability required to do this in a coherent error correcting way [03:11:43] over long periods of time so they're not able to fully string together tasks to perform these longer running jobs but they're getting there and this is improving uh over time but uh probably what's going to happen here is we're going to start to see what's called agents which perform tasks over time and you you supervise them and you watch their work and they come up to once in a while report progress and so on so we're going to see more long running agents uh tasks that don't just take you know a few seconds of response but many tens of [03:12:13] seconds or even minutes or hours over time uh but these uh models are not infallible as we talked about above so all of this will require supervision so for example in factories people talk about the human to robot ratio uh for automation I think we're going to see something similar in the digital space where we are going to be talking about human to agent ratios where humans becomes a lot more supervisors of agent tasks um in the digital domain uh next um I think everything is going to become a lot more pervasive and invisible so it's kind of like [03:12:44] integrated into the tools and everywhere um and in addition kind of like computer using so right now these models aren't able to take actions on your behalf but I think this is a separate bullet point um if you saw chpt launch the operator then uh that's one early example of that where you can actually hand off control to the model to perform you know keyboard and mouse actions on your behalf so that's also something that that I think is very interesting the last point I have here is just a general [03:13:14] comment that there's still a lot of research to potentially do in this domain main one example of that uh is something along the lines of test time training so remember that everything we've done above and that we talked about has two major stages there's first the training stage where we tune the parameters of the model to perform the tasks well once we get the parameters we fix them and then we deploy the model for inference from there the model is fixed it doesn't change anymore it doesn't learn from all the stuff that it's doing a test time it's a fixed um number of parameters and the only thing [03:13:45] that is changing is now the token inside the context windows and so the only type of learning or test time learning that the model has access to is the in context learning of its uh kind of like uh dynamically adjustable context window depending on like what it's doing at test time so but I think this is still different from humans who actually are able to like actually learn uh depending on what they're doing especially when you sleep for example like your brain is updating your parameters or something like that right so there's no kind of equivalent of that currently in these models and tools so there's a lot of [03:14:16] like um more wonky ideas I think that are to be explored still and uh in particular I think this will be necessary because the context window is a finite and precious resource and especially once we start to tackle very long running multimodal tasks and we're putting in videos and these token windows will basically start to grow extremely large like not thousands or even hundreds of thousands but significantly beyond that and the only trick uh the only kind of trick we have Avail to us right now is to make the context Windows longer but I think that [03:14:46] that approach by itself will will not will not scale to actual long running tasks that are multimodal over time and so I think new ideas are needed in some of those disciplines um in some of those kind of cases in the main where these tasks are going to require very long contexts so those are some examples of some of the things you can um expect coming down the pipe let's now turn to where you can actually uh kind of keep track of this progress and um you know be up to date with the latest and grest of what's happening in the field so I would say the three resources that I [03:15:16] have consistently used to stay up to date are number one El Marina uh so let me show you El Marina this is basically an llm leader board and it ranks all the top models and the ranking is based on human comparisons so humans prompt these models and they get to judge which one gives a better answer they don't know which model is which they're just looking at which model is the better answer and you can calculate a ranking and then you get some results and so what you can hear is what you can see [03:15:46] here is the different organizations like Google Gemini for example that produce these models when you click on any one of these it takes you to the place where that model is hosted and then here we see Google is currently on top with open AI right behind here we see deep seek in position number three now the reason this is a big deal is the last column here you see license deep seek is an MIT license model it's open weights anyone can use these weights uh anyone can download them anyone can host their own version of Deep seek and they can use it in what [03:16:16] whatever way they like and so it's not a proprietary model that you don't have access to it's it's basically an open weight release and so this is kind of unprecedented that a model this strong was released with open weights so pretty cool from the team next up we have a few more models from Google and open Ai and then when you continue to scroll down you start to see some other Usual Suspects so xai here anthropic with son it uh here at number 14 and um then [03:16:47] meta with llama over here so llama similar to deep seek is an open weights model and so uh but it's down here as opposed to up here now I will say that this leaderboard was really good for a long time I do think that in the last few months it's become a little bit gamed um and I don't trust it as much as I used to I think um just empirically I feel like a lot of people for example are using a Sonet from anthropic and that it's a really good model so but [03:17:17] that's all the way down here um in number 14 and conversely I think not as many people are using Gemini but it's racking really really high uh so I think use this as a first pass uh but uh sort of try out a few of the models for your tasks and see which one performs better the second thing that I would point to is the uh AI news uh newsletter so AI news is not very creatively named but it is a very good newsletter produced by swix and friends so thank you for maintaining it [03:17:47] and it's been very helpful to me because it is extremely comprehensive so if you go to archives uh you see that it's produced almost every other day and um it is very comprehensive and some of it is written by humans and curated by humans but a lot of it is constructed automatically with llms so you'll see that these are very comprehensive and you're probably not missing anything major if you go through it of course you're probably not going to go through it because it's so long but I do think that these summaries all the way up top are quite good and I think have some human oversight uh so this has been very [03:18:18] helpful to me and the last thing I would point to is just X and Twitter uh a lot of um AI happens on X and so I would just follow people who you like and trust and get all your latest and greatest uh on X as well so those are the major places that have worked for me over time and finally a few words on where you can find the models and where can you use them so the first one I would say is for any of the biggest proprietary models you just have to go to the website of that LM provider so for example for open a that's uh chat I believe actually works now uh so [03:18:49] that's for open AI now for or you know for um for Gemini I think it's gem. google.com or AI Studio I think they have two for some reason that I don't fly understand no one does um for the open weights models like deep SE CL Etc you have to go to some kind of an inference provider of LMS so my favorite one is together together. a and I showed you that when you go to the playground of together. a then you can sort of pick lots of different models and all of these are open models of different types and you [03:19:19] can talk to them here as an example um now if you'd like to use a base model like um you know a base model then this is where I think it's not as common to find base models even on these inference providers they are all targeting assistants and chat and so I think even here I can't I couldn't see base models here so for base models I usually go to hyperbolic because they serve my llama 3.1 base and I love that model and you can just talk to it here so as far as I know this is this is a [03:19:49] good place for a base model and I wish more people hosted base models because they are useful and interesting to work with in some cases finally you can also take some of the models that are smaller and you can run them locally and so for example deep seek the biggest model you're not going to be able to run locally on your MacBook but there are smaller versions of the deep seek model that are what's called distilled and then also you can run these models at smaller Precision so not at the native Precision of for example fp8 on deep seek or you know bf16 llama but much [03:20:20] much lower than that um and don't worry if you don't fully understand those details but you can run smaller versions that have been distilled and then at even lower precision and then you can fit them on your uh computer and so you can actually run pretty okay models on your laptop and my favorite I think place I go to usually is LM studio uh which is basically an app you can get and I think it kind of actually looks really ugly and it's I don't like that it shows you all these models that are basically not that useful like everyone just wants to run deep seek so I don't know why they give you these 500 [03:20:51] different types of models they're really complicated to search for and you have to choose different distillations and different uh precisions and it's all really confusing but once you actually understand how it works and that's a whole separate video then you can actually load up a model like here I loaded up a llama 3 uh2 instruct 1 billion and um you can just talk to it so I ask for Pelican jokes and I can ask for another one and it gives me another one Etc all of this that happens here is locally on your computer so we're not actually going to anywhere anyone else [03:21:22] this is running on the GPU on the MacBook Pro so that's very nice and you can then eject the model when you're done and that frees up the ram so LM studio is probably like my favorite one even though I don't I think it's got a lot of uiux issues and it's really geared towards uh professionals almost uh but if you watch some videos on YouTube I think you can figure out how to how to use this interface uh so those are a few words on where to find them so let me now loop back around to where we started the question was when we go to chashi pta.com and we enter some kind of a [03:21:53] query and we hit go what exactly is happening here what are we seeing what are we talking to how does this work and I hope that this video gave you some appreciation for some of the under the hood details of how these models are trained and what this is that is coming back so in particular we now know that your query is taken and is first chopped up into tokens so we go to to tick tokenizer and here where is the place in the in the um sort of format that is for [03:22:24] the user query we basically put in our query right there so our query goes into what we discussed here is the conversation protocol format which is this way that we maintain conversation objects so this gets inserted there and then this whole thing ends up being just a token sequence a onedimensional token sequence under the hood so Chachi PT saw this token sequence and then when we hit go it basically continues appending tokens into this list it continues the sequence it acts like a token [03:22:55] autocomplete so in particular it gave us this response so we can basically just put it here and we see the tokens that it continued uh these are the tokens that it continued with roughly now the question becomes okay why are these the tokens that the model responded with what are these tokens where are they coming from uh what are we talking to and how do we program this system and so that's where we shifted gears and we talked about the under thehood pieces of it so the first stage of this process and there are [03:23:25] three stages is the pre-training stage which fundamentally has to do with just knowledge acquisition from the internet into the parameters of this neural network and so the neural net internalizes a lot of Knowledge from the internet but where the personality really comes in is in the process of supervised fine-tuning here and so what what happens here is that basically the a company like openai will curate a large data set of conversations like say 1 million conversation across very diverse topics and there will be [03:23:55] conversations between a human and an assistant and even though there's a lot of synthetic data generation used throughout this entire process and a lot of llm help and so on fundamentally this is a human data curation task with lots of humans involved and in particular these humans are data labelers hired by open AI who are given labeling instructions that they learn and they task is to create ideal assistant responses for any arbitrary prompts so they are teaching the neural network by example how to respond to [03:24:27] prompts so what is the way to think about what came back here like what is this well I think the right way to think about it is that this is the neural network simulation of a data labeler at openai so it's as if I gave this query to a data Li open and this data labeler first reads all of the labeling instructions from open Ai and then spends 2 hours writing up the ideal assistant response to this query and uh [03:24:57] giving it to me now we're not actually doing that right because we didn't wait two hours so what we're getting here is a neural network simulation of that process and we have to keep in mind that these neural networks don't function like human brains do they are different what's easy or hard for them is different from what's easy or hard for humans and so we really are just getting a simulation so here I shown you this is a token stream and this is fundamentally the neural network with a bunch of activations and neurons in between this is a fixed mathematical expression that [03:25:28] mixes inputs from tokens with parameters of the model and they get mixed up and get you the next token in a sequence but this is a finite amount of compute that happens for every single token and so this is some kind of a lossy simulation of a human that is kind of like restricted in this way and so whatever the humans write the language model is kind of imitating on this token level with only this this specific computation for every [03:25:58] single token and sequence we also saw that as a result of this and the cognitive differences the models will suffer in a variety of ways and uh you have to be very careful with their use so for example we saw that they will suffer from hallucinations and they also we have the sense of a Swiss model of the LM capabilities where basically there's like holes in the cheese sometimes the models will just arbitrarily like do something dumb uh so even though they're doing lots of magical stuff sometimes they just can't [03:26:28] so maybe you're not giving them enough tokens to think and maybe they're going to just make stuff up because they're mental arithmetic breaks uh maybe they are suddenly unable to count number of letters um or maybe they're unable to tell you that 911 9.11 is smaller than 9.9 and it looks kind of dumb and so so it's a Swiss cheese capability and we have to be careful with that and we saw the reasons for that but fundamentally this is how we think of what came back it's again a simulation of this neural network of a [03:27:00] human data labeler following the labeling instructions at open a so that's what we're getting back now I do think that the uh things change a little bit when you actually go and reach for one of the thinking models like o03 mini and the reason for that is that GPT 40 basically doesn't do reinforcement learning it does do rhf but I've told you that rhf is not RL there's no there's no uh time for magic in there [03:27:31] it's just a little bit of a fine-tuning is the way to look at it but these thinking models they do use RL so they go through this third state stage of perfecting their thinking process and discovering new thinking strategies and uh solutions to problem solving that look a little bit like your internal monologue in your head and they practice that on a large collection of practice problems that companies like openi create and curate and um then make available to the LMS so when I come here and I talked to [03:28:02] a thinking model and I put in this question what we're seeing here is not anymore just the straightforward simulation of a human data labeler like this is actually kind of new unique and interesting um and of course open is not showing us the under thehood thinking and the chains of thought that are underlying the reasoning here but we know that such a thing exists and this is a summary of it and what we're getting here is actually not just an imitation of a human data labeler it's actually something that is kind of new and interesting and exciting in the [03:28:32] sense that it is a function of thinking that was emergent in a simulation it's not just imitating human data labeler it comes from this reinforcement learning process and so here we're of course not giving it a chance to shine because this is not a mathematical or a reasoning problem this is just some kind of a sort of creative writing problem roughly speaking and I think it's um it's a a question an open question as to whether the thinking strategies that are developed inside verifiable domains [03:29:02] transfer and are generalizable to other domains that are unverifiable such as create writing the extent to which that transfer happens is unknown in the field I would say so we're not sure if we are able to do RL on everything that is very verifiable and see the benefits of that on things that are unverifiable like this prompt so that's an open question the other thing that's interesting is that this reinforcement learning here is still like way too new primordial and nent so we're just seeing like the beginnings of the hints of greatness uh [03:29:34] in the reasoning problems we're seeing something that is in principle capable of something like the equivalent of move 37 but not in the game of Go but in open domain thinking and problem solving in principle this Paradigm is capable of doing something really cool new and exciting something even that no human has thought of before in principle these models are capable of analogies no human has had so I think it's incredibly exciting that these models exist but again it's very early and these are primordial models for now um and they [03:30:05] will mostly shine in domains that are verifiable like math en code Etc so very interesting to play with and think about and use and then that's roughly it um um I would say those are the broad Strokes of what's available right now I will say that overall it is an extremely exciting time to be in the field personally I use these models all the time daily uh tens or hundreds of times because they dramatically accelerate my work I think a lot of people see the same thing I think we're going to see a huge amount of wealth creation as a result of these models be [03:30:37] aware of some of their shortcomings even with RL models they're going to suffer from some of these use it as a tool in a toolbox don't trust it fully because they will randomly do dumb things they will randomly hallucinate they will randomly skip over some mental arithmetic and not get it right um they randomly can't count or something like that so use them as tools in the toolbox check their work and own the product of your work but use them for inspiration for first draft uh ask them questions but always check and verify and you will [03:31:08] be very successful in your work if you do so uh so I hope this video was useful and interesting to you I hope you had it fun and uh it's already like very long so I apologize for that but I hope it was useful and yeah I will see you later