How does an AI pick its next word?
What a chatbot actually does when you press Enter, and a word predictor you train yourself.
-
Why now
A big number came up at a dinner
Reported
OpenAI, the company that makes ChatGPT, hosted a dinner in New York. The speaker was Adam Fry, ChatGPT's consumer product lead. ChatGPT, he said, had gone from 1 billion weekly users to 1.2 billion in 60 days. Source OpenAI had already shown that 1.2 billion figure at its DevDay event on September 29. Source The figure is OpenAI's own count, and the reports do not mention any outside check.
Two hundred million more people in two months, all typing into the same box.
Here is a smaller question, the kind that doesn't usually come up at dinner.
Guess first. When you press Enter, what does the box do?
- Looks up the exact answer in a huge database You have company. In one survey, 45% of US adults picked this. It is the most popular answer, and it is wrong.
- Follows a script of prewritten responses In one survey, 21% of US adults picked this. There is no script.
- A person writes each answer In one survey, 6% of US adults picked this. Nobody is typing back.
- Guesses what comes next, piece by piece In one survey, 28% of US adults picked this, and it is the closest. The next step explains what that means.
In that survey of 2,301 US adults, 45% picked the database, 21% the script, 6% a person, and 28% guessing. Guessing is the closest to what really happens.
-
Step by step
There is no answer waiting anywhere
A chatbot writes one small piece of text and adds it to what is already there. Then it looks at the whole thing and picks the next piece. Then it does that again, until it stops. Researchers call this autoregressive, which means each piece it writes becomes part of what it reads next. Source Textbook
The program inside a chatbot that does this is called a language model, or just a model.
The survey you just saw came from the Searchlight Institute, a policy group, and Tavern Research. It asked 2,301 US adults in August 2025. Survey Analysis The biggest group, the 45% who picked the database, were picturing a very large filing cabinet.
A chatbot can also search the web and read what it finds. It still writes the reply this way, one piece at a time.
-
Step by step
The pieces are called tokens
A token is a chunk of text from a fixed list. Some tokens are whole words. Others are common bits of words, like
-er. SourceA tokenizer is a program that cuts text into tokens. One from OpenAI splits
tiktoken is great!into six tokens:tiktokenisgreat!Notice the spaces. Here, each space is part of the token after it. SourceWhere the cuts fall depends on the list. The word
antidisestablishmentarianismis 5 tokens on an older OpenAI list and 6 on newer ones. Source So think of a token, roughly, as a word or a piece of a word.A model comes across a word it has never seen, and its list of tokens is fixed. What happens?
- It stops and reports an error It doesn't need to stop. Look again at how
tiktokenwas split. - It builds the word from pieces it has That is why the list has pieces and not only whole words. Any new word can be built from them.
- It adds the new word to its list The list is fixed before the model is trained. It doesn't grow while you chat.
- It stops and reports an error It doesn't need to stop. Look again at how
-
Step by step
Every token gets a chance
At each step, the model gives a score to every token on its list. GPT-2, an older OpenAI model, has 50,257 tokens on its list. Source A piece of math called softmax turns those scores into probabilities that add up to 100%. Source This lesson also calls them the odds.
These numbers are made up for teaching, using a list of only four words. A real model does this across its whole list, and most of the probability usually lands on a small group of tokens. Even a silly token gets some tiny chance. In a model like this, the number is never exactly zero.
At each step, how many tokens get a probability?
- Just the single best one The best one hasn't been chosen yet. The model works out the odds first and chooses after.
- About ten likely ones Most of the probability may land on a small group, but the rest still get a number.
- Every token on the list Every one, even the silly ones. For GPT-2 that means 50,257 numbers for each new token it writes.
-
Step by step
Then the model picks one token, and not always the top one
The simplest rule is to always take the token with the highest odds. That is called greedy, and it gives generic, repetitive text. The usual method is a random draw that favors higher odds, which is why the same question can get two different answers. Source
A setting called temperature changes the odds before the draw. High temperature evens them out, and low spreads them apart. Their order never changes, only the gaps between them. The table shows this for the word after "The cat sat on the."
Temperature mat floor couch moon 0.5 86.7% 11.7% 1.6% 0.03% 1 65.7% 24.2% 8.9% 1.2% 2 47.4% 28.7% 17.4% 6.4% We found no temperature setting in the ChatGPT or Claude apps. Developers build software on these models. On newer Claude models, they can't change the temperature. Anthropic, which makes Claude, says those models run at a temperature of 1. Anthropic On the newest OpenAI models, they can change it only in limited cases. OpenAI To try it, use open models, which anyone can download.
Why can the same question get two different answers?
- The next token is drawn at random, using the odds A different draw early on leads to different odds later, and the two answers drift apart.
- The model changes its mind about the facts The model doesn't have to change at all. A different draw is enough.
- Temperature reorders the words each time Temperature changes the gaps and never the order. In the table on the last screen, mat is first in every row.
-
Try it
Train your own predictor
The predictor below reads a text, keeps a table counting which word follows which, and turns the counts into odds. It is called a bigram model, because it works with pairs of words, and it runs on your device. The mathematician Claude Shannon printed text like this in 1948. Text like this still reads the way his did: a few words at a time seem fine, but the whole thing is nonsense. Source
The sample text is the first two chapters of Alice's Adventures in Wonderland. Press Train it. Press Pick next word a few times. Then press Add 20 words and read the result out loud. Last, drag the temperature slider all the way down, and then all the way up.
This experiment needs JavaScript. You can build the same predictor in the project at the end of this lesson.
With the temperature turned far down, what happens to the text?
- It gets more surprising, with rare words showing up Surprises come from the high end of the slider. The low end favors the most common words.
- The common words almost always win, so it starts to repeat This is the same problem the greedy rule has. A table with one favorite word after each word soon goes around in a circle.
- It learns new words from the book as it goes The learning ended when you pressed Train it. The slider only reshapes the odds.
-
Step by step
What your predictor shares with a real model
They have more in common than you might expect.
- Both give odds for each item on a fixed list.
- Both draw one item using those odds, add it to the text, and repeat.
- Both learn from text, and nobody writes grammar rules into them by hand.
- Both are graded the same way, by how surprised they were by the item that really came next.
- Both are shaped by what they read.
Your predictor is a table of word counts. Counting the word pairs and dividing by the total gets a table like yours the best possible grade on the text it trained on, with no further training. Source
So your table and a real model do the same job and are graded the same way. They are not built the same way inside.
-
Step by step
Why a bigger table can't do the job
Your table looks back one word. A table of pairs like yours, using GPT-2's list of tokens, would have about 2.53 billion cells. That is already more numbers than the whole GPT-2 model holds, which is 1.5 billion. GPT-2 can look back on 1,024 tokens. A table that looked back that far would need about 104814 rows. No computer could hold that. Source
So a real model stores weights instead. Weights are numbers the model adjusts during training, and the same weights get used in every situation. No weight on its own means "the odds that the next word is mat." The model works out the odds fresh at each step. Source
Weights also fix a problem you may have run into. Your table has nothing to say about a pair of words it never saw. During training, the weights picked up patterns from similar text, so a real model can still make an estimate. Source
What does a real model store instead of a giant table?
- Every sentence it has ever read, word for word Storing them would not be the hard part. The problem is that most sentences you could type have never been written before.
- A longer table that looks back over more words This is the tempting answer, but it can't work. Looking back as far as GPT-2 does would take about 104814 rows.
- Weights, the numbers it uses to work out fresh odds No single weight means anything you could read. The odds appear only when the model runs those numbers on your text.
-
Step by step
How does a model learn?
Training shows the model real text. At every position in the text, the model gives its odds for what comes next. Training then checks one number: how much probability the model gave to the true next token, the one that really came next. From that number comes a score called loss, which measures how surprised the model was. Source
Probability on the true next token Loss 90% 0.11 50% 0.69 1% 4.61 A blind guess, with equal odds across GPT-2's list 10.82 The weights then get nudged to lower the loss, and the process repeats. OpenAI's GPT-3 models went through 300 billion tokens during training. Source Meta's biggest Llama 3.1 model trained on 15.6 trillion. Source We could not find an exact number for the newest top models from OpenAI, Anthropic or Google. For text, OpenAI's public summary of the training data for GPT-6 Astra gives only a range: more than 10 trillion tokens. Source Anthropic's summary for Claude Opus 5.5 gives the same range. Source
The true next word is "mat." Which model gets the biggest loss?
- One that gave mat 90% That gives a loss of only 0.11. The model was barely surprised.
- One that gave mat 50% That gives a loss of 0.69. A coin flip between two words isn't too costly.
- One that gave mat 1% That gives a loss of 4.61. The less probability on the true word, the higher the loss.
-
Step by step
Why does a chatbot answer you instead of just continuing your text?
Training on next words alone gives a base model, which is poor at following instructions. A 2022 OpenAI paper shows a hand-picked example. GPT-3 was asked, in French, for a short story about a time-traveling frog. It wrote more writing prompts instead. InstructGPT, a version of the model tuned with extra training, wrote the story. Source
The tuning needed people, known as labelers. They wrote good answers, and the model was tuned on those answers. They also ranked the model's replies. A second model learned what they preferred, and the first model was then trained to score well with the second. Source
The tuning did not make the model truthful. On tasks where the answer should come from a text it was given, that 2022 version still made up information 21% of the time, compared with 41% for GPT-3. Source In a 2026 survey by Common Sense Media, a nonprofit focused on kids and technology, 42% of US kids aged 9 to 17 said AI can tell true things from false things. Source
A chatbot gives you a smooth, confident answer. What should you do with it?
- Trust it, since it was tuned by people In the 2022 OpenAI paper, tuning cut how often the model made things up, but did not stop it.
- Treat it as a claim to check A tuned model can still make up facts. Sounding sure tells you nothing about being right.
- Ignore it, since it's only guessing It is often right, and that is what makes it tricky. You can't tell the right answers from the wrong ones by how they sound.
-
The honest part
Is "it just predicts the next word" the whole story?
That line is accurate about what comes out of a model. Whether it also covers what happens inside is still being argued.
In 2025, Anthropic, the company that makes Claude, studied one of its own models writing a rhyming couplet, a pair of lines that rhyme. The first line ended in "grab it," and the second ended in "rabbit." The researchers expected the model to improvise, choosing the rhyming word only when it reached the end of the second line. Instead, they found signals inside the model for "rabbit" and "habit" already active before the second line began. Changing those signals changed the line. It looked as if the model was planning the rhyme ahead of time. Source
-
The honest part
How far does the rhyme finding go?
The Anthropic researchers found early signals for the rhyming word in about half the poems they checked. They say the model may not have planned in the rest, or their tool may have missed it. The tool they used to look inside the model gave satisfying insight on about a quarter of all the prompts they tried, not just poems. The examples they show are the ones that worked, and even those capture a small part of what the model does. Source
A 2026 paper by researchers at European universities and at Google DeepMind, Google's AI lab, calls this kind of planning universal across many models. Source Two Stanford researchers tested more than ten open models. Only one, Google's Gemma-3-27B, clearly used a rhyme signal at the break between the two lines. The others kept relying on the last word of the first line. Source
Part of the disagreement is about what counts as planning. None of this shows that a model has intentions or awareness.
What can you fairly say about this research?
- Some models, on some tasks, seem to pick a word early, but how widely is disputed That is about as far as the evidence goes today.
- All AI models think ahead, and they do it the same way people do These tests covered rhymes and short questions on certain models. Nothing shows that models plan the way people do, and the newest top models weren't tested.
- It has been proven that models do nothing inside except predict the next word The studies point the other way, even while they disagree on details. Whether "just predicting" is the whole story is not settled either.
-
Your project
Build it on a whole book
- You will have A word-pair table from a real book, some text the table wrote, and a side-by-side comparison with GPT-2.
- Time About 60 to 90 minutes.
- You need A computer, JupyterLite (a free tool for running code in your browser, with no account needed), and an adult for steps 1, 5 and 6.
- Ask a parent or teacher to download one plain-text book from Project Gutenberg, a free online library. Its terms say minors should be accompanied by an adult. Pick a book in English, since this code reads only the letters a to z.
- Delete Gutenberg's notes at the top and bottom of the file, or they will end up in your counts. Name the file
book.txt. - Open JupyterLite and start a Python notebook, which is a page for running code in the Python language. Upload the file and run this code:
Show the code
import random, re from collections import Counter, defaultdict text = open('book.txt', encoding='utf-8').read().lower() words = re.findall(r"[a-z']+", text) table = defaultdict(Counter) for a, b in zip(words, words[1:]): table[a][b] += 1 def top(word, n=3): c = table[word] total = sum(c.values()) return [(w, round(k / total * 100, 1)) for w, k in c.most_common(n)] def write(start, length=8, seed=1): random.seed(seed) out = [start] for _ in range(length): c = table[out[-1]] if not c: break out.append(random.choices(list(c), weights=list(c.values()))[0]) return ' '.join(out) print(top('the')) print(write('the', 20))- Try other words in place of
'the'. Find one whose most common next word surprises you. Changeseed, the number that sets the random draws, and watch the text change. - Open Transformer Explainer, a web page that shows the real odds from a small version of GPT-2. It downloads about 600 MB, so use Wi-Fi and ask a parent or teacher first.
- Have an adult type the same starting words you used into a big chatbot, on their own account. Many services are for ages 13 and up, often with a parent's permission, and some, including Claude, are for ages 18 and up.
- You now have three predictors: your table, GPT-2 and the chatbot. For each one, write down one place it failed, and why. Save your notebook before you close the tab, because browser storage can get wiped.
-
Done
Back to the box
Tonight a great many people will type a question into a chatbot's text box. It will answer in whole sentences, one piece at a time, and it will sound sure of itself.
You can keep using it. You just know what it is doing now.
Next lesson Will an AI try to escape?Sources
- Big Technology, Nov 3, 2026: ChatGPT's reported user count. OpenAI's own figure. Engadget, Sept. 29, 2026: the same figure at DevDay.
- Searchlight Institute and Tavern Research, survey of 2,301 US adults, August 2025.
- Punya Mishra, analysis of the same survey.
- Common Sense Media, AI census of 1,204 US youth aged 9 to 17, March 2026.
- Jurafsky and Martin, Speech and Language Processing, draft of August 2026: chapters 2, 3 and 7.
- OpenAI Cookbook: how tokens split.
- GPT-2 paper and GPT-3 paper (OpenAI).
- Llama 3 paper (Meta).
- OpenAI, public summary for GPT-6 Astra, Sept. 2, 2026, and Anthropic, summary for Claude Opus 5.5, Sept. 22, 2026 (a copy kept by a Trinity College Dublin project): training size, given only as a range.
- Ouyang et al. 2022 (OpenAI): InstructGPT.
- Anthropic and OpenAI developer guides: temperature on newer models.
- Shannon 1948: word-pair text.
- Bengio et al. 2003: why learned weights handle unseen pairs.
- Lindsey et al. 2025 (Anthropic); Maar et al. 2026 (Potsdam, Utrecht and Google DeepMind); Ma and Rui 2026 (Stanford): planning inside models.
The temperature and loss numbers are worked out from the standard formulas, and the mat example uses made-up scores. The table sizes are our arithmetic from GPT-2's published numbers.
Last checked . This field moves fast, so some model details may have changed. Torah Tech researched and wrote this lesson with the help of Claude, an AI made by Anthropic, whose research appears above. Any mistakes are ours.