LLMs and tokens: how a machine writes text
ChatGPT, Claude and Gemini are large language models (LLMs). Their single operation is predicting the next token, a chunk of text. How whole articles and code emerge from this simple mechanism, what tokens and context windows are — and why it all matters practically.
Time to open the hood on the main characters of the era — large language models.
LLM: what each letter means
Large Language Model. "Language" — it learned from text: books, articles, websites, code (literally a large slice of the internet). "Large" — hundreds of billions of the weights from the last lesson. ChatGPT, Claude, Gemini, DeepSeek are all LLMs from different companies, built on the same principle (that same 2017 transformer).
The one trick: guess the next chunk
Everything an LLM does is predict the next token. You write: "The capital of France is ". The model runs through its vocabulary and scores the possible continuations: "Paris" — 99%, "Lyon" — 0.3%, "banana" — 0.0001%. It picks a likely one, adds it to the text — and predicts the next chunk. Over and over, word by word, and a whole answer is born.
Hold on. If the model is just "guessing the next word" — how does it write coherent essays and working code?
The answer is elegant: to predict the next word well in any text humanity has written, the model had to learn grammar, facts, chains of reasoning, styles and the structure of code. Predicting a word turned out to be a task with "understanding" of language hidden inside it. That's the great discovery of the LLM era — and the great source of arguments about whether a model really "understands" anything.
Tokens: the currency of the LLM world
The chunks a model works in are called tokens. A token isn't always a word: a short word is one token, a long one gets cut into pieces, a punctuation mark is a token of its own. On average 1 token ≈ 3–4 characters — but that rule only holds for English. Worth knowing: in other languages, especially ones that don't use the Latin alphabet, tokens are "pricier" — often just 1–2 characters each.
So the same text, meaning for meaning, burns noticeably more tokens outside English and hits limits and the context window sooner. Practical takeaway: if you're working in another language and counting cost or volume, leave yourself headroom.
Tokens aren't an abstraction — they show up in practice:
- The context window — how many tokens the model holds in its head at once: your question, its answers, the files you uploaded. Whatever doesn't fit, the model "forgets". That's why long conversations lose the beginning.
- Price — when you plug a model into your own software (that's called an API), you pay per token. Building a bot or an automation means counting tokens.
- Plan limits — the "messages per hour" caps on free plans grow out of token economics too.
How "large" is large?
Get a feel for the scale. The training set of a flagship LLM runs to trillions of tokens: a person reading a book a day would need hundreds of thousands of years to get through that much. Which is why the model "knows" physics, and cooking recipes, and the syntax of twenty programming languages: it statistically chewed through the written experience of all humanity. And why the worst of the internet is in there too — companies pour enormous effort into filtering the data and polishing the behaviour (that reinforcement learning from human ratings from the last lesson).
Generation, not search
A crucial consequence: an LLM doesn't look the answer up in a database — it generates it by predicting a likely continuation. Which is why it can write a sonnet about your cat, who never existed anywhere on the internet (creativity!). And equally why it can confidently write something false, if the falsehood "sounds likely" (that's what the whole next lesson is about).
Under the hood (optional): two lovely facts
What follows is an optional deep-dive. It won't change anything in practice: skip to "Do this now" if you like. But the facts are lovely — two new words, two ideas.
Emergence. The most mysterious property of big models: as they grow, abilities appear that nobody trained into them. The model was trained to predict text — and suddenly it can translate, solve logic puzzles, write code, explain jokes. These "out of nowhere" abilities are called emergent. Where the effect stops, scientists still argue — and that's the big open question of the next few years: all three ingredients (data, power, architecture) keep growing.
Temperature. Ask a model the same question twice and the answers will differ. That's not a fault: when choosing the next token, the model doesn't always take the most likely one — it's allowed to "take a small risk" (the setting is literally called temperature). A pinch of randomness keeps text alive instead of robotically identical. Practical takeaway: if you don't like an answer, sometimes just regenerating is enough. And "The capital of France is Paris" stays rock solid: a 99% probability outweighs any randomness.
Do this now
Run this prompt right here, then press Run a second time without changing a word:
Continue this sentence five different ways: The morning started with…
You'll watch the probabilistic nature of generation with your own eyes: one model, one identical request — and different likely continuations.
Short questions on the lesson — with an explanation for every answer.
Skip this lesson →