← Course Home Module 1 · Math Foundations
Module 1 · Foundations

Math Foundations

Everything in both papers reduces to a handful of mathematical ideas: vectors, matrices, functions, derivatives, probabilities, and logarithms. Master these short sections and no equation in the papers will scare you.

▶
Audio recap
A ~2-minute spoken summary of this module — great for revision on the go.

1.1 Vectors: lists of numbers

A vector is just an ordered list of numbers, e.g. v = (2, −1, 3). We say this vector lives in ℝ³ ("3-dimensional real space") because it has 3 entries. In deep learning, everything becomes a vector: a DNA letter, a word, a tactile image — all get converted to lists of numbers so a model can compute with them.

Key operations:

Why you care Paper 2's whole method is "make the tactile vector point the same way as the language vector." Similarity of vectors — dot products and the distributions built from them — is the beating heart of representation learning, attention, and distillation.

1.2 Matrices: grids of numbers, machines that transform vectors

A matrix is a rectangular grid of numbers, e.g. a 2×3 matrix has 2 rows and 3 columns. Multiplying a matrix by a vector produces a new vector: each output entry is a dot product between one matrix row and the input. So a matrix is a machine that transforms vectors — rotating, stretching, mixing their entries.

y = W x + b

This is the single most important equation in the course: a linear layer. x is the input vector, W ("weights") is a matrix, b ("bias") is a vector, and y is the output. Training a neural network means finding good numbers to put inside W and b. Nothing more mysterious than that.

Example W = [[1, 0], [0, 2]], b = (0, 1), x = (3, 4). Then Wx = (1·3+0·4, 0·3+2·4) = (3, 8), and y = Wx + b = (3, 9).

1.3 Functions and composition

A function maps inputs to outputs: f(x) = x². Functions can be composed — fed into each other: g(f(x)). A deep neural network is nothing but a long composition:

output = fL( … f2( f1(input) ) … )

where each fi is a simple layer (a matrix multiply followed by a simple nonlinear function). "Deep" literally means "many functions composed."

One special function family you must know: nonlinear activations, like ReLU(x) = max(0, x), which outputs x if positive and 0 otherwise. Without nonlinearities between them, stacked linear layers collapse into one linear layer — the network could never learn curves, only straight lines. Paper 1's Conv1D layers use ReLU (the σ in its Equation 1).

1.4 Derivatives and gradients: which way is downhill?

The derivative of f at a point tells you how much f changes if you nudge the input slightly: the slope. If f(x) = x², then f′(x) = 2x; at x = 3 the slope is 6, so increasing x increases f. To decrease f, move x in the opposite direction of the slope.

With many inputs, we collect the slope with respect to each input into a vector called the gradient, written ∇f. The gradient points in the direction of steepest increase; its negative points steepest downhill.

Why you care Training = defining a "badness score" (the loss) as a function of all the weights, then repeatedly nudging every weight a small step downhill: w ← w − η ∇L. That step size η is the learning rate — Paper 1 sets it to 1×10⁻⁴, Paper 2 tunes it to 2×10⁻⁵. You'll meet this as gradient descent in Module 2.

For compositions there is the chain rule: the derivative of g(f(x)) is g′(f(x)) · f′(x) — multiply the slopes of each stage. Backpropagation (Module 3) is just the chain rule applied systematically through every layer of a network.

1.5 Probability in five minutes

1.6 Exponentials, logarithms, and softmax

exp(x) = ex turns any real number into a positive one, exaggerating differences. log is its inverse: log(1) = 0; log of a small probability like 0.01 is a large negative number (≈ −4.6). Two properties you'll use constantly: log(ab) = log a + log b, and log is monotonic (bigger input, bigger output).

Networks internally produce raw unbounded scores called logits, one per class. The softmax function converts logits u = (u₁, …, u_K) into a valid probability distribution:

softmax(u)c = exp(uc)Σk exp(uk)

Every entry becomes positive, and the entries sum to 1. The biggest logit gets the biggest probability.

Worked example Logits (2, 1, 0) → exp gives (7.39, 2.72, 1.00), sum ≈ 11.11 → softmax ≈ (0.67, 0.24, 0.09). A clean probability distribution favoring class 1.
Where the papers use this Paper 1's classifier ends in a softmax over 21 classes, trained with cross-entropy loss (its Eq. 5). Paper 2 goes further: it applies softmax with a temperature T (dividing logits by T before softmax) to soften the teacher's and student's feature distributions before comparing them — you'll unpack that in Module 8.

1.7 Comparing distributions: a taste of cross-entropy and KL

Once model outputs are probability distributions, we need to measure "how far" a predicted distribution p is from a target distribution q. Two related measures dominate deep learning:

The one-sentence summary Cross-entropy trains a model to match hard labels (Paper 1's disease classes, Paper 2's material classes); KL divergence trains a student to match a teacher's whole soft distribution (Paper 2's distillation loss, its Eq. 7). Same family, different targets.
Exam warm-up — say it out loud
  1. What does a dot product measure, geometrically?
  2. Why do neural networks need nonlinear activations at all?
  3. What does the gradient of a loss tell you, and what do you do with it?
  4. Walk through softmax on logits (1, 1, 3) qualitatively — which class wins and why is the output a valid distribution?

Module 1 Quiz

10 questions. These exact ideas reappear in every later module.

← Previous
Module 0: The Two Worlds