What a language model actually is
Most explanations describe a language model as something that "understands" text, or a database of facts it "remembers." Both are wrong in ways that will confuse you later, when the model confidently states something false or forgets what you told it two messages ago. Neither behavior makes sense if you think of it as a knowledge store. Both make complete sense once you know what it actually is.
A language model is a function. Give it a sequence of tokens, it gives you back a probability distribution over what token comes next. That is the entire definition. Everything else, chat interfaces, code generation, reasoning-looking output, is built on top of calling that function over and over.
A language model is a next-word guesser, extraordinarily well trained. Not a search engine. Not a fact database. A function from "text so far" to "probability of what comes next."
Making that concrete
Take the sentence "The cat sat on the ___". A trained model does not know, in any factual sense, what the cat sat on. It has seen enormous amounts of text where sentences like this one are completed with words like mat, floor, or couch, far more often than with words like moon or equation. So it assigns mat a high probability, floor a lower but still meaningful one, and moon something close to zero. That ranked list of probabilities is the model's entire output for this step.
Try it below. Pick a prompt and watch the distribution. Notice that "2 + 2 =" gets a sharply confident answer, not because the model computed the sum, but because virtually every training example that looks like that sentence was completed the same way. Rule: confidence in a language model's output reflects how consistently the training data completed a similar pattern, not whether the model verified anything.
The distribution, the sample, the loop
A single forward pass through the model produces one probability distribution over the entire vocabulary, tens of thousands of possible next tokens, each with a probability. Generating an entire paragraph is that same step, repeated. Pick one token from the distribution, append it to the input, run the model again on the new, slightly longer sequence. This is called autoregressive generation: each output becomes part of the input for the next step.
These probabilities are hand-authored to illustrate the shape of a real distribution, not pulled from a running model. Adjust the temperature slider and watch the bars sharpen toward one token or spread out across many, that reshaping is a real, verifiable calculation (softmax with temperature scaling), covered in full in the Sampling and Generation article later in this series.
Why "pick one" and not "pick the best"
You might expect the model to always output the single highest-probability token. Some systems do exactly that (it's called greedy decoding), but it tends to produce dull, repetitive text. Most production systems sample: they roll a weighted die over the distribution, so a token with 20% probability gets chosen roughly one time in five. Same underlying model, different generations, every time you run it. That's why asking the same question twice can give you two different answers with plausible-sounding confidence in both.
The generation loop, stripped to its essence
1tokens = tokenize(prompt)23for _ in range(max_new_tokens):4 distribution = model(tokens) # probabilities over the whole vocabulary5 next_token = sample(distribution) # weighted random pick, not always the top one6 tokens.append(next_token)7 if next_token == END_OF_TEXT:8 break910return detokenize(tokens)
Every capability that feels intelligent, writing a function, explaining a concept, carrying on a conversation, is this loop running thousands of times, one token guessed after another, each guess conditioned on everything generated so far.
What this explains, and what it doesn't
Once "next-token prediction" is the model you actually hold in your head, a lot of confusing LLM behavior stops being confusing. It becomes predictable, because you can ask a sharper question: "what would a plausible continuation of this text look like," instead of "does the model know this."
There is no lookup step at inference time. Every fact-shaped output is a token sequence the model judged probable, based on patterns in training data. It often happens to be correct, because correct completions were common in that data. It is never verified against a source while generating.
Hallucination and correct output come from the exact same mechanism: predicting a plausible next token. The model has no separate 'I don't know' pathway unless it was specifically trained to produce one. A fluent, confident, wrong sentence and a fluent, confident, right sentence look identical from the inside.
Nothing persists between calls to the model itself. Each time you send a message, the entire visible conversation is re-fed in as input tokens. 'Memory' in a chat product is the application re-sending prior messages, not the model recalling anything.
What looks like reasoning is the model predicting tokens that resemble reasoning, because its training data contained huge amounts of worked-through reasoning. Writing out intermediate steps measurably improves the final answer's accuracy, that's real and useful, but it's still next-token prediction at every step, not a separate logic engine running underneath.
Then why does this feel like more than autocomplete?
Fair question. Your phone's keyboard also predicts the next word, and nobody confuses it for something intelligent. The difference is scale and depth: a phone keyboard looks at the last one or two words and a tiny model. A large language model looks at thousands of tokens of context, was trained on a meaningful fraction of publicly available text, and runs that prediction through a network with billions of tuned parameters. The objective stayed exactly the same, predict the next token, but at sufficient scale, getting that objective right on enough diverse text requires the model to internalize grammar, facts, style, and multi-step patterns well enough to reproduce them. Nobody designed those capabilities in directly. They fell out of the objective once the scale was large enough.
In practice: when an LLM gets something wrong, the useful question is not "why is it broken," it's "what completion pattern in its training data would produce this." That question actually has an answer, and it's the mental model this entire series is built on.
Where this series goes from here
Fifteen articles, each one building directly on the last. No article assumes anything beyond what came before it. By the end, you will have built a working, if small, GPT-style model yourself, and understood every line of it.
What Is a Language Model
You are hereNext-token prediction, the objective everything else is built on.
Tokenization
Next upHow text becomes the numbers a model can actually operate on.
Embeddings
Turning token IDs into points in space that capture meaning.
Neural Network Foundations
Neurons, weights, and matrix multiplication, the machinery underneath.
Attention
The mechanism that lets a model decide what to focus on.
The Transformer Block
Attention, feedforward, and residuals, assembled into one architecture.
Positional Encoding
How word order gets injected back in.
Loss and Backpropagation
How a model learns from being wrong.
Pretraining at Scale
What a real training run looks like.
From Base Model to Assistant
Instruction tuning and RLHF, why raw models don't chat.
Sampling and Generation
Temperature, top-k, top-p, why output varies.
Context Windows and the KV Cache
Why longer conversations cost more.
Evaluating LLMs
Perplexity, benchmarks, and why eval is hard.
Scaling Laws
Why bigger models predictably work better.
Build a Tiny LLM From Scratch
Every prior article, tied into working code.