Lesson 15: How Language Models Learn from Text
A language model is a transformer trained on one simple task: given some text, predict the next word. That task sounds narrow, but it turns out to be remarkably rich. To predict the next word well, a model must learn grammar, facts, reasoning patterns and style — because all of those shape what comes next. A model that has read a vast amount of text and learned to predict it well has, in the process, learned a great deal about the world as described in text.
Training works like this. The text is broken into tokens — pieces of words, such as "un", "believ" and "able", which handle rare words gracefully. The model reads a stretch of tokens and predicts the next one; the loss measures how far its prediction was from the actual next token; backpropagation adjusts the weights. This is repeated billions of times over huge collections of text. Nothing in the training tells the model what is true or what a sentence means — it only ever learns which words tend to follow which. The understanding, such as it is, is a by-product of prediction.
From Prediction to Conversation
A model trained only to predict the next word can complete a sentence, but it is not yet a helpful assistant. Extra stages shape it: fine-tuning on examples of instructions and good replies teaches it to follow requests, and further training with human feedback rewards answers people judge helpful and honest. These stages do not add new knowledge so much as they steer the model towards using what it learned in a useful way. It is worth knowing they exist, because they explain why the same underlying model can behave very differently in different products.
It is equally worth knowing the limits. A language model does not look things up, does not know when it is guessing, and can produce confident, fluent text that is simply wrong — a behaviour often called hallucination. Its knowledge is frozen at the time its training data was collected, and it has no way to know what has changed since. Treat its output as a draft to check, not as a fact to trust, and you will use it well.
A Note on Scale and Cost
Training a large language model needs enormous amounts of text and computing power, far beyond what a school project can run. That is why this course does not ask you to train one. What you can do — and what the capstone invites — is to use smaller models, study how they behave, and understand the principles. The ideas are the same at every scale: predict the next token, measure the loss, adjust the weights, and judge the result on data the model has not seen.
What a Language Model Does Not Know
A language model can write a convincing paragraph about a topic it has never truly learned, because fluency and knowledge are different things. It can also be confidently wrong about simple facts, arithmetic, or the contents of a document it was just given, because it has no way to check itself against the world. These failures are not rare edge cases; they are the predictable result of a system that predicts likely words rather than verifying claims. The more fluent the output, the easier it is to miss the error — which is why the habit of checking matters more, not less, as these models improve.
There is also the question of what the model was trained on. Its knowledge comes from text written by people, and that text contains errors, outdated facts, and the biases of its authors. A model trained mostly on text from one part of the world will know that part better than others, and will reproduce the assumptions in its training data as if they were facts. None of this makes language models useless — they are remarkable tools — but it means the user must supply the judgement the model lacks.
Key Terms
- Language model
- A model trained to predict the next word or token in a piece of text.
- Token
- A piece of a word used as the model's unit of text; words are split into tokens before training.
- Pretraining
- The first, largest stage of training a language model on a huge collection of text.
- Fine-tuning
- Further training on examples of instructions and good replies, to steer a model towards useful behaviour.
- Hallucination
- When a language model produces confident, fluent text that is wrong.
- Human feedback
- Judgements from people about which answers are helpful, used to steer a model's behaviour.
Discussion Questions
- If a model only ever learns 'which word comes next', how can it end up knowing facts about the world?
- Why might fine-tuning on instructions change a model's behaviour without adding new knowledge?
- A model gives a fluent, confident answer that is wrong. Who is responsible for checking it — the model, or the person who uses it?
Practice Questions
- What is the training task of a language model?
- What is a token?
- Why can a language model produce a confident answer that is wrong?
- What does fine-tuning on instructions add to a pretrained model?
- Why is a language model's knowledge frozen in time?
Show answers
- Predicting the next word — or token — given the text so far. The loss measures how far the prediction was from the actual next token.
- A piece of a word used as the model's unit of text. Splitting words into tokens lets the model handle rare and unfamiliar words.
- Because it predicts likely words, it does not look facts up and does not know when it is guessing. Fluency is not the same as truth.
- It teaches the model to follow requests and give helpful replies, steering how it uses what it already learned. It does not mainly add new knowledge.
- Because it only knows what was in its training data, collected up to a certain point. It has no way to know what has changed since.