5. Roll the dice
First, two things from lesson 4.
The counts in the table are the program’s…
After “the”, the program from lesson 4 says…
Same answer every time
Ask that program to write a sentence starting with “The”, and you get “The cat sat on the cat sat on the cat…”. Every time.
| word | what came next |
|---|---|
| the | cat ×2rug ×1sofa ×1dog ×1mat ×1 |
| cat | sat ×2 |
| sat | on ×3 |
| on | the ×3 |
| dog | sat ×1 |
The program picks the bold word in each row. Follow the → cat → sat → on → the. Back at the, it picks cat again.
Ask ChatGPT the same question in two fresh chats. The answers can differ. How?
Make a die for each row. Here are two. In the the row, cat ×2 puts cat on two faces.
from random import choice
dice = {
"the": ["cat", "cat", "rug", "sofa", "dog", "mat"],
"cat": ["sat", "sat"],
}
last_word = "the"
die = dice[last_word]
next_word = choice(die)The last word selects the die. choice picks one face at random, each with the same chance. If the last word is cat, both faces say sat.
Try the die for the below. Click Roll, then Roll 60 times.
Faces of the die
Not rolled yet.
| word | times rolled |
|---|---|
| cat | 0 |
| rug | 0 |
| sofa | 0 |
| dog | 0 |
| mat | 0 |
| all rolls | 0 |
Look at the six faces. What’s the chance of rolling cat on the next roll?
What just happened
A probability is a chance written as a number. For cat after the, divide the count for cat by the total in the the row. That’s 2 / 6.
Picking a word at random using those chances is sampling.
Write a sentence
Start with The cat. Roll the die for cat and add what comes up. Repeat with the new last word. Stop when there’s no die to roll.
After cat, the text had sat twice. So both faces of the die for cat say sat.
Click Write a sentence until you see ★ new.
Training text
- The cat sat on the rug.
- The cat sat on the sofa.
- The dog sat on the mat.
All attempts
Can the program write a sentence that wasn’t in the text?
What just happened
- Each last word has its own counts. Sampling from those counts lets the program write sentences it never saw.
- An LLM uses probabilities to sample its next piece of text. That’s how the same question can get different answers.