Lesson 3 · Part 1. How language models work · 6 min
What a language model is
Goal. Explain a language model in one sentence, and say why every app feature built on one is a loop.
You build apps. You know functions: input in, output out. A language model is a function too. Once you hold that picture, the rest of the course is easier.
The one-sentence model
A language model takes a list of tokens. It returns a probability for every possible next token.
That is all. It does not "understand" your question. It scores which small piece of text is most likely to come next.
Take the text The capital of France is. The model might return something like this.
| Next token | Probability |
|---|---|
Paris |
0.92 |
a |
0.03 |
the |
0.02 |
| thousands of others | the rest |
All the probabilities add up to 1. A program then picks one token. That pick is called sampling.
Writing text is a loop
One pick gives one token. To write a sentence, the program repeats the same steps.
- Give the model the tokens so far.
- Get probabilities for the next token.
- Pick one token.
- Add it to the text. Go back to step 1.
The loop stops when the model picks a special "end" token, or when you hit a size limit.

Note Think of a
whileloop that appends to aStringBuilder. The model is the function you call inside the loop. Your app owns the loop, so your app decides when to stop.
Why this matters for an app
Three things follow from "a function in a loop".
- Speed is per token. Ten tokens means ten trips through the model. A long answer takes longer.
- The text can change between runs. Step 3 can pick differently each time. Lesson 5 shows how you control that.
- The model has a size limit. It can only look at a fixed number of tokens at once.
Check yourself
What does a language model return?
The model scores every possible next token. A separate step picks one, and a loop repeats this to build a sentence.
Who decides when the text generation loop stops?
The model only scores the next token. Your app runs the loop and sets the limits.
Recap
- A language model is a function: tokens in, next-token probabilities out.
- Text comes from a loop: score, pick, append, repeat.
- Next lesson: what a token is, and why token count decides speed and memory.