Availit World How AI really works, in your language

Lesson 10 of 4615 minFacts checked October 20, 2026

Neural networks: small functions, stacked deep

A straight line can only learn straight-line patterns. Stack thousands of tiny functions, each with a small bend in it, and you can learn almost any pattern at all. That stack is a neural network.

In this lesson you will

  • Work out by hand what a single artificial neuron computes
  • Explain why every network needs a bend, an activation function such as ReLU
  • Describe layers, width and depth, and count the parameters of a small network
  • Find the neural network inside every layer of a language model, the feed-forward block
On this page
  1. One neuron
  2. Why the bend matters
  3. Layers: wide and deep
  4. What the hidden layers learn
  5. The network inside every language-model layer
  6. Remember
  7. Check yourself

One neuron

An artificial neuron is a very small function. It takes some numbers in, multiplies each by a weight, adds them up, adds one more number called the bias, and passes the result through a simple bend called the activation function.

What one neuron computes
sum = w₁×x₁ + w₂×x₂ + … + b

A dot product of the inputs with the weights, plus the bias. You met both in the vectors lesson.

output = ReLU(sum) = max(0, sum)

ReLU, the most common bend: keep a positive sum as it is, turn a negative one into zero.

x = [1, 0.5], w = [0.8, −1.2], b = 0.3

An example.

sum = 0.8 − 0.6 + 0.3 = 0.5, output = 0.5

The sum is positive, so ReLU lets it through unchanged.

Try itPlay with a neuron

These sliders start at the example above. Change the inputs, the weights and the bias, and watch the sum and the output. Find a setting where the output becomes zero.

This interactive part needs JavaScript.

Why the bend matters

Why not leave the bend out? Because without it, stacking neurons gains nothing. A layer without a bend is a matrix multiplication, and two matrix multiplications in a row are the same as one (you can multiply the two matrices together first). However many such layers you stack, the result is still a straight-line function, and a straight line cannot learn a curve.

Add a bend after each layer and everything changes. Each ReLU neuron contributes one “hinge”: flat on one side, sloped on the other. Add up enough hinges, placed at different points with different slopes, and you can trace any curve you like, as closely as you want.

Activation functions you will see in papers
NameWhat it doesWhere
ReLUmax(0, x): zero for negatives, unchanged for positivesThe default for many years; simple and fast
GELUA smooth version of ReLU that lets small negative values throughBERT and many GPT-style models
SiLU (Swish)x times a smooth step between 0 and 1; also smoothInside SwiGLU, used by Llama, Qwen, DeepSeek and most open models

Layers: wide and deep

A layer is many neurons side by side, all reading the same inputs, each with its own weights. A whole layer is computed at once as one matrix times the input vector, plus a vector of biases, then the bend applied to every number. A network is layers in sequence: each layer’s outputs are the next layer’s inputs.

A classic network: reading handwritten digits
  1. 784 inputsThe brightness of each pixel in a 28 × 28 image
  2. Hidden layer128 neurons with ReLU; they learn useful strokes and shapes
  3. 10 outputsOne score per digit, 0 to 9, turned into chances by softmax
Counting its parameters
784 × 128 + 128 = 100,480

Every input connects to every hidden neuron, plus one bias each.

128 × 10 + 10 = 1,290

Every hidden neuron connects to every output.

total = 101,770 parameters

Enough to read handwritten digits about 98 % correctly. Llama 3.1 8B has about 80,000 times as many.

The number of neurons in a layer is its width; the number of layers is the network’s depth. The layers between input and output are called hidden layers, because you never see their values directly. Deep learning just means learning with networks of many layers. Llama 3.1 8B has 32 layers; DeepSeek-V3 has 61.

Quick check

A network has 3 inputs, a hidden layer of 4 neurons and 2 outputs. How many parameters does it have, counting biases?

Show the answer

Answer: 26 Inputs to hidden: 3 × 4 + 4 biases = 16. Hidden to outputs: 4 × 2 + 2 biases = 10. Total 26.

What the hidden layers learn

Nobody tells the hidden neurons what to look for. Training adjusts their weights, and useful detectors appear by themselves. In 2013, researchers looked inside an image network trained to recognise objects and found a clear ladder: neurons in the first layers responded to edges and colours, the middle layers to textures and parts like eyes or wheels, and the last layers to whole objects such as faces and dogs.

