Marginal

Deep Learning

Neural networks from neurons to transformers: activation functions and multilayer perceptrons, universal approximation, backpropagation and automatic differentiation, initialization and vanishing gradients, normalization and residual connections, convolutional networks, embeddings, attention, the transformer architecture, next-token prediction, memory and compute arithmetic, and fine-tuning.

28 lessons in 3 units

Start your free trial14 days free. No card needed.
What you'll learn

28 lessons, one small step at a time

Each lesson states its goal, then works up to it in short steps with practice after each. A placement test at the start skips what you already know.

Neural Networks

7 lessons
  1. Neurons & activation functionsCompute a neuron's output with ReLU, sigmoid and tanh activations, and explain why the nonlinearity is essential.
  2. Forward passesCompute a forward pass through a hidden layer and the output it feeds, and the activation shapes for a batch.
  3. Multilayer perceptronsShow how a hidden layer solves XOR and how depth multiplies linear pieces, and count the parameters of a layer and of a whole network.
  4. Universal approximationCount the linear pieces a ReLU network can have, and state what the universal approximation theorem does and does not say.
  5. Convolution output sizesCompute the output size of a convolution, and track the size through downsampling layers.
  6. Convolutional networksCount a convolutional layer's parameters, chain shapes through layers, compare with a fully connected layer, and compute receptive fields.
  7. Recurrent networksUnroll a recurrent network over a sequence, compute how gradients shrink or grow through time, and explain why transformers replaced RNNs.

Training Deep Networks

7 lessons
  1. Local gradientsPass a gradient back through an activation and through a linear layer, and chain the local rules along a computation graph.
  2. BackpropagationCompute gradients by backpropagation, from the last layer back through earlier ones.
  3. Computational graphs & autogradCompute the gradients autograd stores, including for a variable used twice, and avoid common training bugs.
  4. Signal propagationCompute how a layer scales the variance of its signal, and how the scaling compounds over many layers.
  5. Initialization schemesCompute Xavier and He initialization scales, explain ReLU's factor of 2, and explain why the weights must start random.
  6. Layer normalizationApply layer normalization to a vector, including its learned scale and shift.
  7. Residual connectionsCompute how residual connections carry gradients, describe the residual stream, and tell pre-norm from post-norm.

Transformers & Language Models

14 lessons
  1. TokenizationCount pair frequencies for byte-pair encoding, convert between tokens and words, and explain tokenization's trade-offs.
  2. Embedding matricesCount the parameters of embedding matrices, with and without weight tying, and the shape of the activations they produce.
  3. Embedding similarityCompute the cosine similarity of embeddings, use directions for analogies, and find nearest neighbors.
  4. Attention scoresCompute scaled dot-product attention scores, and turn them into attention weights.
  5. AttentionCompute an attention output as a weighted average of values, and count the pairs a causal mask allows.
  6. Positional informationCompute sinusoidal position encodings and rotary rotations, and compare positional schemes.
  7. Multi-head attentionCompute how attention heads split the model width, and the quadratic cost of attention scores.
  8. The transformerTrace a transformer from tokens to next-token predictions, count its parameters, and tell what each part and each arrangement of blocks does.
  9. Sequence probabilitiesCompute a sequence's probability with the chain rule, and its log-probability.
  10. Next-token predictionCompute a language model's next-token loss, explain how one pass trains on every position, and sample with temperature.
  11. Memory arithmeticCompute the memory a model's weights take, the memory training with Adam needs, and the savings from quantization.
  12. Compute arithmeticCompute the FLOPs of training and of inference, and the wall-clock time a training run takes.
  13. KV cachesCompute the size of a transformer's KV cache per token and for long contexts.
  14. Fine-tuning & LoRACount the parameters of a LoRA update and the fraction of a matrix it trains, and place fine-tuning among the stages of building an assistant.
Sample lesson

Neurons & activation functions

Goal: Compute a neuron's output with ReLU, sigmoid and tanh activations, and explain why the nonlinearity is essential.

Deep learning builds enormously capable systems from one simple unit, loosely inspired by biological neurons: a weighted sum followed by a nonlinearity. Everything from image classifiers to language models is made of millions or billions of these.

We will compute a weighted sum with ReLU, try other activations, and finish with why nonlinearity matters.

Step 1: Weighted sum and ReLU

An artificial neuron computes a weighted sum of its inputs plus a bias, then applies an activation function φ:

a = φ(wᵀx + b)

The default activation in hidden layers is the rectified linear unit, ReLU(z) = max(0, z): it passes positive sums through unchanged and outputs exactly 0 for every negative input. A neuron with weights (0.5, 0.5), bias −1 and input (−1, 3) has sum −0.5 + 1.5 − 1 = 0, so it outputs 0.

Step 2: Other activations

Smooth alternatives are also used. The sigmoid 1/(1 + e−z) runs from 0 to 1 with σ(0) = ½. Tanh, (eᶻ − e−z)/(eᶻ + e−z), has the same S shape but runs from −1 to 1, centered at 0 with tanh(0) = 0, and is odd: tanh(−z) = −tanh(z). GELU, approximately z·Φ(z), is a smooth version of ReLU used in many transformers: near 0 for very negative inputs, near z for large positive ones.

Step 3: Why nonlinearity

Without activation functions, each layer is an affine map, and a composition of affine maps is affine: a network of 10 such layers is equivalent to a single linear layer. The nonlinearity is what lets depth add expressive power. ReLU replaced sigmoids in hidden layers because sigmoid slopes are at most ¼, which shrinks signals through many layers, while ReLU's slope is exactly 1 for active units. Its weakness: a unit whose input is negative for every example outputs zero, gets no gradient and stops learning, a dead ReLU.

In the app, each step ends with practice questions, new ones every time, and the lesson comes back later in spaced reviews.

Start Deep Learning

Lessons that need something you haven't learned yet bring it in first, from any course.

Start your free trial14 days free. No card needed.