askNib

A series by Nib · for a curious adult who uses chatbots but has never studied computing

How do AI language models like ChatGPT actually work?

8 explainers, each one drawn by Nib. Read it here, or play it and he draws and says every page. Updated .

▶ Play from the startQuick reviewCheat sheet

the short answer

A chatbot such as ChatGPT is a very large text predictor. It reads your message as numbered chunks of text called tokens, and it writes its reply by repeatedly guessing a likely next chunk, adding it to the text, and guessing again. It learned to guess well by practicing on enormous amounts of text, it uses a mechanism called attention to decide which earlier words matter, and it was then trained on examples and human preferences to behave like an assistant. Because it aims at text that sounds likely rather than text that has been checked, it can be wrong while sounding sure, so what matters should be verified.

Part 1 of 8

How does ChatGPT work?

▶ Play this partIts own page

Start with something familiar. Type “see you” into your phone and it suggests “soon”. It does not know your plans. It only knows what usually follows. A chatbot like ChatGPT is that same idea scaled up enormously.

Give it a sentence to finish, such as “The capital of France is”. The model scores every candidate for the next piece of text. “Paris” gets a very high score, a few alternatives get small ones, and “banana” gets almost none. It is not looking the answer up in a database; the score comes from patterns it absorbed in training.

Then comes the trick. The chosen piece is added to the text, the longer text goes back into the model, and it guesses again, round and round, until the reply is finished. Every fluent answer you have ever read from a chatbot was built one guess at a time.

The guess is a choice among likely options rather than one fixed answer. That is why, with the usual settings, asking the same question twice can produce different wording, and why early choices steer everything after them. The rest of this path explains how it guesses so well, and where the guessing slips.

A chatbot writes by guessing a likely next piece of text, adding it, and guessing again.

Part 2 of 8

How does it read your words?

▶ Play this partIts own page

We said the model guesses the next “piece” of text. What exactly is a piece? It is called a token. A fixed procedure chops your text into tokens before the model sees anything: everyday words usually stay whole, while rarer or longer words are cut into familiar fragments, a bit like building a long word from small blocks.

Then each token is swapped for a number, its identification code in a fixed list. From that point on, the model sees only numbers, never letters. It does not look words up in a dictionary of meanings either; it receives a list of numbered chunks.

There is a subtlety about timing. When you send a long message, the model takes in all of its tokens together, in one batch. Only the reply comes out one token at a time. It is not a person reading your message left to right, one word at a time.

This is also why chatbots can fumble tasks that depend on the letters inside words: they never received the letters, only chunks. We take that puzzle apart properly in a separate series, Why can’t AI count the r’s in “strawberry”?

Your words reach the model as numbered chunks, taken in together, and only the reply is produced one token at a time.

Part 3 of 8

How does it learn which words come next?

▶ Play this partIts own page

Who taught the machine to guess well? Nobody typed in grammar rules or facts. It learned by reading, an enormous amount of text from books, web pages and code.

The method is wonderfully simple. Take a real sentence, cover up the next token, and make the model guess it. The original text already contains the correct answer, so the grading is free: nobody has to label anything by hand.

Inside the model are billions of adjustable numbers called parameters, which you can picture as knobs on a giant mixing board. The best-known early large model, GPT-3, had 175 billion of them. At the start they are set at random and the guesses are gibberish. After each guess the model checks the real answer, and if it gave that token low odds, every knob gets a tiny push toward raising them. Each nudge is small, so that no single sentence overwrites what earlier text taught; the learning comes from an astronomical number of small pushes adding up.

Spelling gets learned first, then grammar, then facts and style, because all of it helps predict what comes next. When training ends, the knobs are frozen. What is left is a pattern of settings rather than a stored library of everything the model read, although a model can memorize some of its training text, and researchers have extracted verbatim passages from models.

The model learns by guessing the next token and nudging its billions of numbers toward the right answer, over and over.

Part 4 of 8

How does it know which earlier words matter?

▶ Play this partIts own page

Take the sentence: “The trophy didn’t fit in the suitcase because it was too big.” What does “it” refer to? To you it is obviously the trophy. To the model, the token “it” is just a number that is identical in countless sentences, so on its own it means almost nothing.

The mechanism that fixes this is called attention, and it was the central idea of the 2017 paper that introduced the transformer, the design behind today’s chatbots, built entirely on attention. Each token looks around and asks, in effect, which of the other tokens matter to me? It gives every other token a score, high for helpful ones and low for useless ones. For “it” in this sentence, “trophy”, “suitcase” and “big” get large weights, while little words like “the” get small ones. Training taught the model which clues usually point to the right noun.

