# Under the hood

> A follow-on for groups who've built the paper model and want to know what a real one does differently. Complete a pattern the model never trained on, and measure how close two words are by hand.

Once a room has built a <GlossaryTerm id="bigram-model">bigram model</GlossaryTerm> and rolled dice through it, someone
usually asks how <GlossaryTerm id="chatbot">ChatGPT</GlossaryTerm> holds a conversation when this paper model only ever
looks at the previous word. Real models differ in three ways: they look at more
than one word of <GlossaryTerm id="context-window">context</GlossaryTerm>, they can complete patterns they never saw in
training, and they are trained to answer questions as well as continue text.

This lesson runs the first two by hand. Participants build the grid model as
usual, add two rules that read back over the page they've already written
(<GlossaryTerm id="in-context-learning">in-context learning</GlossaryTerm>), and turn each word's row of counts into a vector to
measure how close two words are (word <GlossaryTerm id="embedding">embeddings</GlossaryTerm>). Everything uses counting
and subtraction, giving concrete mechanics to <GlossaryTerm id="attention-mechanism">attention</GlossaryTerm> and <GlossaryTerm id="embedding">embedding</GlossaryTerm>.

## Run of show

| Section                                                         | Time   |
| --------------------------------------------------------------- | ------ |
| Icebreaker and intro                                            | 10 min |
| [Training](https://www.llmsunplugged.org/modules/training/)                                  | 20 min |
| [Generation](https://www.llmsunplugged.org/modules/generation/)                              | 20 min |
| [Pre-trained Model Generation](https://www.llmsunplugged.org/modules/pretrained-generation/) | 15 min |
| _Break_                                                         | 10 min |
| [In-context Learning](https://www.llmsunplugged.org/modules/in-context-learning/)            | 25 min |
| [Word Embeddings](https://www.llmsunplugged.org/modules/word-embeddings/)                    | 20 min |
| Close: scaling up                                               | 10 min |

That's two hours and ten minutes. If your slot is a hard two hours, run the
pre-trained booklet round at 10 minutes or shorten the break; don't take the
time out of in-context learning.

There's no deck for this lesson. Run it straight from the module pages: each one
has the goal, the algorithm, a worked example and instructor notes, and the two
in the back half carry the widgets you'll want on the projector.

## How it goes

The first hour is the fundamentals, and it's the same first hour as
[My First Language Model](https://www.llmsunplugged.org/lessons/my-first-language-model/): tally word pairs
into the <GlossaryTerm id="grid">grid</GlossaryTerm>, then roll a d10 to generate text from your own counts. If your
group has already done that, you can compress it hard; 20 minutes of rebuild is
usually enough to get everyone's hands back in. Don't skip it, though, because
the back half needs a filled-in grid to work on.

The pre-trained <GlossaryTerm id="booklet">booklet</GlossaryTerm> round is here for a practical reason as well as a
conceptual one. The in-context rules only bite when the model has a decent
vocabulary behind it, and a booklet trained on a whole book gives a much better
demo than a grid built from two pages. Hand out booklets, let people generate a
few sentences, and keep them on the table for the next section.

**In-context learning** starts with a two-minute demonstration: write a short
pattern on the board and ask the room what comes next. The model has never seen
that pattern, so they find the answer by scanning back up the page (the
induction rule). Then add the memory rule, which softly favours words used
recently, and generate again with both rules running. The output stays on topic
in a way the plain bigram never manages, and nobody has changed a single count.

**Word embeddings** treats each word's row in the grid as a vector: two words
with similar rows behave similarly. Run the twins activity (find two words whose
rows look alike), then the swap test (substitute one for the other in generated
text and see whether anyone notices), then put the Embedding widget on the
projector and let the room argue with the numbers.

The close is the scaling-up conversation: what changes when the grid has fifty
thousand words instead of forty, when the context is thousands of words instead
of one, and when the rules you just ran by hand are learned during training.

## You will need

For each pair or small group:

- a printed [grid template](https://pdf.llmsunplugged.org/worksheets/grid.pdf)
  (or grid paper), plus a second blank one for the embedding distances
- a d10 die
- pens, and plenty of paper; the in-context rules mean reading back over what's
  already been generated, so keep it legible
- some training text: a few pages of any book works
- a pre-trained booklet from the
  [Materials](https://www.llmsunplugged.org/tools/#booklets-for-dice-generation) page, or
  [generate your own](https://www.llmsunplugged.org/tools/#generate-your-own)

Plus a laptop and projector for the Embedding widget on the
[Word Embeddings](https://www.llmsunplugged.org/modules/word-embeddings/) page.

## Before you deliver

- print the grids (two per group) and the booklets, and check the booklets are
  bound or stapled the right way round; people flip through them a lot in this
  lesson
- have your induction demo ready: a three-word pattern the room can complete
  instantly, planted so the current word appears earlier in the generated text
- work the memory rule once yourself on a real booklet before the session. It's
  simple, but explaining it cold is harder than it looks
- open the Embedding widget on the room's computer beforehand and check it
  renders on the projector; the numbers are small
- if you have extra time, [More Context](https://www.llmsunplugged.org/modules/more-context/) (30 min) slots
  in after generation and pairs well with in-context learning: the trigram shows
  what a bigger context window costs, right before the two rules show how to get
  context by reading back over the page

## Where to go next

[Shaping a model](https://www.llmsunplugged.org/lessons/shaping-a-model/) is the companion follow-on,
covering the third difference: how training data, adapters and human feedback
turn a text predictor into an assistant, and the design choices involved. Groups
that want to see a model call tools as well as generate text can add
[Agentic AI](https://www.llmsunplugged.org/modules/agentic-ai/). For a room too big for tables and dice,
[Search Sheets](https://www.llmsunplugged.org/modules/search-sheets/) runs the core activity from the front.

Source: <https://www.llmsunplugged.org/lessons/under-the-hood/>\
Licence: [CC-BY-SA-4.0](https://creativecommons.org/licenses/by-sa/4.0/)\
Cite as: Swift, B. (2026). _LLMs Unplugged: Understand how AI language models work by building one yourself._ https://doi.org/10.5281/zenodo.17403824
