A language model does exactly one thing, over and over: given the text so far, it outputs a probability for every possible next token — a token being a small chunk of text, roughly a word or word-piece. Those probabilities sum to 1. The model picks one, appends it, and asks the same question again. A whole paragraph is just that single prediction *run thousands of times*.
Why next-token prediction is enough
Any sentence's probability can be split into a chain of next-token guesses — this is the autoregressive factorization: P(sentence) = P(t1) · P(t2 | t1) · P(t3 | t1,t2) · …. So a model that's merely good at *one* conditional — the next token given everything before it — can score, and generate, text of any length.
1Feed in the tokens so far (the context).
2The network outputs a raw score (logit) for every token in the vocabulary.
3Softmax turns those logits into a probability distribution that sums to 1.
4Choose a token (greedy, or sampled — see *Sampling*), append it to the context.
5Repeat. Each generated token becomes input for the next step.
Training = maximize the real next token
You don't hand-label anything. Take ordinary text, hide the next token, and tune the model to put high probability on the word that actually came next. This is maximum-likelihood training via cross-entropy loss, and the text supervises itself — which is why the internet can be training data.
# one prediction step (pseudocode)
logits = model(context) # one score per vocab token
probs = softmax(logits) # sums to 1
loss = -log(probs[true_next]) # cross-entropy: punish low prob on the real token
Perplexity — how good is it?
Perplexity measures how *surprised* the model is by real text: it is exp(average cross-entropy loss). A perplexity of 10 means the model is, on average, as unsure as if it were choosing uniformly among 10 tokens. Lower is better — it predicted the actual next words more confidently.
A language model is not a fact database
It learns the *statistics* of text, not a verified store of truth. Fluent and confident does not mean correct — the same loop that writes a perfect sentence will happily continue a plausible-sounding falsehood.
OperationTimeSpace
Score a sequence of length n · one distribution per positionO(n) stepsO(vocab)
Training objective · equiv. to minimizing perplexityminimize cross-entropy—
Check yourself
What does a lower perplexity indicate about a language model?