Lesson 01.04
How AI builds a sentence
You will be able to explain how a generative language model builds a response by repeatedly predicting and adding the next piece of text.
What you’ll do
- RelateRemember your phone's suggestions?
- ExplainPredict, add, repeat
- ExperimentBuild a sentence
- ApplyWhy AI responses appear gradually
- ReflectRemember the idea
- Check3 questions, with feedback
Remember your phone's suggestions?
Last time, we used phone suggestions to understand language models. Before moving on, try to remember what helped you predict the next word.
Quick check
Imagine starting a message with “I'm”, then accepting one suggestion after another. What happens when you keep going?
Text description
Three stages of a phone message: I'm, I'm going, and I'm going to, with a different highlighted next suggestion at each stage.
Predict, add, repeat
Many modern generative language models build text by repeatedly predicting a possible next piece, selecting one and adding it to the text. The next prediction uses the updated context.
Text description
A loop: read I'm going, predict possible next pieces including to, home and outside, select and add to, then repeat using I'm going to.
This repeated process is called autoregressive generation. You do not need to memorize the term yet. Remember three words: Predict. Add. Repeat.
Build a sentence
SimulationBuild a sentence one piece at a time
Choose an example. Add one piece at a time and notice how the text grows. Reset and try the other example.
I went to the bakery
IllustrativePredefined illustrative continuations, not live model output or actual tokenizer splits.
Each new piece extends the text available for the next prediction. Our experiment follows a prepared sequence; a real generative model chooses continuations using its learned patterns and the available context.
Now imagine telling a friend your evening plans: “Tonight, I want to…” What if the next piece changes?
PredictOne choice changes what follows
Try the same candidate continuations after three different earlier choices. Pick the most natural fit.
Case 1 of 3
Tonight, I want to cook …
Text description
The same opening Tonight, I want to branches into cook dinner for my family, watch a movie with my friends, and read a book before bed.
Even a small difference early in a response can change the direction of later text. It does not mean that every run must produce a different answer.
Why AI responses appear gradually
When a chatbot answers a question, you often see the response appear gradually. An application can receive and display parts of a response while generation is still happening.
Text description
Two approaches at the same illustrative point before completion: streaming shows You can improve your application's, while waiting shows Preparing response. At completion both show the same full answer.
Receiving output progressively is called streaming. A frontend can display partial text as it arrives; a backend can support delivering it progressively. Streaming does not necessarily make the model finish generating sooner.
Common misconception
MisconceptionEvery chunk a chatbot displays is exactly one piece predicted by the model.
A better understandingA displayed chunk can contain multiple model-generated pieces. Generation and streaming are related, but they are not the same process.
Remember the idea
Exercise
Explain it to a friend
Without looking back, explain why a chatbot can produce an entire paragraph instead of suggesting just one word. Use the phone example.
What you might observe
A typical generative language model predicts a possible next piece, adds a selected piece and repeats using the updated context. Many small additions can produce a longer response.
We've been calling them small pieces of text. But is a piece always an entire word? These units are called tokens. We'll explore them in the next lesson.