Book an info sessionInfo session

How chatbots predict the next word

AI Explorers · lesson 16 of 24 · 25 min

Text a friend “I’m on my…” and they can probably guess the next word: “way.” AI chatbots are built on that same skill, scaled up enormously.

Natural interaction

Natural interaction is the big idea about computers communicating with people in ways that feel natural to us: talking, typing everyday sentences, and understanding replies. Voice assistants, translation apps and AI chatbots all belong here.

The part of AI that works with human language is called natural language processing. Today’s best-known chatbots are powered by large language models, or LLMs.

The next-word game

At its core, a large language model does one thing: given some text, it predicts what text is likely to come next.

Try it yourself. Finish these:

  • “Peanut butter and…”
  • “Once upon a…”
  • “The bus was late, so I…”

The first two are easy because you’ve seen them so many times. The third has many reasonable endings. A language model works the same way, but it learned its guesses by studying a huge amount of text written by people, like books, articles and websites.

To write a reply, the model predicts one small piece of text, adds it, then predicts the next piece, and repeats. These pieces are called tokens. A token can be a whole short word or part of a longer word.

Why it sounds so smart

Because it learned from so much human writing, an LLM can produce text that sounds like an expert, a poet, or a friendly tutor. It has picked up patterns of grammar, facts that appear often, and styles of writing.

After that first training, companies usually train chatbots further with feedback from people, rating which answers are helpful and safe. That makes them better at following instructions and refusing harmful requests.

But remember: predicting likely words is not the same as knowing what is true. A chatbot produces text that sounds right. Most of the time that overlaps with being right. Sometimes it doesn’t. That is the topic of the next lesson.

Generative AI

Chatbots are one kind of generative AI: AI that creates new content. Other generative tools make images, music, voices or video from a text description. They all learn patterns from huge collections of human-made examples, then generate new combinations.

The amount of text these models learn from is enormous, far more than one person could read in many lifetimes. That is why they can write about so many topics. But it also means they pick up the mistakes, opinions and unfair stereotypes that appear in human writing. Companies try to reduce those problems, but they do not disappear completely.

Try it

Play “human language model” with two or more people. No devices needed.

  1. Sit in a circle. One person says the first word of a story, like “Yesterday.”
  2. Each person adds exactly one word that fits, going around the circle, to build sentences.
  3. Do three rounds. In round 1, choose the most normal next word. In round 2, choose a surprising but still sensible word. In round 3, anything goes.
  4. Write down one sentence from each round.
  5. Discuss: which round made the most sense? Which was most creative? Which sounded “right” but had a made-up fact in it?

Check yourself

What is the main thing a large language model does?

Predicts what text is likely to come next, piece by piece.

What is a token?

A small piece of text, like a short word or part of a word, that a language model predicts one at a time.

Does sounding confident mean a chatbot is correct?

No. It produces likely-sounding text, which is not always true.

Key words

  • Natural language processing: AI that works with human language.
  • Large language model (LLM): an AI model trained on huge amounts of text to predict the next words.
  • Token: a small chunk of text a language model works with.
  • Generative AI: AI that creates new text, images, sound or video.

Previous lesson: The bad data experiment
Back to AI Explorers
Next lesson: Why AI makes things up