0:00Intro: MOFUSA Tech Academy (welcome to Season 3)
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery. And welcome to Season Three: generative AI.
0:09Hook: every chatbot reply, one token at a time
Every response a modern chat assistant writes is produced the same way: one token at a time. At each step, the model looks at everything so far, calculates a probability for every possible next token, picks one, and repeats. And the way it learned to do that is astonishingly simple to describe. It was shown an enormous amount of text and, over and over, asked one question: what comes next? Not trained on answers written by teachers. Just text, and that one question, repeated trillions of times. Today, we look at how a large language model is trained: the objective, the data, the scale, and why the result, on its own, isn't yet the helpful assistant you've used.
Season Three, Module Eleven: large language models. First stop: how they're trained.
1:06The task: predict the next token
The training task is called language modelling: given the text so far, predict the next token. Take a sentence: "Your parcel will arrive tomorrow." Given "Your", predict "parcel". Given "Your parcel", predict "will". Given "Your parcel will", predict "arrive". And so on. Notice something wonderful. We never need anyone to label anything. The text is its own answer key: the targets are simply the same words, shifted along by one. This is called self-supervised learning, and it's why language models can learn from such vast amounts of text.
Any sentence ever written is a ready-made set of training examples. And thanks to the causal mask from last season, a decoder-only transformer makes all of these predictions in parallel. Every position predicts its own next token in a single forward pass.
2:03The objective: cross-entropy and perplexity
How do we score the model? With the cross-entropy loss we've used since Season One. At each position, look at the probability the model gave to the token that really came next, and take minus its log. Here are real numbers for our sentence. The model gave the true next token these probabilities: thirty percent, twenty percent, sixty-five, seventy, and fifty-four percent. The losses are one point two, one point six, zero point four three, zero point three six and zero point six one. Words that were easy to predict, like "arrive" after "will", cost little.
Words that could have been many things, like the first word, cost more. The average is zero point eight four. Raise e to that power and you get the perplexity: about two point three. You can read that as "on average, the model was as uncertain as if it were choosing between two or three equally likely tokens." Lower is better. Training means adjusting billions of weights, with backpropagation and an optimiser like AdamW, to bring this average loss down across trillions of tokens.
3:18Why next-token prediction teaches so much
Why does such a simple task produce such capable models? Because predicting text well, across everything people write, requires picking up a lot along the way. To complete "The capital of France is", the model benefits from absorbing facts. To complete "She dropped the glass, and it", it benefits from patterns about how the world works. To continue a piece of code, it needs programming patterns. To finish a customer-service reply, it needs tone and conventions. But be careful with what this means. The model learns whatever patterns help it predict text, and text contains mistakes, myths and contradictions as well as facts.
Predicting well doesn't guarantee being right. We'll come back to that in episode five of this module.
4:08Training data: the refinery
Where does the text come from? Typically a mix: large crawls of the public web, books, code, scientific papers, reference material and discussion forums, plus licensed or carefully curated datasets. Raw web text is messy, so it goes through a refinery. Identify the language. Remove duplicates, because the same page copied a thousand times would be over-learned. Filter out spam, boilerplate and gibberish. Filter harmful content. Strip personal information. And remove the exact questions used in public tests, so the model's scores later aren't inflated by memorised answers.
Then comes the recipe: how much of each source to include. The mixture shapes the model's skills. More code tends to make a model better at programming. More high-quality text makes it better at writing. And because the public web is dominated by English and a few other major languages, many languages are under-represented, which is why models often work less well for their speakers. Keep in mind that details like these change fast. They were correct when this video was published, so treat them as a snapshot, not a permanent fact.
5:27Training at scale
At the scale of modern models, this simple loop becomes an engineering feat. Each training step may process millions of tokens. The model is too big for one graphics card, so it's split across many: different cards handle different parts of the batch, different slices of each matrix, or different layers. Numbers are stored in compact sixteen-bit formats to save memory and time. Progress is saved regularly, so that if something goes wrong, like a sudden spike in the loss, training can resume from a recent checkpoint.
The optimiser is the AdamW we met last season, with warm-up and a decaying learning rate. Training a large model can run for weeks or months on thousands of chips, which is why pre-training is so expensive, and why most organisations build on models that others have pre-trained.
6:21Domain-specific models and why size matters
Not every model is a generalist. Some are trained mostly on one domain, like code, medicine or law, and can perform very well in that area while being smaller. For a company like Brightcart, pre-training a large model from scratch would make little sense. It's far cheaper to start from an existing model and adapt it, with the prompting, retrieval and fine-tuning techniques we'll learn in Seasons Four and Five. And the next question is one researchers have studied very carefully: how big should a model be, and how much text should it read?
That's scaling laws, next episode.
7:01A base model is not an assistant
Here's something that surprises many people. A freshly pre-trained model, called a base model, is not an assistant. Ask it, "How do I return a cracked mug?", and it might continue with "How do I return a broken kettle? How do I track my order?", because on the web, that question often appears in a list of similar questions. It's continuing a document, not answering you. A base model has absorbed a vast amount from its text, but it doesn't yet know that it's supposed to follow instructions, be helpful, or decline harmful requests.
Turning a base model into an assistant takes another stage, called post-training, and that's episode three of this module.
7:47Try it yourself: one surprising token
Here's a four-token sentence. The model gave the true next tokens probabilities of zero point nine, a half, zero point zero five, and zero point six. Which token contributes most to the loss? Pause. The surprising one. Minus the log of zero point zero five is about three, while the others are small: zero point one, zero point seven and zero point five. That single token is seventy percent of the total loss. The average is about one point zero eight, a perplexity of about two point nine. So training pushes hardest exactly where the model was most surprised, which is where it has the most to learn.
8:37Free labels: self-supervised learning
Why is this called self-supervised? Because the labels come free. A thousand-token help article gives nine hundred and ninety-nine training examples, each position predicting the next, and nobody had to label anything. Compare that with the classifiers in Season One, where every example needed a human label. To use the hardware efficiently, many documents are packed into one long training row, separated by a special end-of-text token, so the model also learns where one document stops and the next begins.
9:14How big is a trillion tokens?
How much text is a trillion tokens? Take one point four trillion, a scale we'll meet next episode. That's roughly a trillion words. If you read two hundred and fifty words a minute, for eight hours a day, every single day, it would take you about twenty-four thousand years to read it all once. A model trained on it sees more text than any human could read in hundreds of lifetimes, and at the time of recording, even that is not the largest scale in use.
9:47Duplicates and leaked tests
Two data problems deserve special attention. First, duplicates. Some text, like a standard terms-and-conditions page, appears on thousands of websites. Train on all those copies, and the model memorises them word for word, wasting effort, so pipelines detect and remove near-duplicates. Second, contamination. If test questions and their answers appear on the web, they can leak into the training data, and the model's scores look better than its real ability. It's the leakage problem from Season One, at enormous scale.
10:24What a base model does with a question
What happens if you ask a base model a question? It doesn't know it's supposed to answer. Give it "Customer: Where is my parcel?", and it might write three more customer questions, because that's a plausible continuation of the pattern. But show it two examples of questions with answers first, and it will continue the pattern by answering. A base model is a brilliant mimic of text. Turning it into a helpful assistant is the job of post-training, two episodes from now.
10:56Consent, copyright and privacy
Training data raises real questions that society is still working out. Is it fair to train on published books and articles? Legal cases and policy debates about that are ongoing in several countries. Should website owners be able to opt out? Many crawlers now respect opt-out signals. And personal information, like email addresses and phone numbers, should be filtered out. When Brightcart adapts models with its own data later in the course, we'll treat these questions as design requirements, not afterthoughts.
11:31Predict: why not just memorise?
Couldn't a model just memorise its training text and get a perfect score? Pause and think about why that wouldn't work. It would fail on anything new, like a sentence it has never seen. That's why training runs watch the loss on held-out text, just like the validation sets in Season One. And there's another reason: even a huge model has far fewer parameters than its training data has tokens, so it can't store everything word for word. It has to compress the text into patterns, and those patterns are what let it handle new sentences.
12:12Myth vs Fact
Myth: a language model searches a database of everything it read and copies out answers. Fact: there's no database inside. What it learned is stored in its weights, as compressed patterns spread across billions of numbers. It can sometimes reproduce passages it saw many times, but mostly it generates new text from those patterns, which is exactly why it can sound fluent and still be wrong.
12:38Recap
Let's recap. Large language models are pre-trained to predict the next token, a self-supervised task where the text provides its own labels. The loss is the average cross-entropy of the true next tokens, and perplexity summarises it. The training data comes from many sources, refined by deduplication, quality and safety filtering, and decontamination, and its mixture shapes the model's skills. Training runs at enormous scale. And the result is a base model that continues text, but isn't yet an assistant. One sentence to remember: read everything, predict what comes next, and the patterns of language follow.
13:22Next: scaling laws
Mission complete. We know how a language model learns to write: by predicting the next token across an enormous, carefully refined library of text. But training runs cost a fortune. Given a fixed budget, should you build a bigger model, or train a smaller one on more data? Researchers found the answer follows surprisingly regular mathematical patterns. Scaling laws, next. See you on the map.