Change the sentence to end “because it was too small” and the clue word changes, so the weight shifts toward the suitcase. The model is not simply linking “it” to the nearest noun; it is weighing the whole sentence.

Then “it” absorbs information from the words it weighted, in proportion, so the token now carries meaning from this particular sentence rather than a generic one. Every token does this at once, and the whole process is repeated through many layers. By the end, the last token has gathered the context it needs to guess what comes next.

Attention lets every token weigh the others, so context, not a fixed dictionary meaning, decides what a word refers to.

Part 5 of 8

Why do AI chatbots hallucinate?

▶ Play this partIts own page

Remember the training game: the model was scored on matching real text. Nobody scored it on whether a sentence was actually true. It was trained to be plausible, and correctness only comes along when true text happens to be the likely text.

Now think about what that means when you ask a question. The model does not open a file; it builds the answer one token at a time, choosing what fits. Ask it for a source and the most likely text looks like a citation, with an author, a journal and a year. The shape fits even if the paper does not exist.

There is also no built-in alarm for “I don’t know”. The model always produces a next token, and its tone stays equally confident whether the content is right or wrong. Where a fact appeared everywhere in the training text, likely and true usually match. Where it is rare, such as an exact number, a quote or a name, they drift apart.

This has had real consequences. In 2023 two New York lawyers were sanctioned after submitting a court filing that cited cases a chatbot had invented. Some chatbots can also search the web or use other tools, which helps, but the underlying habit remains. When a chatbot invents a detail, it is not broken or lying; it is doing exactly what it was trained to do. Treat fluent as a style, never as proof.

A chatbot is trained to sound likely, so it can state a false detail as fluently as a true one.

Part 6 of 8

Why does it forget what you said earlier?

▶ Play this partIts own page

Every guess looks at the text so far, but there is a ceiling on how much text fits in view. That ceiling is called the context window, and it is measured in tokens. Its size varies between models and has grown over time.

Everything shares one budget: your messages, the model’s replies, any hidden instructions from the app, and even the answer it is writing right now. When the conversation outgrows the window, the oldest text slides out. The model is not ignoring it; for the next guess, it simply is not there.

Nor does the model store your chat. Each turn, the application sends the whole conversation back in, and the model reads it fresh. Its parameters are not changed by talking to you, so a brand-new chat starts with an empty window. (Some products add separate memory features that save notes and put them into the window, but that is the app doing it, not the model remembering.)

The practical advice follows. Put what matters close to where you need it. In a long chat that is drifting, start fresh and paste in a short summary of what counts.

The model only sees what is inside its window each turn, so anything you want it to use has to be in there.

Part 7 of 8

How did a text predictor learn to follow instructions?

▶ Play this partIts own page

After the first stage of training, the model is a pure continuer. Type “What is the capital of France?” and it might simply write more questions, because on the internet a question is often followed by more questions, like a quiz.

So developers add a second stage. They collect many examples of a request followed by a good answer, and train the model on them in the same way as before, by guessing the next token, but on carefully chosen examples of good exchanges.

A third stage uses human preferences. The model writes several answers to one prompt, people rank them from best to worst, and those rankings are used to build a scoring signal for what people prefer. The model’s numbers are then nudged toward replies that score well. OpenAI described this approach in its 2022 InstructGPT work.

Underneath, nothing has changed: it still guesses one token at a time. But now the most likely continuation of your request is a real attempt to help. Notice what is being rewarded, though: what people prefer. That usually goes along with helpful and accurate, but it is not the same as verified true.

A helpful chatbot is a text predictor taught by examples and human preferences to aim at what you want.

Part 8 of 8

Does it understand, and how much should you trust it?

▶ Play this partIts own page

Does the machine understand anything? Experts really do split. It handles new puzzles and can explain ideas in fresh ways, which looks like understanding. It also fails at some simple things and has no senses of its own, which looks like the opposite. The honest answer is that this is unresolved.

The useful point is that your practice does not depend on settling it. Whether or not it understands, it was trained to sound likely, not to check. Even if a future model clearly did understand, that would not guarantee that every detail it states was accurate or checked. So treat its output as a draft.

That does not make it useless. A cover letter, a summary or a trip plan in seconds is real value, and then you edit. A great draft is worth having. For tone, structure and brainstorming, the risk is low.

Check hardest on four things: facts, numbers, quotes and citations. A made-up statistic looks exactly like a real one, so if a chatbot says a study found some percentage, find the study and confirm the number before repeating it. Use it like a brilliant, fast, sometimes overconfident assistant: let it draft, and confirm what matters before it matters.

Treat fluent output as a draft: let the chatbot write, then check the facts, numbers, quotes and citations yourself.

