Lecture 1 of 1418 min3D modelFree lecture

Neurons, layers and networks

A neural network is a stack of simple units that multiply, add and bend. See one neuron make a decision, see why a whole layer is a single matrix multiplication, then follow a real trained network as it classifies a flower.

In this lecture you will

  • Describe exactly what one artificial neuron computes
  • Explain how weights and a bias shape a neuron’s decision
  • Read a layer of neurons as a matrix multiplication
  • Follow a forward pass from raw inputs to predicted probabilities
  • Count the parameters of a simple network

In Machine Learning Foundations you met logistic regression: multiply each feature by a weight, add them up, squash the result into a probability. Keep that picture in mind. A neural network is, at heart, many of those little units wired together — and that simple idea powers image recognition, speech, translation and large language models.

This lecture builds a network from the bottom up: one neuron, then a layer, then a stack of layers. By the end you will be able to read a network diagram and know exactly what arithmetic happens inside it.

One neuron

An artificial neuron takes a few numbers in and produces one number out, in two steps.

  1. Weighted sum. Multiply each input by its weight, add them up and add a bias: z=w1x1+w2x2+⋯+wnxn+bz = w_1 x_1 + w_2 x_2 + \dots + w_n x_n + b
  2. Activation. Pass the sum through a simple function ff to get the neuron’s output a=f(z)a = f(z). A common choice is the sigmoid, which squashes any number into the range 0 to 1.

The weights say how much each input matters and in which direction: a large positive weight means “this input pushes me to fire”, a negative weight means “this input holds me back”. The bias sets how easily the neuron fires at all.

InteractiveInside a single neuronDrag the point · change the weights
Loading visual…

The shaded square shows the neuron’s output for every possible pair of inputs. The dashed line is where z = 0 — the neuron’s decision boundary — and the arrow is the weight vector, always perpendicular to it.

Try these experiments:

  • Change w₁ and w₂ and watch the boundary rotate: the weights decide which direction in input space the neuron cares about.
  • Change only the bias and watch the boundary slide without rotating.
  • Switch the activation to Step and the soft gradient becomes a hard yes/no decision. Switch to ReLU and the neuron stays silent on one side of the line and grows linearly on the other.

A single neuron can only ever draw one straight boundary. That is its limitation — and the reason we combine many of them.

A layer is a matrix multiplication

Put several neurons side by side, all reading the same inputs, and you have a layer. Each neuron has its own weights and bias, so each one looks at the inputs in its own way.

Writing out every weighted sum separately gets tedious. Stack each neuron’s weights as a row of a matrix WW, the inputs as a vector x\mathbf{x} and the biases as a vector b\mathbf{b}, and the whole layer becomes one line:

a=f(Wx+b)\mathbf{a} = f(W\mathbf{x} + \mathbf{b})
AnimationFrom neurons to a matrix multiplication
Loading animation…
  1. A layer of four neuronsThree inputs feed four neurons. Every input connects to every neuron, so there are 3 × 4 = 12 weights, plus one bias per neuron.
  2. One neuron, one weighted sumNeuron h₁ multiplies each input by its own weight and adds the results: 0.4 + 0.36 + 0.45 = 1.21.
  3. All neurons at once: W · xStack the four neurons’ weights as the rows of a 4 × 3 matrix. Multiplying it by the input vector computes all four weighted sums in a single operation.
  4. Add the bias, apply ReLUEach neuron adds its bias, then ReLU replaces negative values with zero. Two of the four neurons stay silent for this input — that sparsity is normal.
  5. A whole batch at onceIn practice we pass many examples together. A batch of 32 examples becomes a 32 × 3 matrix, and the layer becomes one matrix–matrix multiplication — exactly what GPUs do best.

This is why deep learning and GPUs grew up together. A graphics card is a machine for multiplying large matrices very fast, and a neural network is mostly large matrix multiplications with cheap activation functions in between.

A network is a stack of layers

A network feeds the output of one layer into the next. The first layer reads the raw inputs; the hidden layers in the middle compute intermediate features that nobody specifies by hand; the output layer produces the answer.

The network below is real: it has just been trained, in your browser, on measurements of three species of iris flower — the length and width of the sepals and petals. Scroll through the story to follow one flower through it.

