An LLM is a next-token machine
Strip away the mystique and a language model does exactly one thing: guess the next token, over and over. Everything else — chatbots, code, essays — is that one trick repeated.
Ask a beginner “What's an LLM?” and the most probable answer is: “An AI that talks like a human.”
It's a reasonable answer, and almost entirely wrong.
Before we can understand a language model, we have to remove that misconception: an LLM does not think, understand, or reason the way humans do.
At its core, an LLM is a next-token prediction machine.
That sounds surprisingly simple, doesn't it?
Yet this one idea is powerful enough to create chatbots, write code, answer questions, summarize books, and hold conversations that feel remarkably human.
The interesting part is not the simplicity of the objective — it's what has to exist inside the system for that objective to work at all.
By the end of this article, you should be able to build a causal mental model of what actually happens when a TypeScript program sends text to an LLM API.
All the way down to the probability distribution over the next token, and back up to the text you see on your screen.
The claim
Let me start with a claim that sounds almost insultingly simple:
An LLM predicts the next token.
That's it. You give it some text. It looks at that text. Then it predicts what should come next.
Formally, an LLM is a parameterized function that assigns probabilities to sequences of tokens — a network with parameters θ that looks at a sequence x₁, x₂, …, x_T (where each xᵢ is a token and T is the sequence length) and outputs what should come next.
Input: "The capital of France is"
Output: "Paris"
Input: "I went to the store and bought some"
Output: "milk"
Input: "I went to the store and bought some milk"
Output: "yesterday" ← then ask again. And again.You keep doing this, one token at a time.
This is the basic mechanism underneath the chat interface you're using right now.
And if you're thinking “Wait. That's all?” — good.
A useful technical definition: an LLM is a parameterized neural network that estimates a probability distribution over the next token, given the tokens that came before it.
That sounds considerably less exciting — so let's represent it mathematically.
The equation
For an autoregressive language model, we can factor the probability of an entire sequence using the chain rule of probability:
P(x₁, x₂, …, x_T) = ∏ₜ P(xₜ | x₁, …, xₜ₋₁)Now you might be thinking, “What the heck is this?” Don't worry — we're going to break it down step by step, and I promise it'll start making sense.
What does this equation actually say?
Take the sentence “The cat sat on the mat”. Does a model treat this as one indivisible sentence?
No. Instead, it models something like this:
P("The")
P("cat" | "The")
P("sat" | "The cat")
P("on" | "The cat sat")
P("the" | "The cat sat on")
P("mat" | "The cat sat on the")Step one: what does P mean?
P is simply probability — the same probability you met when flipping a coin.
P(“The”) asks: what is the probability that the model's sequence starts with the token “The”? The model might assign P(“The”) = 0.05, meaning a 5% chance that “The” is the first token.
Step two: that vertical bar |. It reads as “given that”.
So P(“cat” | “The”) means: what is the probability of “cat”, given that we already have “The”?
Imagine I give you the text “The” and ask what comes next. The model considers many possibilities: cat → 2%, dog → 1%, house → 0.5%, car → 0.2% … and so on across its entire vocabulary.
Step three: the context grows.
P(“sat” | “The cat”) asks: how likely is “sat” after “The cat”? Maybe the model assigns it 0.15 — a 15% probability.
Notice something important: the model is never predicting the entire sentence. It only ever asks, “Given everything I have seen so far, what should come next?”
Now forget the mathematics and imagine we are the LLM.
We start with nothing and predict “The”. Now we have “The”, so we predict “The cat”. Then “The cat sat”, “The cat sat on”, “The cat sat on the” — and finally “The cat sat on the mat”.
The model keeps doing the same thing again and again. Each term in that equation answers one simple question: given what I have seen so far, how likely is this next token?
The interesting part is that an actual LLM doesn't choose from a handful of words. It produces a probability distribution over a huge vocabulary — and that's where things get really interesting.
But LLMs don't actually predict “words”
One correction before we go further.
Until now you've heard: “an LLM predicts the next word.” It's a useful way to grasp the idea, but technically it isn't quite correct.
LLMs don't operate on words. They operate on tokens — and this distinction matters.
What exactly is a token?
A token is a small piece of text the model can process.
Depending on the tokenizer, a token could be an entire word, part of a word, punctuation, whitespace fused to a word, a number, a symbol, or a fragment of code.
For example:
"Hello world!"
→ ["Hello", " world", "!"]Notice the second token isn't just “world” — it can include the space before the word.
The tokenizer decides how text is broken into tokens, and different models use different tokenizers, so the exact split isn't universal.
Why not just use words?
Because language isn't that convenient.
Consider “unbelievable”: a tokenizer might represent it as [“un”, “believ”, “able”] — or as a single token — depending on its vocabulary.
Now consider code:
const user = await getUser(id);
→ ["const", " user", " = ", "await", " get", "User", "(", "id", ");"]There's no useful concept of “words” that captures everything a model needs here.
Tokens give the model a general representation of text — whether that text is English, TypeScript, JSON, mathematics, or something else.
From text to tokens
So we update our mental model.
Instead of Text → Words, think Text → Tokens.
“The cat sat on the mat.” might become [“The”, “ cat”, “ sat”, “ on”, “ the”, “ mat”, “.”]. The model doesn't receive the sentence as humans see it — it receives a sequence of tokens.
Suppose our text is converted into T tokens.
Each token maps to an integer ID from the model's vocabulary: xᵢ ∈ {0, 1, 2, …, V−1}, where V is the vocabulary size. For a toy model with a 50,000-token vocabulary, every token has a unique ID from 0 to 49,999.
So instead of sending “The cat sat” into the network, the tokenizer might produce something conceptually like [791, 3124, 8452].
Those numbers themselves contain no meaning.
Token ID 791 isn't inherently more meaningful than 3124 — they're identifiers saying “this position holds token number 791 from my vocabulary.”
And here's the important part
“Wait — if the model receives numbers, how can it possibly understand language?”
Excellent question.
The neural network doesn't operate directly on the integer IDs. The IDs are used to retrieve embedding vectors — lists of numbers the model can actually do mathematics with:
"cat"
↓
token ID: 3124
↓
embedding lookup
↓
[0.21, -0.73, 0.44, …, 0.18]That vector lives in a high-dimensional continuous space, and this is where the neural network starts doing its real work.
The full pipeline so far
Text → Tokens → Token IDs → Vectors
…and eventually:
Text → Tokens → Embeddings → Transformer → Logits → Probabilities → Next tokenOne more detail: the tokenizer creates a finite vocabulary — {Token 1, Token 2, …, Token V} — and the model's job during generation is to produce a probability distribution over that vocabulary.
Given tokens 1 through T, the model outputs the probability of each possible next token ID.
So when we casually say “the LLM predicts the next word”, what we really mean is: the LLM produces a probability distribution over possible next tokens.
That one correction changes everything — because now the real question becomes: how does a neural network take a sequence of token IDs and turn it into a probability distribution over the next token?
That's where the Transformer enters the story — and that's exactly where the next article picks up.
Tokens, token IDs, embeddings, attention, causal attention, Transformer layers, hidden states, and the mathematics behind them.
For now, keep this question in your head: how does a sequence of numbers become an intelligent-looking prediction? See you in the next one.