A chatbot is a text predictor. It reads numbered chunks, it learned to guess the next chunk from mountains of text, attention tells it which earlier words matter, a window limits what it can see, and examples and human preferences turned it into an assistant. Because all of that aims at likely text rather than checked text, the right way to use it is as a fast and fluent drafter whose facts you verify.

Quick review

The whole series in a few minutes: each part's last board, its one idea, and the lines worth keeping.

Part 1

How does ChatGPT work?

It guesses a likely next piece of text, adds it, and repeats.

  • Autocomplete is a small version of the same idea.
  • Each possible next piece gets a likelihood score.
  • Each guess is added to the text and fed back in.
  • Picking among likely pieces makes answers vary.
  • One simple act, repeated, produces the whole conversation.

Part 2

How does it read your words?

It does not read words: it receives numbered chunks of text called tokens.

  • The model's 'pieces' of text are called tokens.
  • Common words stay whole; rare words split into fragments.
  • A fixed menu of reusable chunks can build any text.
  • Each token is replaced by its numeric ID.
  • It takes in all tokens together, then replies one token at a time.

Part 3

How does it learn which words come next?

By guessing the next token over and over on huge amounts of text, and nudging billions of numbers.

  • Good guesses aren't programmed in; they're learned from text.
  • Hiding the next token turns any text into a self-grading quiz.
  • Parameters are billions of adjustable knobs, and they start out random.
  • Each wrong guess nudges every knob slightly toward the right answer.
  • Billions of tiny nudges add up to grammar, facts, and style.
  • What remains after training is a pattern of settings, not a library of the text.

Part 4

How does it know which earlier words matter?

Each token scores every other token for relevance and absorbs information from the ones that matter.

  • A token's number alone doesn't say what it means in this sentence.
  • Each token scores how relevant every other token is to it.
  • Learned patterns from training decide which words get the high scores.
  • Attention blends in information from the weighted words, so "it" now carries context.
  • Every token does this, layer after layer, until the model can predict the next token.

Part 5

Why do AI chatbots hallucinate?

It is trained to produce text that sounds likely, not text that has been checked.

  • Training rewarded 'sounds like real text,' not 'is true.'
  • Answers are built token by token from patterns, not retrieved from a record.
  • A made-up citation has the right shape, so it comes out looking real.
  • Confidence in the wording tells you nothing about whether it's accurate.
  • Errors cluster on rare, specific details where likely and true come apart.

Part 6

Why does it forget what you said earlier?

It only sees a fixed-size window of text, and the app resends the conversation each turn.

  • The context window is the fixed amount of text the model can look at in one go.
  • Your messages, its replies, and hidden instructions all share one budget.
  • When the chat outgrows the window, the oldest text falls out of view.
  • It doesn't remember your chat; the whole conversation is re-read from scratch every turn.
  • Restate what matters, and start fresh with a summary when chats get long.

Part 7

How did a text predictor learn to follow instructions?

It was fine-tuned on good example answers, then steered by human preferences.

  • A raw text predictor continues text; it does not try to help you.
  • Fine-tuning shows the model many request-and-good-answer pairs.
  • People rank several answers, and their preferences become a score.
  • The model is nudged toward answers people rate highly.
  • It is still a next-token predictor, now shaped to act like an assistant.

Part 8

Does it understand, and how much should you trust it?

Experts disagree about understanding; either way, treat fluent output as a draft to verify.

  • Whether it understands is an open question, not a settled one.
  • Both camps have real evidence; neither has won.
  • Your trust decision doesn't depend on the philosophy.
  • A false detail looks just like a true one.
  • Check the specifics: facts, numbers, quotes, citations.
  • Use it as a fast first draft, then verify.

Cheat sheet

One sheet: every part's key drawing and its key line.

  1. 1. How does ChatGPT work? It guesses a likely next piece of text, adds it, and repeats.

  2. 2. How does it read your words? It does not read words: it receives numbered chunks of text called tokens.

  3. 3. How does it learn which words come next? By guessing the next token over and over on huge amounts of text, and nudging billions of numbers.

  4. 4. How does it know which earlier words matter? Each token scores every other token for relevance and absorbs information from the ones that matter.

  5. 5. Why do AI chatbots hallucinate? It is trained to produce text that sounds likely, not text that has been checked.

  6. 6. Why does it forget what you said earlier? It only sees a fixed-size window of text, and the app resends the conversation each turn.

  7. 7. How did a text predictor learn to follow instructions? It was fine-tuned on good example answers, then steered by human preferences.

  8. 8. Does it understand, and how much should you trust it? Experts disagree about understanding; either way, treat fluent output as a draft to verify.