The network of dials
Forget everything you know about how a computer normally works — rules, if-statements, lookup tables. An LLM works nothing like that. It is, at its core, a gigantic collection of numbers.
Imagine a wall covered in millions of physical dials. Each dial can be turned to any value — positive or negative, big or small. Those dials are called weights (or parameters). A large model like GPT-4 has around 1.8 trillion of them.
These weights are organized into layers. Each layer takes in some numbers, multiplies them by its weights, adds them up, and passes the result to the next layer. That's it. That simple operation, repeated thousands of times across hundreds of layers, is what produces language.
Making a prediction
When you type a prompt, the model's job is to predict: "what token should come next?" A token is roughly a word (or part of a word). The model doesn't pick one deterministically — it produces a probability distribution over the entire vocabulary.
Imagine asking the model to complete: "The sky is ___". The model assigns a probability to every word in its vocabulary — maybe blue gets 42%, falling gets 8%, beautiful gets 6%, and millions of other words share the rest. Then one is sampled.
Measuring the mistake
Before a model can learn, it needs to be able to measure how wrong it was. That measurement is called the loss (or cost). Think of it as a single number that tells you: "how bad was this prediction?"
If the correct next word was "blue" and the model only gave it 2% probability, the loss is high. If the model gave it 85% probability, the loss is low. The specific formula used is called cross-entropy loss, but all you need to know is: higher loss = worse prediction.
During training, the loss is computed for millions of predictions. The goal of training is to minimize this loss — to turn those dials until the model assigns high probability to correct tokens.
Backpropagation — the magic dial-turner
Here is the key question: once you know the loss, how do you know which dials to turn, and in which direction?
The answer is backpropagation — and it's one of the most elegant ideas in all of computer science. Here's the narrative:
Step 1 — The forward pass. The input flows forward through all the layers. Every single multiplication, every addition is recorded. The model builds a kind of "receipt" of every computation it did.
Step 2 — The loss is computed. At the end of the forward pass, we compare the prediction to the correct answer and get a loss number.
Step 3 — The backward pass. Now we go backwards through that receipt, using calculus (the chain rule). For each weight, we compute a gradient — a number that says: "if you increase this weight by a tiny amount, does the loss go up or down, and by how much?"
Step 4 — Update the weights. Each weight is nudged in the direction that reduces the loss, by a tiny amount called the learning rate. That's one step of training. Now repeat this billions of times.
Pre-training — reading the internet
Now you know the mechanics. Here's how they're applied at scale.
During pre-training, the model is given a simple task: predict the next token. That's it. The training data is an enormous corpus of text — books, articles, code, websites. Trillions of tokens.
For each sentence in that corpus, the model is shown the beginning and asked to predict what comes next. It predicts. The actual next word is revealed. Loss is computed. Backprop runs. Weights are updated. Then the next sentence. Then the next. For months, on thousands of chips running in parallel.
At the end of pre-training you have a base model: a model that is extraordinary at predicting and generating text, but has no concept of being helpful, honest, or having a conversation. It would complete "How do I make a bomb?" as naturally as "The sunset was beautiful." It's a text predictor, not an assistant.
RLHF — teaching it to be good
The base model is powerful but wild. To turn it into a helpful assistant, we use Reinforcement Learning from Human Feedback (RLHF). Here's how it works, step by step.
Step 1 — Supervised Fine-Tuning. First, humans write examples of ideal conversations: a question and a perfect answer. The model is trained on these examples using standard backprop. It begins to learn the format and tone of being helpful.
Step 2 — Train a Reward Model. Now humans are shown pairs of answers and asked: which one is better? These preferences train a separate small model — the reward model — whose sole job is to score an answer from 0 to 10 based on how good it is. Think of it as a judge that has been calibrated on thousands of human opinions.
Step 3 — Reinforcement Learning. Now the main model generates an answer. The reward model scores it. And here is where your original question lives:
There's one more piece: a KL penalty. During RL, the model could learn to "cheat" — to generate nonsense that happens to fool the reward model. The KL penalty punishes the model if it drifts too far from the original base model, keeping it grounded.