AI ENGINEER02-01 · From neurons to networks
20/90
Sign in

Layer 02 · Deep Learning · Ch 01

From neurons to networks

Build a reliable mental model for neural networks: weighted sums, activation functions, layers, and one forward pass.

55 min readdifficulty beginnerdepth build

An app needs to spot support tickets that may lock a customer out. A single rule such as “three failed sign-ins means urgent” is easy to write. Real cases combine signals: recent account creation, location change, recovery attempts, and the pattern across them.

A neural network is a way to learn combinations of numeric signals. It is not magic, a database, or a mind. It is many small calculations with adjustable numbers.

Lesson details

Module
Deep learning
Lesson
1 · From neurons to networks
Difficulty
Beginner
Learning time
55 minutes

Before you start

  • Vectors, dot products, loss, gradients, and basic generalisation
  • The train/validation/test discipline from Classical ML

Skills you will gain

  • Calculate a perceptron output from inputs, weights, a bias, and ReLU
  • Explain why activation functions make neural networks more expressive
  • Trace a small forward pass through a hidden layer
  • Describe the purpose of ReLU, GELU, and SwiGLU without overstating their differences
  • Recognise why parameter initialisation matters before training

Why this matters

Neural networks power image recognition, speech systems, recommendation, and language models. Before using a framework, you need to know what a layer calculates. That makes model shapes, unexpected outputs, and later training failures less mysterious.

Plain-English mental model

Step 1 — A perceptron makes a weighted decision

An input is a number supplied to the model. For a ticket, it could be the number of failed sign-ins. A weight is a learned number that scales an input’s contribution. A bias is an extra learned baseline that lets the calculation shift before it reacts to inputs.

First calculate the weighted sum, often written as z:

z = x₁w₁ + x₂w₂ + ... + b

Here x means an input, w means its weight, and b means bias. This is a dot product plus a bias, which you met in the maths foundations.

FIG 02-01.1 · FOLLOW ONE FORWARD PASSinputshidden layeroutputfailed sign-insx₁ = 4account agex₂ = 2 daysw = 0.8w = −0.4neuron Az = 0.8×4 − 0.4×2 − 1ReLU(z) = 1.4neuron Bnegative zReLU(z) = 0w = 1.2urgency score1.2×1.4 + 0.3×0score = 1.68routewith a policyforward pass = calculate outputs using current weights · learning changes weights later
FIG 02-01.1— values flow from the ticket inputs through two hidden neurons to an urgency score. The weights stay fixed during this forward pass; training changes them later.

Small example: use x₁=4 failed sign-ins, x₂=2 days of account age, weights 0.8 and −0.4, and bias −1.

z = (4 × 0.8) + (2 × −0.4) − 1
z = 3.2 − 0.8 − 1
z = 1.4

The negative weight does not mean account age is “bad”. It means that, for the training objective and other available inputs, a higher value moves this unit’s calculation down. Do not turn one weight into a story about cause or policy.

Step 2 — An activation function adds a bend

If we only stack weighted sums, the result is still one big linear calculation. A linear rule can draw a straight decision boundary. It cannot express many useful “if this pattern, then that pattern” shapes.

An activation functionActivation functionA function applied after a neuron’s weighted sum. It adds non-linearity, meaning a network can represent curved and conditional relationships instead of only one straight-line transformation. transforms z after the weighted sum. It adds non-linearity: a bend or gate that lets stacked layers represent more varied relationships.

The beginner-friendly example is ReLUReLURectified Linear Unit, an activation function defined as max(0, input). It outputs zero for negative values and keeps positive values unchanged. It is simple and commonly used, but a unit can stop contributing if it stays negative., short for Rectified Linear Unit:

ReLU(z) = max(0, z)

So ReLU(1.4) is 1.4, while ReLU(−0.7) is 0. This does not mean negative evidence is always useless. It is a design choice for that particular hidden value.

FIG 02-01.2 · THREE WAYS TO GATE A SIGNALactivation functions add useful bendsReLUmax(0, z)GELUsmoothly gates zvalue pathz × Wgate pathswish(z × V)SwiGLU×outputvalue × learned gate
FIG 02-01.2— ReLU makes a sharp zero-or-pass decision. GELU changes smoothly around zero. SwiGLU uses one learned path to gate another. All provide non-linearity; choosing one is an engineering choice, not a guarantee of quality.

GELUGELUGaussian Error Linear Unit, a smooth activation function that gradually gates values rather than using ReLU’s sharp zero corner. It is common in transformer-style networks. is a smooth gate used in many transformer networks. SwiGLUSwiGLUA gated activation used in many modern language-model feed-forward layers. It transforms one path for values, uses another transformed path as a learned gate, and multiplies them. The exact formula is less important than recognising it as a flexible gated non-linearity. is a gated activation: one learned path produces values and another controls how much of those values pass through. You do not need to memorise their formulas yet. Remember the job: preserve useful signal while giving the network a non-linear way to combine it.

