AI principles · Chapter 2 of 8
How a model writes
A language model writes one token at a time by drawing from a list of chances, temperature changes how it draws, and nothing in that step checks whether the words are true.
Goals
- Read the chances for a prompt and let the model take the likeliest word.To do
- Pick the next five words yourself.To do
- Write at a low and a high temperature and watch the text drift.To do
- Pass the check.To do
Step 1 of 4: The read
One piece at a time
In the last chapter a classifier learned from examples to sort points into kinds. A language model, the kind of AI behind chat assistants, learned from a vast amount of text to do one thing: given some text, say what is likely to come next. It writes by repeating that step. It works out a chance for every possible next piece, picks one, adds it to the text and starts again.
Tokens and chances
The pieces are called tokens. A token is a short piece of text: a word, part of a word or a punctuation mark. A chance is a number from 0% to 100%, and the chances of all possible next tokens add up to 100%. After “The café opens at 8 in the”, the token “morning” gets a high chance and “moon” a tiny one. The text you start from is called the prompt.
Temperature
The model draws the next token at random, weighted by the chances, so likely tokens come up most often. Temperature is a setting that reshapes the chances before the draw. Near 0, the likeliest token nearly always wins, and the same prompt gives nearly the same text each time. Higher up, unlikely tokens get picked more often: the text varies more and, past a point, drifts into nonsense.
Fluent is not the same as true
Every token is picked because it is likely to come next, not because it is true. Nothing in this step checks a fact. A model can write a smooth sentence with a wrong date, price or name, and a low temperature does not fix that: it only picks the likeliest words. Checking what it writes stays your job, and a later chapter shows how.
The model in this page
The explorer below runs a tiny model that your browser trains when the page opens, on ten of Aesop's fables. Its tokens are whole words and punctuation marks. It looks only at the last two and counts what came after them in the fables. The models behind chat assistants use tokens that can be parts of words, take in far more of the text and have billions of parameters, the numbers they adjust while learning. The choosing step works the same way.
Step 2 of 4: Try it: Next-word explorer
Next-word explorer
Read the chances for a prompt, pick words yourself, then move the temperature and watch the text drift.
Mode:RealReal: your browser trains the word model on ten of Aesop's fables when the page opens, and every chance and every pick is computed live. It is far smaller than the models behind chat assistants.
Step 3 of 4: Check
Check
Next: Question 2 of 3
Step 4 of 4: What you can do now
What you can do now
- Explain that a language model writes one token at a time, drawing each from chances.
- Say what temperature changes, and what it does not.
- Explain why a smooth, confident answer can still be wrong.