← AI Foundations

Build a text generator with dice

Turn word frequencies into dice outcomes, then sample words without always picking the most common one.

Last lesson, we counted six endings: mat, mat, mat, chair, chair, roof. Now we will use a six-sided die to choose one of those endings.

This is a toy probabilistic text generator, not a miniature LLM. You can do it with paper and a physical die.

How this lesson works: Engage, Explore, Explain, Elaborate, Evaluate
EngageCommit to a prediction before you test anything. A wrong guess is fine: it shows you what to look for.

Engage: Is the most likely outcome certain?

If three faces on a die mean 'mat', two mean 'chair' and one means 'roof', what happens when you roll?

ExploreTry it on the board and compare what happens with your prediction.

Explore: Build the lookup table

Which assignment matches the counts mat = 3, chair = 2, roof = 1?

ExploreTry it on the board and compare what happens with your prediction.

Explore: Roll the die

Use the interactive board to roll a virtual die and record your outcomes. You can also use a physical die and compare the results.

Copy this table into your book:

Die result Next word
1, 2, 3 mat
4, 5 chair
6 roof

Roll a die ten times, recording each result and the chosen word. Use the board's virtual die if you do not have a physical die: it shows each roll, such as Rolled 4 → chair, and your last ten rolls. Keep the lookup table unchanged.

Compare with a partner. Did you get identical results? Does a short run always match the expected 3:2:1 ratio?

Try it yourselfYour edits are saved in this browser.

Roll the virtual die at least ten times.

Use the board. This ticks when you get there.

ExplainPut a name to what you saw, and why it works.

Explain: Sampling

Count how many faces select chair out of six.

Consider why ten rolls might contain no roof outcomes.

Connect probabilities with the different results of repeated rolls.

Choosing an outcome according to its assigned probability is called sampling. A model can use sampling instead of always selecting the single most frequent word.

A generator that always picks the top word would write "mat" every single time. Rolling lets it write "chair" or "roof" sometimes. This is one reason a chatbot can give different answers to the same question.

Our model only chooses one word after one fixed phrase. A larger word-transition model would use the newly chosen word to look up another set of possible next words. That is still far simpler than a modern LLM.

What is the chance of getting 'chair' on one roll?

You and a friend each roll the board's die 10 times. Your friend gets roof 3 times. You get roof 0 times. What is true?

ElaborateUse the idea in a new situation.

Elaborate: Change the model

Make a new lookup table and roll five times. Explain what changed: the die, the sampling procedure or the model's examples?

A new collection has 2 mat, 3 chair and 1 roof. Which assignment matches it?

EvaluateLook back at your first ideas and what changed.

Evaluate: Explain an unexpected outcome

Write one sentence distinguishing probability from what actually happened in your rolls.

Your model produces 'roof' twice in a row. What is the chance of roof on the next roll?

ExplainPut a name to what you saw, and why it works.

Learning with AI: plausible is not the same as correct

A writing assistant produces “The cat sat on the roof.” The sentence is plausible, but that does not tell us whether a real cat sat there. Compare two prepared AI responses to a learner asking, “Is this sentence true?”

Which response better distinguishes generation from verification? What evidence would you need to establish whether the event happened?

Next: let a computer repeat this same sampling procedure, and decide what understanding you must keep.

The generator writes 'The cat sat on the roof.' What would tell you whether a real cat sat on a roof?

Now you can
Next lesson3. Let the computer take overCompare manual and automated sampling, and decide which work can be delegated without losing understanding.
For teachers

Map six equally likely die faces to endings and distinguish probabilities from observed rolls. About 25 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Use the board as a transparent fixed-context model, not a miniature modern LLM. No AI account is required. The Explain it to me clip is an optional scaffold after prediction. The board shows each roll ("Rolled 4 → chair") and the last ten, so students can match its die to their own table. Model the difference between what a text generator produces and what evidence supports. The dice model illustrates sampling, not how a modern assistant checks facts. Students need not calculate formal probabilities to make this distinction.

Running the lesson

  1. Engage: have students predict ten rolls before sampling.
  2. Explore: compare results with a partner; short runs differ.
  3. Explain: the optional line on always picking the top word links sampling to chatbots giving different answers.

The hard part (on purpose)

Students may think a streak changes the odds, or that ten rolls must give five mats.

When students get stuck

Stretch and support

Stretch: Explain where the toy model differs from a modern AI assistant.

Support: Use the prepared examples, read the explanation aloud and repeat a small trial.

Where it leads

Unit 1, lesson 3 lets the computer repeat the same rolls thousands of times.