Pettigrew Lab

How does ChatGPT work?

ChatGPT writes by guessing. It breaks your message into chunks called tokens, then predicts the most likely next chunk, adds it, and predicts again, hundreds of times, until the answer is done. It learned what’s likely from an enormous amount of text. It never plans the sentence ahead and never checks it against the world, which is why it can sound sure and still be wrong.

It reads in chunks, not letters

Before a chatbot can do anything with your words, it turns them into tokens. Common words stay whole, and longer or rarer words break into pieces. Everything it knows is patterns between those chunks.

That’s why chatbots have famously miscounted the r’s in “strawberry.” They never saw the letters, only the pieces. Type something below and watch it break apart.

Type anything and watch it break into chunks. The chunks are what a chatbot actually reads.

This is the same exercise that’s in the app.

How·many·r’s·are·in·“strawberry”?

Letters
24
Words
6
Chunks
11

This is a simplified tokenizer so you can watch the idea work. Real chatbots learn tens of thousands of chunks from data, so their pieces won’t match these exactly.

Words become places on a map

Each chunk gets turned into a list of numbers, a bit like coordinates. Chunks that get used in similar ways end up close together, so “puppy” sits near “dog” and far from “invoice.” The model learns those positions from which words keep the same company, with hundreds of directions instead of two.

It writes one chunk at a time

To write, the model looks at everything so far and scores every possible next chunk by how likely it is. It picks one, adds it to the end, and does the whole thing again. A setting called temperature decides how often it picks something less likely, which is why the same question can get different answers.

The piece that makes this work at scale is called attention. For each new chunk, the model weighs which earlier words matter most, which is how it keeps track of a name from three paragraphs back.

Why it makes things up

A chatbot produces likely text, and a confident made-up answer is very likely text. A fake citation looks exactly like a real one. The extra training that made chatbots polite and helpful made them nicer to talk to, not more truthful.

So the practical rule is the one the course lands on: anything you’d be embarrassed to get wrong, you check.

Questions people ask

Does ChatGPT understand what it says?

Not the way you do. It learned patterns in how words follow each other, and those patterns hold a surprising amount of knowledge. But nothing in it checks an answer against the world, so it can be fluent and wrong at the same time.

What is a token in ChatGPT?

A chunk of text the model reads and writes in. Common words are usually one token, longer words split into a few, and punctuation gets its own. Chatbot limits and prices are counted in tokens.

Why does ChatGPT give different answers to the same question?

Because it picks each next chunk with a little randomness built in. A setting called temperature controls how much, so it doesn’t always take the single most likely word.

Learn it by doing it

Module 21, “How Chatbots Work,” covers this in four lessons: the r’s in “strawberry,” words as places on a map, guessing the next word, and why chatbots make things up.

Data to AI is five-minute lessons on how AI works, starting with the data on your phone, for curious teens, parents and grandparents. No math needed. The first lesson runs right here in your browser.

Keep going