Tokenwerk · The LLM textbook

Chapter 3 · I · Understanding neural networks · 5 minutes

An artificial neuron you can compute by hand

The neuron is the basic building block of every neural network, ChatGPT included. And all it can really do is multiply and add.

What is an artificial neuron?

The name sounds like brains, but don't worry: you need zero biology. An artificial neuron is a tiny calculating machine. A few numbers go in, one number comes out. The idea was loosely inspired by nerve cells; there is not much more resemblance than that.

Picture a mixing desk. Several channels come in, each with its own volume fader, and the desk mixes everything into one signal. A neuron does exactly that. Every input has its own fader, the weight. It decides how much the input counts. All the weighted inputs are added up. Finally a fixed base value is added, the bias.

Many neurons then apply a small extra rule, the activation function. That comes in the next chapter. Here it is only about mixing.

An example to calculate along

Two inputs: 2 and 1. The first weight is 1, the second −1. The bias is 0.5. The numbers are deliberately small and have no deeper meaning. We just want to see how the calculation goes.

Step Calculation Result
First contribution First input × first weight 2 × 1 = 2
Second contribution Second input × second weight 1 × (−1) = −1
Add contributions 2 + (−1) 1
Add bias 1 + 0.5 1.5

Result: 1.5. That was your first neuron calculation!

Did you notice the negative weight? It does not mean “bad”. It means: the larger this input, the more it pulls the sum down. Sometimes that is exactly what is useful, for example when a signal speaks against something.

Weights: strength and direction

Move the first fader: weight from 1 to 2. The first contribution doubles, 4 instead of 2. The sum becomes 4 − 1 + 0.5 = 3.5. The neuron now listens more closely to the first input.

Weight 0 means: this input is ignored. Weight −2 means: it counts a lot, but the other way around. So remember weights as the strength and direction of an influence.

Why add a bias?

Set both inputs to zero. Without a bias, the result would always be zero no matter how the weights are set; zero times anything stays zero. With bias 0.5 the sum starts at 0.5. So the bias shifts the starting point.

An everyday picture: a taxi ride costs a base fare plus a price per mile. The price per mile is like a weight, the base fare like the bias. (A neuron obviously doesn't calculate taxi fares. The picture is only there to make the calculation tangible.)

Weights and bias are both parameters, so they are the dials from the last chapter that training sets. Inputs are not parameters. They come in fresh from outside each time, for example from the data.

The same calculation with short names

Once you have more than two inputs, you quickly get tired of writing “first input times first weight”. That is why the numbers get short names:

Symbol Read it as Value here
x1x_1 first input 2
x2x_2 second input 1
w1w_1 weight of the first input 1
w2w_2 weight of the second input −1
bb bias, the base shift 0.5
zz result before the activation function 1.5

The small lowered number is a house number, not a power: x2x_2 means “the second input”, not “x squared”.

With that, the whole table above shrinks to a single line:

z=x1w1+x2w2+b.z=x_1w_1+x_2w_2+b.

Read the formula: first input times its weight, plus second input times its weight, plus bias. Two letters written right next to each other mean “times”.

With numbers: 2 × 1 + 1 × (−1) + 0.5 = 1.5. Same calculation, just in shorthand.

One neuron, many examples

The same neuron computes with all sorts of different inputs, one after the other. Its weights and its bias stay the same. Training looks for a setting that fits as many examples as possible well, not just one.

What this has to do with ChatGPT

A large language model consists of billions of weights like these. They are arranged differently than in our mini neuron, but the basic calculation “inputs times weights, add up, plus bias” is everywhere. If you can redo the table above, you know the most common calculation in a language model.

Key points

  • A neuron multiplies each input by its weight, adds everything up and adds the bias.
  • Weights set the strength and direction of an influence. The bias shifts the starting point.
  • Weights and bias are parameters and get trained. Inputs don't.