The Lab · AI

How does an AI pick its next word?

What a chatbot actually does when you press Enter, and a word predictor you train yourself.

  • 13 steps
  • About 20 minutes
  • One experiment
  • Then a project
  1. Why now

    The number came up at a dinner

    Reported

    It was an OpenAI-hosted dinner in New York, and 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 the 1.2 billion at its DevDay event on September 29. Source It is OpenAI's own count, and the reports cite no 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 21% of US adults in that survey picked this. There is no script.
    • A person writes each answer 6% of US adults in that survey picked this. Nobody is typing back.
    • Guesses what comes next, piece by piece That is what 28% of US adults in the survey picked, and it is the closest. Next, what it 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.

  2. 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 output becomes part of the next input. Source Textbook

    The survey you just saw, by the Searchlight Institute and Tavern Research, asked 2,301 US adults in August 2025. Survey Analysis The biggest group, 45%, 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.

  3. 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, like -er. Source

    One OpenAI tokenizer splits tiktoken is great! into six tokens: t ikt oken  is  great ! Notice the spaces. Here, each space is part of the token after it. Source

    The splits depend on the list. antidisestablishmentarianism is 5 tokens in an older OpenAI list and 6 in newer ones. So think of a token as roughly a word piece.

    A model meets a word it has never seen. Its token list is fixed. What happens?

    • It stops and reports an error It doesn't need to stop. Look again at how tiktoken was split.
    • It builds the word from smaller pieces it already 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.
  4. 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 a list of 50,257. Source A piece of math called softmax turns those scores into probabilities that add up to 100%. Source

    The cat sat on the ___ mat65.7% floor24.2% couch8.9% moon1.2%
    These numbers are made up for teaching, on a four-word list. 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. Choosing comes after the odds.
    • 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.
  5. Step by step

    Then it picks one, and not always the top one

    The simplest rule is to always take the top token. That is called greedy, and it gives generic, repetitive text. So the usual choice is a draw, weighted by the odds. That is why the same question can get two different answers. Source

    Temperature changes how even the odds are before the draw. It never changes the order, only the gaps.

    Temperaturematfloorcouchmoon
    0.586.7%11.7%1.6%0.03%
    165.7%24.2%8.9%1.2%
    247.4%28.7%17.4%6.4%

    We found no temperature setting in the ChatGPT or Claude apps. Developers can't change it on newer Claude models, and on the newest OpenAI models only in limited cases. Anthropic says its newer models run at a temperature of 1. You can try the math yourself in open models and demos. Anthropic OpenAI

    Why can the same question get two different answers?

    • The next token is drawn at random, using the odds Right. 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. Check the table: mat is first in every row.
  6. Try it

    Train your own predictor

    This one reads a text, counts which word follows which, and turns the counts into odds. It is called a bigram model, and it runs on your device. Claude Shannon printed text like this in 1948, and it still reads the way he showed: fine up close, nonsense from a distance. Source

    The sample is the first two chapters of Alice's Adventures in Wonderland. Press Train it. Pick a few words. Add 20 and read them out loud. Then drag the temperature all the way down, and 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 That is the high end of the slider. The low end plays it safe.
    • The most common words win almost every time, so it starts repeating itself This is the same problem greedy has. A table with one favorite after each word soon runs in a circle.
    • It learns new words from the book The learning ended when you pressed Train it. The slider only reshapes the odds.
  7. Step by step

    What your predictor shares with a real model

    More than you might expect.

    • Both give odds for each item on a fixed list.
    • Both draw one, add it, and repeat.
    • Both start from text, with no grammar rules written by hand.
    • Both get the same grade: how surprised they were by the true next item.
    • Both are shaped by what they read.

    For a table like yours, counting and dividing gets the best possible score on that grade for the text it trained on, in one step. Source

    Same job. Same grade sheet. It does not have the same insides.

  8. Step by step

    Why a bigger table can't get there

    Your table looks back one word. A word-pair table over GPT-2's list would have about 2.53 billion cells. That is already more numbers than all of GPT-2, which has 1.5 billion. A table for the 1,024 tokens GPT-2 can look back on would need about 104814 rows. No computer gets there. Source

    So a real model stores weights instead. Weights are numbers the model adjusts during training, and they are shared across every situation. None of them reads as "the odds of mat." The odds get worked out fresh at each step. Source

    That also fixes a problem you may have hit. Your table has nothing to say about a pair it never saw. A real model makes an estimate from similar contexts. Source

    What does a real model store instead of a giant table?

    • Every sentence it ever read The storage would not be the hard part. The problem is that most sentences you could type have never been written before.
    • A longer table with more words of context This is the tempting answer. The 104814 rows are why it can't work.
    • Weights shared across every situation, used to work out fresh odds No single weight means anything you could read. The odds only appear when the numbers run on your text.
  9. Step by step

    How does it learn?

    Training shows the model real text and, at every position, asks for odds on what comes next. Then it checks one number: how much probability went to the true next token. That score is called loss, and it measures surprise. Source

    Probability on the true next tokenLoss
    90%0.11
    50%0.69
    1%4.61
    A blind guess across GPT-2's list10.82

    The weights get nudged to lower the loss, and the process repeats. GPT-3 models trained for 300 billion tokens. Source Meta's Llama 3.1 flagship trained on 15.6 trillion. Source We could not find an exact number for the newest top models from OpenAI, Anthropic or Google. OpenAI's public summary for GPT-6 Astra says only: more than 10 trillion tokens of text. Source Anthropic's summary for Claude Opus 5.5 says the same. Source

    The true next word is "mat." Which model takes the biggest loss?

    • One that gave mat 90% That costs only 0.11. It was barely surprised.
    • One that gave mat 50% That costs 0.69. A coin flip between two words isn't too costly.
    • One that gave mat 1%, because it was sure of another word That costs 4.61. The less probability on the true word, the higher the loss.
  10. Step by step

    Why does it answer you instead of just continuing?

    Next-word training alone gives a base model, and base models are poor at following instructions. In a hand-picked example from a 2022 OpenAI paper, a request in French for a short story about a time-traveling frog went to GPT-3. It wrote more writing prompts. The tuned version, InstructGPT, wrote the story.

    The tuning took people. Labelers wrote good answers, and the model was tuned on them. They ranked outputs, a second model learned their preferences, and the first was then trained to score well with it. Source

    That did not make it truthful. On tasks where the answer should come from a given text, that 2022 version still made up information 21% of the time, against 41% for GPT-3. In a 2026 Common Sense Media survey, 42% of US kids aged 9 to 17 said AI can tell true from false. Source

    A chatbot gives you a smooth, confident answer. What should you do with it?

    • Trust it, since it was tuned by people Tuning cut the making-up in that test and did not end 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 the difficulty. You can't tell which answers are which by how they sound.
  11. The honest part

    Is "it just predicts the next word" the whole story?

    It's accurate about the output. Whether it covers what happens inside is a live argument.

    In 2025, Anthropic, the company that makes Claude, studied one of its own models writing a rhyming couplet. The first line ended in "grab it," and the second ended in "rabbit." The authors expected the model to improvise at the end of the line. They found signals for "rabbit" and "habit" already active before the line began. Changing those signals changed the line. Source

    They found these signals in about half the poems they checked. Their tool gave a satisfying look inside on about a quarter of the prompts they tried. They show only successes, and even those capture a small part of the model's work. Source A 2026 paper by European and Google DeepMind researchers calls this kind of planning universal. Source Two Stanford researchers tested more than ten open models, and only Google's Gemma-3-27B clearly used the signal at the line break. Source Part of the disagreement is about what counts as planning. None of this shows intention or awareness.

    What can you fairly say about this research?

    • Some models, on some tasks, seem to settle on a word early, and researchers disagree on how widely That is about as far as the evidence goes today.
    • All AIs think ahead the way people do These tests covered rhymes and short questions on certain models. Nothing shows it works the way people do, and the newest flagships weren't tested.
    • It has been proven that nothing is going on inside The studies point the other way, even while they disagree on details. "Just predicting" is not settled either.
  12. Your project

    Build it on a whole book

    • You will have A word-pair table from a real book, text it wrote, and a side-by-side with GPT-2.
    • Time About 60 to 90 minutes.
    • You need A computer, JupyterLite (free, no account, runs in your browser), and an adult for steps 1 and 6.
    1. Ask a parent or teacher to download one plain-text book from Project Gutenberg. Its terms say minors should be accompanied by an adult. Pick a book in English, since this code only reads a to z.
    2. Delete Gutenberg's notes at the top and bottom of the file, or they end up in your counts. Name it book.txt.
    3. Open JupyterLite, start a Python notebook, upload the file, and run this:
    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))
    1. Try other words. Find one with a surprising favorite. Change seed and watch the text change.
    2. Open Transformer Explainer to see the real odds from a small version of GPT-2. It downloads about 600 MB, so use Wi-Fi and ask first.
    3. Have an adult type your same starting words into a big chatbot, on their own account. Many services are 13+, often with a parent's permission, and some, including Claude, are 18+.
    4. Write down one place each of the three failed, and why. Save your notebook before you close the tab, because browser storage can get wiped.
  13. Done

    Back to the box

    Tonight a great many people will type a question into that 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?

    Back to the Lab

    Sources
    1. Big Technology, Nov 3, 2026: ChatGPT's reported user count. OpenAI's own figure. Engadget, Sept. 29, 2026: the same figure at DevDay.
    2. Searchlight Institute and Tavern Research, survey of 2,301 US adults, August 2025.
    3. Punya Mishra, analysis of the same survey.
    4. Common Sense Media, AI census of 1,204 US youth aged 9 to 17, March 2026.
    5. Jurafsky and Martin, Speech and Language Processing, draft of August 2026: chapters 2, 3 and 7.
    6. OpenAI Cookbook: how tokens split.
    7. GPT-2 paper and GPT-3 paper (OpenAI).
    8. Llama 3 paper (Meta).
    9. 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.
    10. Ouyang et al. 2022 (OpenAI): InstructGPT.
    11. Anthropic and OpenAI developer guides: temperature on newer models.
    12. Shannon 1948: word-pair text.
    13. Bengio et al. 2003: why learned weights handle unseen pairs.
    14. 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.

The Opportunity Year · Tel Aviv, Israel

Learn like this for a year

Torah Tech is a beit midrash in Tel Aviv built for personal and professional growth: Torah learning at the center of every day, and internships at Israeli startups. It is the year a future Jewish leader realizes who he can become, and chooses to become it.