3 · Deep learning

7. Neural Networks from First Principles

Perceptrons, activations, forward and backward passes, and what depth buys you.

10 min read · 3 MCQs

From perceptron to multilayer network

A neuron computes a weighted sum plus bias, then applies a non-linear activation. Stacking layers of neurons gives a universal function approximator: without the non-linearity, any stack of linear layers collapses into a single linear map.

Activations

ReLU (max(0, x)) is the default because it is cheap and avoids saturation; GELU and SiLU are smooth variants used in transformers. Sigmoid and tanh saturate and are now mostly limited to gates and output layers.

Forward and backward

The forward pass computes predictions and the loss. The backward pass computes gradients layer by layer, and the optimiser updates the weights. Every framework automates this with an autograd graph.

import torch, torch.nn as nn

net = nn.Sequential(nn.Linear(64, 128), nn.ReLU(), nn.Linear(128, 10))
opt = torch.optim.AdamW(net.parameters(), lr=3e-4)
loss_fn = nn.CrossEntropyLoss()

logits = net(x)          # forward
loss = loss_fn(logits, y)
loss.backward()          # backward
opt.step(); opt.zero_grad()

Chapter quiz

3 questions · pass mark 75%
  1. 1. Removing all activation functions makes a deep network…

  2. 2. ReLU is popular because it…

  3. 3. Gradients are produced by the…

Answer every question to submit. Progress for ai-07 is saved in this browser.