Scroll storyA trained network classifying one flowerStep 1 of 6
Loading 3D model…
  1. 1
    Four measurements go in

    Each input neuron holds one measurement of the flower. Before entering the network, measurements are standardized so that each feature has a similar scale.

  2. 2
    Every connection has a weight

    Each line is one weight. Teal lines are positive and coral lines negative; brighter lines are larger. These values were learned from 150 example flowers.

  3. 3
    Hidden layer 1 builds features

    Each hidden neuron computes a weighted sum of the four measurements, adds its bias and applies ReLU. Some neurons light up strongly; others output exactly zero for this flower.

  4. 4
    Hidden layer 2 combines them

    The second hidden layer sees only the first layer’s outputs. It combines those intermediate features into ones that separate the species more cleanly.

  5. 5
    Softmax turns scores into probabilities

    The three output neurons produce one score per species. Softmax converts the scores into probabilities that add up to 100%, and the largest becomes the prediction.

  6. 6
    Training tunes every parameter

    All the weights and biases were learned by comparing predictions with the right answers and nudging every parameter to reduce the error. The next lectures show exactly how.

Input layer
The raw features. It performs no computation; it simply holds the values that enter the network.
Hidden layer
Any layer between input and output. Its outputs are learned intermediate features that nobody labels by hand.
Output layer
Produces the prediction — for example one score per class, turned into probabilities with softmax.
Fully connected (dense) layer
A layer in which every input connects to every neuron. The most basic building block of neural networks.
Forward pass
Running an input through the network, layer by layer, to produce a prediction.
Parameters
All the weights and biases. Training adjusts these; nothing else in the network changes.

Counting parameters

The size of a model is usually quoted as its number of parameters. For a fully connected layer with ninn_\text{in} inputs and noutn_\text{out} outputs:

parameters=nin×nout+nout\text{parameters} = n_\text{in} \times n_\text{out} + n_\text{out}

The flower network above has layers of 4 → 6 → 6 → 3 neurons, so it has 4⋅6+6+6⋅6+6+6⋅3+3=934·6 + 6 + 6·6 + 6 + 6·3 + 3 = 93 parameters. A classic network that reads 28 × 28-pixel handwritten digits (784 inputs), with one hidden layer of 128 neurons and 10 outputs, has 784⋅128+128+128⋅10+10=101,770784·128 + 128 + 128·10 + 10 = 101{,}770. Large language models have hundreds of billions — built from the same idea.

The same network in code

Frameworks such as PyTorch describe a network as a sequence of layers. This is the flower classifier:

import torch
from torch import nn

model = nn.Sequential(
    nn.Linear(4, 6),   # 4 inputs  -> 6 neurons: W is 6x4, b has 6 values
    nn.ReLU(),
    nn.Linear(6, 6),   # hidden layer 2
    nn.ReLU(),
    nn.Linear(6, 3),   # one score per species
)

flower = torch.tensor([[0.53, -0.36, 1.05, 0.79]])  # standardized measurements
probabilities = torch.softmax(model(flower), dim=1)
print(sum(p.numel() for p in model.parameters()))   # 93

We have quietly used ReLU and sigmoid without asking why a network needs activation functions at all. The next lecture answers that question — and shows why stacking layers without them would be pointless.

Key takeaways

  • A neuron computes a weighted sum of its inputs plus a bias, then passes the result through an activation function.
  • Weights decide how much each input matters and in which direction; the bias shifts the neuron’s threshold.
  • A layer applies many neurons at once — mathematically one matrix multiplication, which is why GPUs are so effective.
  • A network stacks layers, so each layer builds more useful features from the one before; training adjusts every weight and bias.

Check your understanding

4 questions · answers explained

Q1A neuron has weights w₁ = 2 and w₂ = −1, bias b = 0.5, and receives inputs x₁ = 1 and x₂ = 3. What is its weighted sum z?

z = w₁·x₁ + w₂·x₂ + b = 2·1 + (−1)·3 + 0.5 = −0.5. The activation function is applied to this value afterwards.

Q2What does the bias of a neuron do?

The bias is added after the weighted sum. Changing it moves the decision boundary without rotating it — like moving a door frame without changing which way it faces.

Q3A fully connected layer maps 128 inputs to 64 outputs. How many parameters does it have?

There is one weight per input–output pair (128 × 64 = 8,192) plus one bias per output neuron (64), giving 8,256 parameters.

Q4Why do deep-learning frameworks process a batch of examples through a layer at once?

A batch of 32 examples becomes a 32-row matrix, and the whole layer becomes one matrix multiplication. GPUs and other accelerators are built to run exactly this operation at enormous speed.