← The working tiny model

Part two · beyond counting

Keep the loop. Improve the prediction.

The tiny model works. Now change the task, expose its limits, and see which new idea helps with each problem.

  1. 01A memory problem
  2. 02Remember more
  3. 03Missing combinations
  4. 04Share a calculation
  5. 05Vectors & embeddings
  6. 06From recipe to scores
  7. 07Learn the numbers
  8. 08Preserve order
  9. 09Use relevant context
  10. 10Put the pieces together
  11. 11The same generation loop
01

The last character hides the difference.

Part One could finish cat, car, and can. Now we extend its training examples into three sentences. When the prompt ends in “is ”, the last character is a space in every case. Our tiny model looks up the same row and makes the same prediction, even though the earlier subject differs.

New example
the cat is sleeping
New example
the car is moving
New example
the can is empty
This is a new training collection, not knowledge contained in the original ten words. We still use character tokens. The experiment below counts real transitions from these three sentences.

First, try giving the count model more memory.

02

Look up several previous characters instead of one.

Instead of a row for “ ”, use a row for the last three characters, “is ”. That is still the same for all three prompts. Eight characters retain the subject and can distinguish “ cat is ”, “ car is ”, and “ can is ”. Move the context control below and watch which earlier characters remain visible.

One character
“ ” → subject forgotten
Three characters
“is ” → still ambiguous
Eight characters
“ cat is ” → subject retained
More context solves this distinction in the training collection. It does not automatically solve unfamiliar text.

A longer lookup has a catch: what if that exact context never appeared?

What can the count model remember?

Trained on the three sentences above, once each. Spaces count as characters.

the cat is␠

Faded: forgotten · Highlighted: used for lookup · ␠ = space

Enable JavaScript to compare the observed next-character counts for each context.
03

An exact lookup can have no answer.

Choose “the cab is ” in the experiment. Its eight-character context was never observed, so there is no row to look up. A shorter context can provide a fallback, and adding small counts can avoid zero probabilities. Those are useful count-model improvements—but neither creates an understanding of the new subject.

Seen context
“ cat is ” → observed continuation
Unseen context
“ cab is ” → no eight-character row
An unseen row is different from a low-probability outcome in an existing row. Neural models can also fail on unfamiliar inputs; they do not create missing knowledge for free.

Can we reuse pieces of what we learned, rather than demand a separate row for every full context?

04

Separate rows cannot share what they learn.

Longer contexts create many possible combinations. A counting table stores the observed combinations separately. A neural model instead uses a shared calculation whose adjustable numbers are reused for many inputs. This can help generalization; it is a different approach, not a requirement for our original tiny task.

Count approach
exact context → its own count row
Learned approach
input representation → shared calculation → scores
With V tokens there are Vᵏ possible contexts of length k. A sparse table stores only observed ones, but then many combinations remain missing.

A shared calculation needs an input representation with adjustable values, rather than just an arbitrary token label.

05

Store a small recipe for each token.

Give every character an ID to locate it in a table. Its row contains several adjustable numbers: a vector. When that row represents a token, it is called an embedding. The entries tell later calculations how strongly to use different shared patterns. The ID finds the row; the embedding supplies values to calculate with.

Tokena
ID selects a row1
Embedding · adjustable settings
0.75pattern A0.25pattern B
Token ID
a → row 1
Embedding stored in row 1
[0.75, 0.25]
Meaning in our toy calculation
amount of pattern A; amount of pattern B
A and B below are deliberately simple scoring patterns. In a real model their meanings are not hand-assigned; embeddings and shared calculations learn together. These entries are not probabilities.

Let’s make the recipe do something visible, using the same t/r/n choices from Part One.

06

A weight multiplies a contribution.

A weight is an adjustable multiplier: 2 doubles a number, 0 removes its contribution, and a negative value reverses its sign. Use the embedding [0.75, 0.25] to multiply two shared patterns, then add. This gives a score for each possible next character. Higher scores express stronger preference, not percentages.

