The chain rule of probability
A language model assigns a probability to a sequence, and it does so by factorising that probability into a product of conditionals.
This is not an approximation. It is an identity, true of any joint distribution over any ordered variables.
The modelling choice is not the factorisation, it is deciding to learn each conditional with a neural network and to condition on everything before.
Why the left-to-right order
The identity holds for any ordering, so left to right is a choice rather than a necessity.
It is chosen because it matches generation: to produce text you need the next token given the past, which is exactly what this factorisation provides.
A model factorised in some other order would assign the same probability to a full sequence and be useless for writing one.
The objective
Maximising the likelihood of the training text is minimising this, which is the cross-entropy between the true next-token distribution and the model's.
Every token in the sequence is a training example, so a document of 2000 tokens gives 2000 supervised predictions from one unlabelled document.
That is the property that made the whole field possible: the supervision is free, because the next word is already there.
Teacher forcing, and the gap it leaves
During training the model always conditions on the real prefix, even when its own prediction for the previous token was wrong.
During generation it conditions on what it produced. One mistake enters the context and every later prediction is made from a prefix the model never saw in training.
That mismatch is called exposure bias, and it is part of why long generations drift while short ones are fine.
One training step, in order
- Take a document and tokenise it.
- Feed the whole sequence in at once, with a causal mask so no position sees its own future.
- Read off one predicted distribution per position.
- Compute cross-entropy against the actual next token at every position.
- Average and backpropagate.
Step two is why transformers train so much faster than recurrent models: all predictions are made in one parallel pass, not sequential ones.