Language models build features too, though they are harder to see, because each idea is spread across many neurons and each neuron takes part in many ideas. In 2024, Anthropic researchers used a second, helper network to pull millions of separate features out of a production model, and found ones that switch on for famous landmarks, for bugs in code, or for an idea expressed in any language. The study of what is going on inside models is called interpretability.

Which part of a neuron does each job?

0 of 6 sorted
  • Decides how strongly each input counts

    Answer: Weights

  • Is added once, after the inputs are summed

    Answer: Bias

  • Turns a negative sum into zero

    Answer: Activation

  • Lets stacked layers learn curves instead of straight lines

    Answer: Activation

  • Is multiplied by one of the inputs

    Answer: Weights

  • Shifts the point where the neuron starts to switch on

    Answer: Bias

The network inside every language-model layer

Every layer of a transformer contains a small two-layer neural network called the feed-forward block (or MLP, for multi-layer perceptron). It is applied to each token’s vector separately. In Llama 3.1 8B it widens each 4,096-number vector to 14,336 numbers, applies the bend, and narrows it back to 4,096.

SwiGLU, the feed-forward block of most open models
h = SiLU(gate_proj · x) ⊙ (up_proj · x)

Two matrices widen the vector. One goes through the bend and then acts as a “gate”: ⊙ means multiply number by number, so the gate decides how much of each of the 14,336 values gets through.

output = down_proj · h

A third matrix narrows it back to 4,096 numbers, and the result is added to the token’s vector.

These three matrices are the gate_proj, up_proj and down_proj you counted in the matrices lesson: about 176 million of the 218 million weights in each Llama layer, or 81 %. Research suggests the feed-forward blocks hold much of a model’s stored knowledge: a 2020 study found their neurons acting like key–value memories, where a pattern in the text (the key) calls up a likely next word (the value).

Remember

  • A neuron computes a dot product of inputs and weights, adds a bias, and applies an activation such as ReLU = max(0, x).
  • Without the bend, stacked layers collapse into one straight-line function. With it, enough neurons can approximate any curve.
  • A layer is a matrix multiplication plus biases plus the bend. Width is neurons per layer, depth is the number of layers.
  • Hidden layers learn their own features, from edges to objects in images and concepts in language models.
  • Each transformer layer has a feed-forward block (SwiGLU in most open models) holding about 80 % of its weights. Split into experts, it becomes a mixture of experts.

Words to know

Neuron
A small function: weighted sum of inputs, plus a bias, through a bend.
Bias
A number added to a neuron’s sum, shifting when it switches on.
Activation function
The bend applied after the sum, such as ReLU, GELU or SiLU. Without it, layers add nothing.
ReLU
max(0, x): keeps positive numbers, turns negative ones into zero.
Layer
Many neurons side by side, computed together as one matrix multiplication.
Hidden layer
A layer between the input and the output, whose values you never see directly.
Deep learning
Machine learning with neural networks of many layers.
Feature
Something a network has learned to detect, such as an edge, a face, or an idea in text.
Feed-forward block (MLP)
The small two-layer network inside every transformer layer.
SwiGLU
The gated feed-forward design used by most open models: three matrices and a SiLU gate.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

A neuron has inputs [2, 1], weights [0.5, −3] and bias 1. What does it output with ReLU?

Show the answer

Answer: 0 sum = 2×0.5 + 1×(−3) + 1 = 1 − 3 + 1 = −1. ReLU turns the negative sum into 0.

Why does a network need activation functions?

Show the answer

Answer: Without them, any number of layers is the same as one straight-line layer Matrix multiplications in a row combine into a single one. The bends are what let depth add power.

What does “deep” in deep learning mean?

Show the answer

Answer: The network has many layers Deep simply means many layers stacked one after another.

In each layer of Llama 3.1 8B, where are most of the weights?

Show the answer

Answer: In the feed-forward block Its three feed-forward matrices hold about 176 of the 218 million weights in each layer. Activation functions have no weights at all.

Who decides what each hidden neuron detects?

Show the answer

Answer: Nobody: it emerges from training Training adjusts the weights to lower the loss, and useful detectors appear on their own.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonBackpropagation: how billions of weights learn at once
Previous lesson All lessons

Choose your language