LearnBuild toward a chatbotChoosing the word
Choosing the word
Aim. At the end of this lesson one brainfuck program does the whole sum: it works out three scores, finds the highest and prints the word piece.
Where the lessons are going
You can make every number of the model (lesson 9). After its last layer a model has one number for each word piece it knows: a score. The piece with the highest score is the next piece of the answer. Finding the highest is the last part.
A race in place of a comparison
Try it: six word pieces, six scores. Go to the last step. Which piece does the program print?
What you just saw
The program cannot ask which score is highest. So it holds a race. All six scores get 1 added, in one loop, round after round. After each round the pointer slides along the row until it meets an empty cell: a score that has just gone round to zero (step 7 of lesson 1). The highest score gets there first.
To keep the race short, every score is first split into two digits (a peel: step 3 of lesson 5). The race is run on the first digit, and only the winners race again on the second.
Then the program prints the letters of the winner with the . command of step 6 of lesson 1.
The whole sum in one program
Try it: go to the last step. The tape holds only the four inputs 90, โ25, 40 and 12. What does the program print?
What you just saw
That was the whole sum, in one program of 45,360 characters. It multiplied and added (step 4 of lesson 3): 11,868 for " Paris". It divided, rounded and clamped (step 5 of lesson 5): 93, 41 and โ49. It held the race, and it printed " Paris".
The program has no comma in it. It reads nothing. Everything it knows about the three word pieces stands in its own text.
Other inputs, another word
Try it: change the inputs so that the same program prints " London". Go to the last step after each change:
| Input | Weight for " Paris" | Weight for " London" |
|---|
Hint
Compare the two columns of weights. Input 4 counts 100 times for " London" and only 14 times for " Paris". Make input 4 large.
What you just saw
The program did not change. Only the numbers on the tape did, and a different word came out.
That is what happens in a chat model. The weights are always the same. The inputs come from the word pieces of your question, by looking back (lesson 10). Other question, other inputs, other word.
The real thing
Try it: this is what the chat program does when you ask a question. Press the six stages, one after the other:
What you just saw
Each stage is a larger version of something you ran. The chat program does the same kind of work as your program of step 2, with far more of everything: 135 million weights where you had 12, 30 layers where you had one, 49,152 word pieces where you had three.
One word piece costs it 1.6 to 1.9 billion steps. In the browser that takes 0.6 to 1.0 seconds measured.
What you can do now
You have built a small version of every part that a program needs to work out a number of the model and to choose a word. The four obstacles were: only "is it zero?" (lesson 4), two numbers from the tape (lesson 6), no addresses (lesson 7), and size (lesson 8).
What is the capital of France?The capital of France is Paris.
How the real program differs
The race, measured. In the chat program, finding the highest of 512 scores took 119,000 to 595,000 steps with a simple countdown, and about 5,000 with this race. The 49,152 scores are handled in groups, and a "best so far" travels from group to group.
Equal scores. The slide stops at the first empty cell it meets. So when two scores are equal, the one that lies first on the tape wins. Try it in step 1.
Scores below zero. In step 2 the program adds 128 to each of the three results before the race, so that the scores run from 0 to 255. That is a choice of this lesson.
| The model | SmolLM2-135M-Instruct |
| Weights | about 135 million |
| Layers | 30 |
| Word pieces it knows | 49,152 |
| Program length | 1,030,902,380 characters |
| Input | your question, nothing else |
| Tape | 188,012,789 cells of 32 bits |
| Work for one word piece | 1.6 to 1.9 billion steps |
| Time for one word piece | about 0.6 to 1.0 seconds |
brnfck-qwen2.5-0.5b and brnfck-qwen2.5-1.5b. The site also runs Qwen2.5-0.5B-Instruct (about 494 million weights) and Qwen2.5-1.5B-Instruct (about 1.54 billion weights) as brainfuck programs, of 4,169,659,608 and 11,430,468,880 characters. They use the same tricks. brnfck-qwen2.5-0.5b runs in the browser at about 2.3 seconds for a word piece; brnfck-qwen2.5-1.5b runs from the command line at 7 to 12 seconds for a word piece, and ran in one desktop Chromium browser at about 9 seconds for a word piece (measured). Unlike brnfck-smollm2-135m, they get simple sums right.
brnfck-qwen3.5-0.8b. The site also runs Qwen3.5-0.8B (about 752 million weights, 24 layers) as a brainfuck program of 7,709,034,855 characters, on a tape of 1,067,424,772 cells. Only 6 of its layers look back at every earlier word piece. The other 18 are Gated DeltaNet layers: they keep a memory of a fixed size. The page Compare the models explains them. The program follows its whole-number recipe exactly, and that recipe picks the same next word piece as the original model at 95.1% of the positions tested. Ask it yourself on that page runs the model in floating point with its DeltaNet layers in whole numbers: close to the program, but not what it computes. brnfck-qwen3.5-0.8b runs in the browser at about 5.6 s for a word piece.
What "one brainfuck program" does not mean. The model was not made in brainfuck: it was trained in the usual way, and brainfuck only runs it. Its numbers were rounded to whole numbers first (step 2 of lesson 9). It needs a fast interpreter (step 3 of lesson 3) and cells of 32 bits (the note "Two honest notes" of lesson 5). And nobody typed a billion characters: a generator wrote them. These lessons build small versions of the parts; the chat program is far larger and was not written by hand. The full list is in How it works, under the question What does "pure brainfuck" mean, and what does it not mean? The question How do I know the program does what it says? on that page has a button that counts every character of the program in your browser.
Has this been done before? An earlier public project ran a neural network of 7 neurons in brainfuck, for the XOR function. A search for an earlier language model in brainfuck found none. The search was limited, so this is not a claim to be the first.