One recipe → three output scores
Contributiontrn
0.75 × A1.500.750
0.25 × B00.250.50
Add ↓1.501.000.50
Shared pattern A, for [t, r, n]
[2, 1, 0]
Shared pattern B, for [t, r, n]
[0, 1, 2]
Apply the recipe
0.75 × A + 0.25 × B = [1.5, 1.0, 0.5]
This is a toy output calculation, not a trained sentence model. A full model scores every token in its vocabulary. Grouping these multiply-and-add calculations into a table is matrix multiplication.

These predictions only become useful when the recipe and patterns are adjusted using real examples.

07

Replace invented settings with practice.

Softmax converts scores into probabilities. Loss measures how little probability the model assigned to the observed next token. Gradients tell us how a small change to each adjustable number would affect that loss; backpropagation computes them through the calculation. An optimizer then takes a small update step. Repeat this across examples to train the embeddings and weights together.

Compare prediction with observed proportions

t
Prediction 50.6%Observed 60%
r
Prediction 30.7%Observed 30%
n
Prediction 18.6%Observed 10%
Our invented scores
[1.5, 1.0, 0.5]
Softmax probabilities, rounded
[50.6%, 30.7%, 18.6%]
Original observed proportions
[60%, 30%, 10%]
The numbers above illustrate the starting mismatch; this page does not run neural training. Softmax uses exponentials and normalization. Repeated examples guide the probabilities; no single update is guaranteed to improve every example.

Token embeddings can now be useful inputs. For longer text, we still need to preserve order and combine context.

08

A bag of token vectors loses the sentence.

The words cat and act contain the same characters. Looking up their embeddings gives the same three rows in different orders. If we simply add the rows, the result is identical. Position information lets later calculations distinguish where each token occurred.

position 1cposition 2aposition 3t
position 1aposition 2cposition 3t

Same characters. Different positions.

cat
c at 1 · a at 2 · t at 3
act
a at 1 · c at 2 · t at 3
There are several ways to supply position information. The purpose is to distinguish order; it does not by itself decide which information matters.

Now the model can combine information from different positions without treating every position identically.

09

Calculate a different mixture for each context.

Attention compares the current representation with available positions and turns comparison scores into mixing shares. It combines their information using those shares. Unlike a fixed lookup row, this mixture depends on the input. To complete “the cat is ”, the model can use information from the earlier subject as well as the final space.

Toy mixture · invented values

25%[1, 0]+75%[0, 1]=Combined[0.25, 0.75]

earlier positions → current positionfuture positions: hidden

Context available
the cat is
Attention operation
compare → assign shares → combine vectors
The diagram uses invented shares and simplified vectors, not learned explanations for the sentence. Future positions must be masked during training so the model cannot read the answer ahead. Attention alone is not a complete transformer.

The context-dependent result feeds later transformations and the output-score calculation.

10

Attention needs a surrounding prediction model.

A small decoder-only transformer combines token representations and position information with causal attention and a feedforward network. The feedforward network applies learned transformations and a nonlinear rule, allowing more than one linear remix. Residual connections carry an earlier representation forward; normalization helps control numerical scales. These blocks produce a vector used to score next tokens.

Token IDs↓Embeddings + positions↓
Causal attention↓Feedforward networkResidual paths + normalization
↓Output scores → probabilities
Input
character IDs → embeddings + position information
Transformer block
causal attention → feedforward transformation
Output
context vector → scores → probabilities
This is the assembly map, not a full implementation tutorial. Residual connections and normalization belong around the block operations. Every added component must be trained; adding it does not automatically improve quality.

Once trained, generation is still the same loop you already understand.

11

Only the prediction machinery has changed.

Part One looked up a count row. The neural version calculates probabilities from a learned representation of the context. Both choose a token, append it, and repeat until END or a length limit. During generation, the learned weights stay fixed. Evaluate on held-out text to check whether the extra machinery actually helped.

Count tableNeural calculation

↘ Probabilities ↙

Choose → append → repeat → END
Part One
previous token → count row → probabilities
Neural model
available context → learned calculation → probabilities
Both
sample → append → repeat → stop
The neural model can still generate incorrect or meaningless text. More context and shared representations offer capacity; sufficient data, training, and evaluation determine whether that capacity is useful.

Return to the tiny model whenever you want to see the complete generation loop without the extra machinery.