LLM Kitchen
Explanations

Part III · Learning

Ch 6. A neuron

What a model is made of

So far, text goes in as tokens, each token becomes a list of numbers, and out comes a chance for every possible next token. A language model is the calculation in between. This Part asks what that calculation is made of (this chapter) and where its numbers come from (the next one).

The counting model in Ch 1 looked its answer up in a table. A large language model works it out instead, by passing the numbers through millions of tiny calculators called .

The pieces so far fit together like this. Text is split into tokens (Ch 4), each token becomes a vector, a list of numbers (Ch 5), and at the other end the model gives a chance for every possible next token (Ch 2). A language model is the calculation in between: numbers in, chances out. This Part answers two questions about it. What is the calculation made of? That’s this chapter. And where do its numbers come from? That’s the next.

The counting model in Ch 1 computed almost nothing: it looked its answer up in a table of counts. A large language model computes its answer instead, by passing the numbers through millions of tiny calculators called .

One neuron

Each neuron is simple enough to work out by hand. This one has two inputs so you can follow every number; a neuron in GPT-2 reads 768. Move the sliders and watch the numbers flow.

Try it

One neuron

Computed in your browser
1.00× 0.800.50× −1.20+ bias 0.30sum0.50output0.50
outputsum

Multiply, add, squash

A neuron does three things. It multiplies each input by its own , which says how much that input matters. It adds the results up, plus one extra number called the bias. Then it squashes the total: a common squash, ReLU, turns anything below 0 into 0.

Think of it as a vote. Each input pushes the total up or down, as hard as its weight says, and the neuron only passes a signal on when the total comes out above 0.

A neuron does three things:

  1. Multiply each input by its own . A big weight means “this input matters a lot”; a negative weight (dashed wire) means “this input pushes the other way”.
  2. Add the results together, plus one more number called the bias, which shifts the total up or down.
  3. Squash the total with an activation function. ReLU, for example, turns any negative total into 0 and leaves positive totals alone. Without this step, stacking neurons would only ever produce straight lines, however many you used.

So a neuron is a small detector. The weights decide which mix of inputs it looks for, the bias how much of that mix it needs, and the squash makes it stay quiet until it has enough: with ReLU, it outputs 0 below that point and a bigger number the further past it the inputs go.

The idea is old. Warren McCulloch and Walter Pitts described a mathematical neuron in 1943,[1][1] loosely inspired by brain cells, and Frank Rosenblatt’s perceptron of 1958 added weights that could be adjusted from examples.[2][2] Real brain cells are far more complicated; the name stuck anyway.

The neuron as a formula

With inputs x1,…,xn, weights w1,…,wn, bias b, and activation function f, a neuron outputs

y=f(∑i=1nwixi+b),ReLU⁡(z)=max⁡(0,z)

A whole layer is the same thing for every neuron at once: h=f(Wx+b), where row j of the matrix W holds neuron j’s weights and b is now a list of biases. That’s why models are run as matrix multiplications.

The squash is what makes layers worth stacking. Without it, two layers collapse into one:

W2(W1x+b1)+b2=(W2W1)x+(W2b1+b2)

which is a single layer with weights W2W1 and bias W2b1+b2: still a straight line, or a flat plane, however many layers you stack.

Many neurons make a network

One neuron answers one yes-or-no question about its inputs, so on a map of them it can only draw one straight edge: on one side it fires, on the other it stays quiet. Many neurons side by side make a layer, and a next layer can combine their answers into complicated shapes. Below, three neurons and one output neuron fence off a triangle. Turn neurons off to see what fewer can do:

One neuron answers one question about its inputs: is this mix of them big enough? On a map of the inputs, the answer changes along a straight line. It fires on one side and stays quiet on the other. The power comes from numbers: put many neurons side by side in a layer, feed their outputs into the next layer, and the network can pick out complicated regions.

Below, a layer of three neurons reads the same two inputs. Each one draws its own straight line and fires only on the far side of it. A second layer, here a single output neuron, adds up what they say with negative weights, so it stays above 0 only where none of them fire: inside a triangle. Turn neurons off to see what fewer can do. One gives a single straight edge, two a wedge. Try it:

Try it

A layer of neurons

Computed in your browser
0.501.000.2010.0020.003× −3.000.40output
123
Neurons in the layer

Click or drag in the square, or move the sliders, to change the inputs. The square's shading shows the output for every pair of inputs from −2 to 2, and the dashed lines are where each neuron starts to fire.

