LearnBuild toward a chatbotObstacle 4: size

Obstacle 4: size

Aim. At the end of this lesson you know where 135 million weights go, why the program is a billion characters long and not 43 trillion, and how the program finds the end of a row of weights.

Where the lessons are going

Every piece of arithmetic works, anywhere on the tape. What is missing is the model itself: a very long list of numbers, the weights. In lesson 3 a weight was a row of plus signs in the program.

Eight weights, written by counting

Try it: go to the last step. The program writes eight weights onto the tape. Then look at how long it is:

This program is characters long: for each weight.

Figure 1. Eight weights written by counting. Look at the program text: one plus sign for every unit. (interactive)

The same weights, written with digits

Try it: press Play. Each cell gets a small number. Then one loop multiplies the whole row by five. Watch that happen three times:

Characters of programBy countingWith digits
These 8 weights
A row of 8,192 weights
Figure 2. The same eight weights written with digits. Watch the row move one cell to the left with each pass. (interactive)

Walk along the weights

Try it: press Play. Four weights lie on the tape and the input is 5. Watch the pointer walk along the weights and back, twice:

The weights are 100, −60, 30 and 14. To keep the example short they come in as typed input.

Figure 3. The engine walking along four weights. Watch the pointer cross the row once for each bit of the input that is on. (interactive)

Break the walk

Try it: every weight takes a number from −128 to 127. One of those numbers makes the engine go wrong. Find it:

Figure 4. Your weights, as they stand on the tape, and what the engine makes of them. A cross marks a wrong result. (interactive)

What you can do now

Put a long row of weights on the tape for a few characters each, and walk along it without knowing how long it is. The whole sum now works with weights from the tape. The fourth obstacle is gone.

All four obstacles are behind you. How do the parts go together into one number of the model?

How the real program differs

Step 2 is simplified. The real writer also uses digits below zero and other steps than five, and picks them for every row so that the text is as short as it can be. It reaches about six characters for each number. The loop that multiplies the row tests the cell it stands on, so no cell may be empty during the passes. Every cell therefore starts at 1 before the first digit is added.

Two parts. The chat program is 1,030,902,380 characters. The first 1,004,387,443 only write numbers onto the tape and read nothing. The engine after that is 26.5 million characters. Drawn to scale:

  • writes numbers onto the tape: 1,004,387,443
  • the engine: 26.5 million
The two parts. The characters of the chat program of brnfck-smollm2-135m, to scale.

Nearly all of the program only writes numbers. An earlier version had only the engine and read its weights as typed input, as step 3 does here: 355,761,802 bytes before your question.

The real walk. In the engine a walk costs two steps for each weight, and the row is not carried back each time: it goes to and fro between two places. The weights of the chat model are a little wider than those of this example, so they are put on the tape with 512 added, not 128.

What the first billion characters look like from the outside is shown in "A billion characters of numbers" in How it works.