AI Lab › Explainer
How do chatbots work?
A chatbot is built around one simple job: given some text, predict what comes next. It does this again and again, one small piece at a time, until it has written a whole answer.
Predicting the next word
Finish this: "Peanut butter and ___". You probably thought "jelly". A language model works in a similar way. It was trained on enormous amounts of text, and it learned which words tend to follow which. For every blank it can calculate odds, like "jelly 88%, banana 4%, honey 3%".
Tokens, not letters
Models do not read letter by letter. They split text into chunks called tokens, which can be a word or part of a word. That is why chatbots can struggle with things like counting the letters in a word. They see chunks, not letters.
Why answers differ each time
When several words are almost equally likely, the model picks among them with some randomness. Ask the same question twice and you can get two different answers. When one word is far more likely, like "Paris" after "The capital of France is", the answer is steady.
Context matters
The odds change with everything that came before. Add a few words to your question and the list of likely next words changes. This is why how you ask matters so much.
What this explains
- Fluent writing. Predicting likely text produces smooth sentences.
- Confident mistakes. A likely-sounding word is not always a true one.
- Different answers. The model samples from odds, it does not retrieve a fixed answer.
Companies also train models further with human feedback to make answers more helpful and safe, and some tools can search the web or run code. But the core of how the text is written is still prediction.
Talk about it
- If a model only predicts likely words, why can it still write helpful answers?
- What kinds of questions are the model most and least likely to get right, and why?
Words to know
- Language model
- An AI trained on lots of text to predict which words come next.
- Token
- A chunk of text, such as a word or part of a word, that a model reads and writes.
- Probability
- How likely something is, often shown as a percentage.