How a Chatbot Writes an Answer, One Guess at a Time

Why does a chatbot give a different answer every time you ask? It comes down to tokens, weights, and a bit of randomness — and the story of how a machine learns to guess what comes next.

Ask a chatbot why the sky is blue, and it answers in a second, in tidy paragraphs, and will even crack a joke if you ask. It feels as though a very well-read person is behind the screen, thinking it over. There isn’t. There is a machine doing one simple thing over and over: guessing what comes next. Everything else follows from that.

A large language model is neither a database nor a search engine. It is a mathematical function with an enormous number of adjustable numbers inside it, usually called parameters or weights. Think of a mixing desk with hundreds of billions of knobs, all wired together. Text goes in, numbers come out, and that is all it does. Nothing inside is stored as a sentence you could look up.

Before the text reaches those knobs, it is chopped up. Not into words, and not into letters, but into tokens, which are chunks of text. Common words get a token of their own; rarer ones are broken into pieces, so “unbelievable” might arrive as three tokens. Punctuation gets its own token, and so do pieces of numbers. A typical vocabulary runs to a few hundred thousand tokens, and an average English word takes a little more than one token. This is not a technicality: the limits on how much a model can read at once, and the bills people pay, are measured in tokens.

The model needs a fixed menu to choose from. At every step, it takes the tokens so far and produces a score for every token on that menu: how likely is this one to come next? Not one answer, but a spread of probabilities across the whole vocabulary. Then one token is picked, added to the end, and the process runs again with the new text as input. That is how an answer gets written, one small piece at a time, each piece chosen with the whole conversation in view.

Your phone’s autocomplete is the same trick at a much smaller scale: it suggests a word because that word often follows the ones you typed. The chatbot does that with a vastly larger memory of how text tends to go, which is why it can hold a paragraph together, keep a tone, and follow an instruction like “explain it to a ten-year-old”.

Where did it learn how text tends to go? From text: a very large slice of what is publicly available on the internet, plus books, articles, code and reference material. The training task is almost embarrassingly simple. Take a stretch of text, hide the next token, ask the model to guess it, compare the guess with what was actually there, and nudge the knobs slightly in the direction that would have made the right answer a little more likely. Then do it again. Nobody labels the data, because the text is its own answer key.

The scale of that repetition is the whole story. A serious run goes through trillions of tokens, and every one requires a pass through hundreds of billions of parameters, forwards and backwards, with tiny adjustments each time. It is like doing fill-in-the-blank exercises, billions upon billions of them, and turning a few billion knobs by a hair after each mistake. Individual nudges are almost meaningless; accumulate enough of them, and the thing starts to produce sentences that read like they were written by someone who understands.

To make that possible, the work is spread across thousands of specialised chips in a data centre. These chips are built for exactly this arithmetic: enormous numbers of simple multiplications at once. But the knobs are shared, so the chips must keep exchanging notes, and at some point the wiring between them, rather than the chips themselves, becomes the slow part. They also draw a lot of power and produce a lot of heat, which is why cooling is such a large part of the bill. A run on this scale takes weeks or months, often costing tens of millions of dollars or more. If it falls over partway through, you may have to start again.

After all that, the model is still not an assistant. It is a very good autocomplete. If you type a question into a raw model, it may well respond with more questions, because in the text it learned from, a list of questions is often followed by more questions. It has no idea that it is supposed to be helpful, and no particular interest in being polite. It is simply continuing the text in the most plausible way it can.

That is what fine-tuning is for. You take the trained model and continue training it, briefly, on a much smaller set of examples: real questions paired with answers that people wrote or carefully selected. The mechanism is identical — the guessing of the next token — but now the text it imitates is the kind of text you want out of it. It picks up the shape of a useful reply: address the question, stay on topic, admit when something is unclear, stop instead of rambling.

Then comes human feedback. People are shown pairs of answers to the same question and asked which one is better. Out of thousands of those small judgements, a second, much smaller model learns to predict what people tend to prefer. The main model is tuned to score well against that predictor. This is roughly what reinforcement learning from human feedback means, and it explains much of the manner of modern chatbots: the hedged phrasing, the willingness to say “I’m not sure”, the habit of offering a short summary at the end. What it adds is behaviour, not knowledge. It makes the model more agreeable, and agreeable is not the same as correct.

Shelf: Non-fiction

You may also like

  • How AI Learned to Talk — From ELIZA's rule-based replies to transformers' attention-powered chat, discover how AI learned to generate fluent, conversation-like language.
  • Why AI Sounds So Sure — Why do AI assistants sound so sure even when they're wrong? Discover how language models create confident answers—and why you should always double-check them.
  • Teaching the Machine — Discover how AI systems learn from enormous data by making mistakes and adjusting themselves, shaping the digital brains behind assistants and tools.
  • How Machines Learn Patterns — Discover how neural networks turn simple arithmetic into machines that recognize images and language by learning patterns from data.
  • Can AI Think? — Can AI truly think or only mimic thought? Exploring how machines learn, predict, and the gap between human and artificial understanding.
  • Smarter Than Us? — Could AI one day match or surpass human intelligence in nearly all tasks? Explore the promises, limits, and challenges of artificial general intelligence.
  • When Machines Make Music — Explore how AI learns musical patterns to compose tunes and voices, blending tech and art while facing ethical and emotional challenges.
  • Could a Machine Be Awake? — Can AI systems truly be conscious or just mimic awareness? Explore how neuroscience and philosophy challenge our view of machine minds.
  • Why Time Speeds Up — Why does a childhood summer seem endless, but adult years vanish so fast? Discover how the brain's memory shapes our experience of time.
  • The Boston Molasses Flood: The 1919 Wave That Exposed a Rushed Tank — On a warm January afternoon in 1919, a leaking tank in Boston's North End let go more than two million gallons of molasses. What turned a thick syrup into a deadly wave down a crowded street?
  • Mallory and Irvine: The Summit No One Can Prove — On 8 June 1924, George Mallory and Sandy Irvine walked into the clouds on Everest's northeast ridge and were never seen alive again. Seventy-five years later a search team found Mallory's body — but…
  • Birkin and the G-Virus — William Birkin's breakthrough G-Virus transforms him from Umbrella scientist into a relentless monster hunting his daughter in a secret underground bioweapon nightmare.