Step 3 — Layers create intermediate representations

A hidden layerHidden layerA layer of calculations between a network’s visible input and output. Its intermediate values are called hidden because they are internal model representations, not because they are secret or unknowable. sits between the visible input and output. “Hidden” only means internal to the model. Its values can be inspected, although they may not have a simple human label such as “fraud risk”.

For the ticket example, one hidden unit might react to a suspicious combination of failures and a young account. Another could react to a different combination. An output layer combines those intermediate values into a score.

A forward passForward passOne calculation that moves an input through a model’s current parameters to produce an output. A forward pass does not itself learn or change the parameters; backpropagation and an optimiser do that during training. is one trip from input to output using the current values of all parameters. A parameter is any learned number in the model, including weights and biases. A forward pass predicts; it does not learn. The next lesson explains how backpropagation measures which parameters contributed to an error and how an optimiser updates them.

Worked example — two neurons, one output

Suppose the first hidden unit has output h₁ = ReLU(1.4) = 1.4. A second unit receives a negative sum and has h₂ = ReLU(−0.7) = 0.

The output layer uses weights 1.2 and 0.3, with no output bias for this tiny example:

score = (1.2 × h₁) + (0.3 × h₂)
score = (1.2 × 1.4) + (0.3 × 0)
score = 1.68

1.68 is a score, not automatically a probability or an instruction. A real system decides how to transform a score, choose a threshold, request more evidence, or hand the case to a person. That policy must be validated for errors, workload, privacy, and fairness.

Try it — write one perceptron in Python

PythonA small forward pass with ReLU
def relu(value: float) -> float:
    return max(0.0, value)


failed_sign_ins = 4.0
account_age_days = 2.0

weighted_sum = (
    failed_sign_ins * 0.8
    + account_age_days * -0.4
    - 1.0  # bias
)

hidden_value = relu(weighted_sum)
urgency_score = hidden_value * 1.2

print("weighted sum:", weighted_sum)
print("hidden value:", hidden_value)
print("urgency score:", urgency_score)

The long decimal is normal floating-point representation, not evidence that the calculation is conceptually wrong. For display, use round(value, 2). Do not round values during training just to make logs tidier.

Important lines

failed_sign_ins * 0.8
This input is scaled by a weight. During training, that weight can change.
+ account_age_days * -0.4
A second input contributes with its own weight. The meaning depends on all other inputs and training data.
- 1.0
This is the bias: an adjustable baseline before the activation.
hidden_value = relu(...)
ReLU adds the non-linear gate. Without an activation, extra linear layers do not create a richer class of functions.

Modification ideas: change one input at a time; set weighted_sum negative; add a second hidden unit; then compare what changes. Do not claim the output is a calibrated risk probability unless the full model was trained and evaluated for that purpose.

Step 4 — Starting values matter before learning

Training begins with initialisationInitialisationThe choice of starting values for model parameters before training. Good initialisation keeps signals and gradients at practical sizes; it does not replace training or guarantee quality.: choosing starting parameter values. If every neuron starts with the same values, equivalent neurons can keep doing the same work. If values are wildly large or tiny, signals and later gradients can become unstable.

Common initialisation methods choose small random values scaled for the layer shape. The important beginner rule is: use the framework default unless you have a measured reason to change it. Random starts mean training results can vary slightly, so record seeds and compare repeat runs when reliability matters.

You may hear universal approximationUniversal approximationThe mathematical result that a sufficiently large neural network with a suitable activation can approximate many continuous functions on a bounded input range. It does not say that the network will learn the function from limited data, train efficiently, generalise, or be the best design.: sufficiently large networks can approximate many functions over a bounded range. This is a possibility result, not a product plan. It does not promise enough data, easy training, generalisation, low cost, safety, or a good user experience.

Real-world AI engineering example — triaging support safely

Common mistakes

Calling a neural network an “AI brain” and assuming it understands the task.

Fix — Describe the actual inputs, target, parameters, and evaluation. A learned score can be useful without understanding intent or consequences.

Thinking more layers automatically make a model better.

Fix — Start with a baseline and add capacity only when validation evidence supports it. More layers can raise cost, instability, and overfitting risk.

Forgetting the activation function between layers.

Fix — Check the model definition. A stack of affine calculations without non-linearity is still affine.

Treating one weight as a causal explanation.

Fix — Inspect data, feature design, correlated inputs, evaluation slices, and counterfactual limits. Use weights only as part of a wider investigation.