A token’s vector has 768 numbers rather than 2, so GPT-2’s neurons pick out regions in a space with 768 directions. Nobody can draw that, but each neuron still works just like the ones above.

Two inputs give a flat square you can draw. A neuron in GPT-2 reads 768 numbers, so it splits a space with 768 directions instead, and the next layer combines thousands of those splits. Nobody can draw that, but each neuron still multiplies, adds, and squashes like the ones above.

Where neurons sit in a model

GPT-2 small is built from 12 blocks, one after another. In each block, a part called attention lets each token take in what came before it (Ch 9), and then a layer of 3,072 neurons works on each token’s vector. After the last block, the vector becomes a chance for every next token.

Here is the whole path through GPT-2 small, with the parts this course has covered and the ones still to come:

  1. Each token becomes a vector of 768 numbers (Ch 5).
  2. The vectors pass through 12 blocks, one after another. In each block, attention lets every token take in information from the tokens before it (Ch 9), and then a layer of 3,072 neurons works on each token’s vector on its own.[3][3] The two together make a transformer block (Ch 10).
  3. After the last block, each token’s vector is turned into a chance for every possible next token.

Its neurons use GELU, a smooth cousin of ReLU, as their squash.[4][4]

In each block, GPT-2’s neurons form two layers, a part called the MLP:

MLP⁡(x)=W2GELU⁡(W1x+b1)+b2

where x is a token’s 768 numbers, W1 (3,072 × 768) and b1 feed the 3,072 neurons, and W2 (768 × 3,072) and b2 turn their outputs back into 768 numbers.[3] That’s 4,722,432 weights and biases per block, and 56,669,184 across the 12 blocks: about 46% of the whole model. GELU is GELU⁡(z)=zΦ(z), where Φ(z) is the chance that a standard normal random number is below z. GPT-2 uses a faster approximation of it:

GELU⁡(z)≈12z(1+tanh⁡(2/π(z+0.044715z3)))

which matches the exact curve to within about 0.001 everywhere.[4]

Who sets the weights?

Every one of those neurons has weights, numbers like the ones on your sliders. So does the rest of the model: the token vectors are numbers too. Above, someone chose the triangle’s weights by hand. Nobody could do that for millions of them.

Every one of those neurons has its own weights and bias, numbers like the ones on your sliders. So does the rest of the model: the token vectors from Ch 5 are numbers too, and so is attention. GPT-2 small has about 124 million in all. The triangle’s weights above were picked by hand to make a triangle. Nobody could pick 124 million, and nobody knows in advance which patterns a language model needs its neurons to pick out.

Recipe card

Recap

  • A language model is a calculation from token vectors to a chance for every next token, and much of that calculation is done by neurons.
  • A neuron multiplies each input by a weight, adds them up with a bias, and squashes the result.
  • Weights say how much each input matters, and in which direction.
  • Layers of many neurons, stacked, can pick out complicated patterns. GPT-2 small has a layer of 3,072 in each of its 12 blocks, after attention.
  • A layer computes f(Wx+b), one row of W per neuron; without f, stacked layers collapse into one.

Next question: nobody set GPT-2’s 124 million numbers by hand. So how were they chosen?

Sources

  1. Warren S. McCulloch and Walter Pitts (1943). A Logical Calculus of the Ideas Immanent in Nervous Activity. Bulletin of Mathematical Biophysics 5.
  2. Frank Rosenblatt (1958). The Perceptron: A Probabilistic Model for Information Storage and Organization in the Brain. Psychological Review 65(6).
  3. OpenAI and Hugging Face (2019). GPT-2 small configuration (config.json). Hugging Face. Accessed October 23, 2026.
  4. Dan Hendrycks and Kevin Gimpel (2016). Gaussian Error Linear Units (GELUs). arXiv:1606.08415.

Sources

  1. Warren S. McCulloch and Walter Pitts (1943). A Logical Calculus of the Ideas Immanent in Nervous Activity. Bulletin of Mathematical Biophysics 5.
  2. Frank Rosenblatt (1958). The Perceptron: A Probabilistic Model for Information Storage and Organization in the Brain. Psychological Review 65(6).
  3. OpenAI and Hugging Face (2019). GPT-2 small configuration (config.json). Hugging Face. Accessed October 23, 2026.
  4. Dan Hendrycks and Kevin Gimpel (2016). Gaussian Error Linear Units (GELUs). arXiv:1606.08415.