Tokenwerk · The LLM textbook

Chapter 5 · I · Understanding neural networks · 5 minutes

From neurons to a small network

A single neuron can't do much. Connect a few of them and you have a neural network, a small version of what ChatGPT contains billions of times over.

One result becomes the next input

A neural network comes about very simply: the output of one neuron becomes the input of the next. Neurons that compute side by side at the same stage form a layer.

Our mini network: two inputs, two neurons in the middle, one neuron at the end. That's all. No words, no giant tables, but the whole principle is already in there.

The names of the layers

The input layer is the numbers that come in. Nothing is computed here yet. The hidden layer is the neurons in the middle; they compute intermediate results. The output layer is the neuron at the end; it delivers the prediction.

“Hidden” sounds mysterious, but it isn't. We can look at every number in it. It only means: the data gives no target for these intermediate values. We know what should go in and what should come out. What happens in the middle, the network has to figure out itself.

Worked through once, completely

The inputs are 2 and 1 again. In the middle sit two ReLU neurons. Both see the same inputs but have different weights. So they look at the same data in different ways.

Neuron First contribution Second contribution Bias Sum After ReLU
First inner neuron 2 × 1 = 2 1 × 1 = 1 −2 1 1
Second inner neuron 2 × (−1) = −2 1 × 2 = 2 +1 1 1

That both intermediate values are 1 is a coincidence. Change an input and they go their separate ways.

The output neuron takes the first intermediate value times 2 and the second times 3. Bias zero, no ReLU at the end:

Prediction = first intermediate value × 2 + second intermediate value × 3 = 1 × 2 + 1 × 3 = 5.

Congratulations: you just ran a complete neural network by hand.

What “forward” means

This path from the inputs to the output is called the forward pass. It only computes; nothing is learned. The weights stay as they are.

That is an important distinction. When you change an input in the experiment, the output changes, but the network learns nothing from it. A pocket calculator gives a different result for 3 + 4 than for 3 + 5 without getting any smarter.

How many parameters does this network have?

Let's count the dials. Each of the two middle neurons has two weights and one bias, that makes 3 + 3 = 6. The output neuron also has two weights and one bias, another 3. Together that is nine parameters.

The inputs and the intermediate values are not counted. They are created fresh for every example. The intermediate values are called activations.

When you hear that a model has “7 billion parameters”, this is exactly what is meant: 7 billion dials like these. Same way of counting, just a few more zeros.

Width and depth

Width means how many neurons stand side by side in a layer. Our middle layer has width two. Depth means how many layers come one after another.

Wider means more intermediate calculations at the same time, deeper means more processing stages in a row. Sounds like “more is better”, but it doesn't happen by itself: data and training have to play along. (Exactly which layers get counted, by the way, isn't consistent everywhere.)

What do the neurons in the middle “think”?

A tempting idea: one neuron handles grammar, one handles cats, one handles the weather. In reality we haven't assigned the neurons any tasks. For now they are just calculation paths. Useful patterns can develop during training, but not necessarily one per neuron, and certainly not with a neat name tag.

The abilities live in the interplay. That is why it is so hard to watch a large model “think”: you see billions of numbers but no labels.

The next question

Suppose the answer should really be 6. Our network says 5. Close, but how close exactly? And how do we turn that into a signal for learning? For that we need an error measure, a number that says how far off the network is. That comes in the next chapter.

Key points

  • A network consists of layers of neurons. Each layer passes its results on to the next.
  • The forward pass only computes; it doesn't learn.
  • Counting parameters means counting weights and biases: 9 for us, billions in large models.