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?

Figure 1. Six scores and the race between them. Watch the line "Printed so far" at the end. (interactive)

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?

Figure 2. One program for the whole sum. The table underneath fills in with the three scores it worked out. (interactive)

Other inputs, another word

Try it: change the inputs so that the same program prints " London". Go to the last step after each change:

InputWeight for " Paris"Weight for " London"
Figure 3. The same program with inputs you choose. Compare the two columns of weights before you move a slider. (interactive)

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:

Figure 4. The six stages of the chat program. Each one names the lesson in which you built it. (interactive)

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.

That is the route of one answer. Inside the program takes the real program apart, the program map shows every character of it, and the chat page lets you ask it a question of your own.

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.

Table 1. The chat program of brnfck-smollm2-135m in numbers (counted in the program file; times measured on one desktop computer).
The modelSmolLM2-135M-Instruct
Weightsabout 135 million
Layers30
Word pieces it knows49,152
Program length1,030,902,380 characters
Inputyour question, nothing else
Tape188,012,789 cells of 32 bits
Work for one word piece1.6 to 1.9 billion steps
Time for one word pieceabout 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.