Using a raw model score as an automatic high-stakes decision.

Fix — Calibrate and validate the output, choose an explicit policy, add human review and a safe fallback, and monitor outcomes.

Changing initialisation or activations because a blog says they are newer.

Fix — Use framework defaults first. Change one measured variable at a time and compare validation quality, stability, latency, and cost.

Knowledge check

Knowledge check

1What does a perceptron calculate before its activation?
2Why are activation functions important between layers?
3If z = -0.7, what is ReLU(z)?
4Which statement about a forward pass is correct?

Practice activity

Practice · 10–20 minutes

Trace and alter a tiny neural network

Goal: Calculate a weighted sum, apply ReLU, and explain what changes when you alter an input or bias.

  1. Copy the starter code into a Python file or notebook.
  2. Run it with the provided inputs and record z, hidden, and score.
  3. Change failed sign-ins from 4 to 1. Predict the ReLU output before running it.
  4. Change the bias from -1.0 to 0.5. Explain why this shifts the hidden unit.
  5. Write one sentence explaining why the score is not yet a production decision.

Expected result: With fewer failed sign-ins, z becomes negative and ReLU produces 0. Increasing the bias shifts z upward. Your explanation separates a learned score from a validated decision policy.

Optional challenge: Add a second hidden unit with different weights, then combine both hidden values into one score. Label which values are inputs, parameters, and activations.

Reveal solution
def relu(value):
    return max(0.0, value)


failed_sign_ins = 4.0
account_age_days = 2.0
bias = -1.0

z = failed_sign_ins * 0.8 + account_age_days * -0.4 + bias
hidden = relu(z)
score = hidden * 1.2

print('z:', z)
print('hidden:', hidden)
print('score:', score)

Solution: with the original inputs, z is about 1.4, hidden is about 1.4, and score is about 1.68. With failed_sign_ins = 1, z becomes -1.0, so ReLU makes hidden = 0 and score = 0. With bias = 0.5 and the original inputs, z becomes 2.9; the bias shifts the unit’s baseline before the activation. Neither score tells a production system what it should do by itself: that needs a validated threshold or ranking policy, human workflow, and monitoring.

Key takeaways

  • A perceptron is a weighted sum plus a bias, followed by an activation.
  • Weights and biases are learned parameters; a forward pass uses them but does not update them.
  • Activations add the non-linearity that makes stacked layers more expressive.
  • A hidden layer creates intermediate numeric representations, not guaranteed human concepts.
  • Good initialisation helps training start stably, while validation and monitoring determine whether a system is useful.

Flashcards

Flashcards

1 of 6

Revision and interview questions

  1. Draw and explain the calculation inside one perceptron. Define input, weight, bias, pre-activation, and activation.
  2. Use a small numeric example to show why ReLU changes what a two-layer network can represent.
  3. Trace a forward pass through two hidden units and one output unit. Which values can change during training?
  4. Explain why a neural-network score must be paired with evaluation and an explicit decision policy before use in a support workflow.

One-page sketchnote summary

Print me · one-page revision sheet

From neurons to networks

Main idea

A neural network is a stack of small adjustable calculations. Each unit mixes inputs with weights and a bias, then an activation gates the result. A forward pass creates a score; training and product policy are separate jobs.

Core terms

  • Perceptron — weighted sum + bias + activation
  • Weight — learned contribution scale
  • Bias — learned baseline shift
  • Forward pass — calculate, do not learn
  • ReLU — max(0, z)
  • Hidden layer — internal numeric representation

One picture

inputshidden layeroutputfailed sign-insx₁ = 4account agex₂ = 2 daysw = 0.8w = −0.4neuron Az = 0.8×4 − 0.4×2 − 1ReLU(z) = 1.4neuron Bnegative zReLU(z) = 0w = 1.2urgency score1.2×1.4 + 0.3×0score = 1.68routewith a policyforward pass = calculate outputs using current weights · learning changes weights later

Code pattern

z = Σ(input × weight) + bias
hidden = ReLU(z)
score = Σ(hidden × output_weight)

Watch out

  • More layers are not automatically better
  • No activations means still-linear layers
  • A weight is not a causal explanation
  • A score is not a decision policy

Remember

  • Trace one unit before using a framework
  • Activations create useful bends
  • Parameters change during training, not prediction
  • Keep output policy separate from model score
  • Use defaults and validation before clever tuning

Three quick questions

  1. What produces z?
  2. What does an activation add?
  3. When are weights updated?

Lesson checklist

0 of 7 complete

Resources

Next up
Backpropagation from scratch
You can now calculate a network’s forward pass. Next, follow an error backwards through the same calculation graph to see how training discovers which weights should change.