Lecture 03 · The two worlds

The neural world.

Representation learning, gradients, generalization. A network is a stack of differentiable functions; the interesting object is the coordinates it learns.

9 sections 1 worked gradient step 1 interactive lab Self-paced
00 · Learning objectivesLecture 03 · The neural world

By the end of this lecture

Four things you can do.

01

Explain learning as optimization

Write the empirical risk, take a gradient step by hand, and say what backpropagation caches and why.

02

Read architectures as priors

Locality, weight sharing, recurrence, attention: what each assumption saves and where it fails.

03

Diagnose generalization failures

Separate iid from shift and composition, and explain double descent without treating it as a law.

04

Judge confidence and uncertainty

Calibration, OOD, ensembles, adversarial examples — and what none of them guarantees.

S/V · Lecture 03
00 · The hookLecture 03 · The neural world

Exclusive or

Four points no line can separate.

x₁x₂label
000
011
101
110

A linear classifier computes w₁x₁ + w₂x₂ + b and predicts 1 when the score is positive. It draws one line.

The label is 1 exactly when the inputs differ. The two positive points sit on one diagonal; the two negatives on the other.

Can one line put each diagonal on its own side?

S/V · Lecture 03
00 · The hookLecture 03 · The neural world

Four inequalities, one contradiction

There is no (w, b).

(0,0) → b < 0
(1,1) → w₁ + w₂ + b < 0
(0,1) → w₂ > −b
(1,0) → w₁ > −b

Add the last two: w₁ + w₂ > −2b, so w₁ + w₂ + b > −b > 0. That contradicts the second inequality.

No choice of w₁, w₂, b fits the four labels. A single-layer network cannot represent XOR.

Minsky & Papert, Perceptrons (1969). The critique is correct about the single layer, and was read as a verdict on the field.

S/V · Lecture 03
00 · The hookLecture 03 · The neural world

Learn the coordinates, then read them out

The fold.

h₁ = ReLU(x₁ − x₂)    h₂ = ReLU(x₂ − x₁)    predict 1 if h₁ + h₂ > 0.5

xlabelh₁h₂h₁ + h₂prediction
(0, 0)00000
(0, 1)10111
(1, 0)11011
(1, 1)00000

The map is piecewise linear. It folds the square along x₁ = x₂; both negative corners land on the origin, the positives land on the axes.

The sum x₁ + x₂ is gone. A representation is a choice of what to ignore.

S/V · Lecture 03
00 · The hookLecture 03 · The neural world

Interactive · change the coordinates, not the classifier

The same four points, three views.

INPUT SPACE (0,0) · 0 (1,1) · 0 (0,1) · 1 (1,0) · 1 no line separates the diagonals HIDDEN SPACE h₁ + h₂ = 0.5 (0,0) and (1,1) (0,1) (1,0) one line now separates them BACK IN INPUT SPACE (0,0) · 0 (1,1) · 0 (0,1) · 1 (1,0) · 1 the boundary is two half-planes, not one line
Schematic. The exact coordinates are in the table on the previous slide.

The classifier sees (x₁, x₂). No line separates the diagonals.

h is not defined yet: the input is the representation.

Press a view. The buttons change the drawing, not just its colour: the coordinates and the boundary are recomputed from the same four points.

S/V · Lecture 03
01 · OptimizationLecture 03 · The neural world
01 / 08

Learning as optimization.

A loss, a gradient, and a chain rule. The mechanism is old; the scale is new.

S/V · Lecture 03
01 · OptimizationLecture 03 · The neural world

What training minimizes

A sample average, and its slope.

Empirical risk

R̂(θ) = (1/n) Σ ℓ(fθ(xi), yi)

The population risk R(θ) is what we want; the gap is the generalization gap.

Gradient descent

θt+1 = θt − η ∇R̂(θt)

If R̂ is L-smooth, any 0 < η < 2/L decreases the loss.

For classification: pk = softmax(z)k, ℓ = −log py. Compute it with log-sum-exp; the ratio overflows for large logits.

S/V · Lecture 03
01 · OptimizationLecture 03 · The neural world

Reverse-mode automatic differentiation

The chain rule, scheduled.

x z = Wx + b a = φ(z) ŷ = Va + c L(ŷ, y) FORWARD · cache activations BACKWARD · multiply by local Jacobians
A schematic computation graph. The backward pass reuses the forward values at every node.

Cost: a small constant multiple of the forward pass, independent of the parameter count.

Why cache: the derivative is evaluated at the forward value — e.g. d tanh = 1 − tanh².

S/V · Lecture 03
01 · OptimizationLecture 03 · The neural world

One scalar input, one hidden unit, one step

By hand: 1.125 → 0.490.

z = wx + b, a = ReLU(z)
ŷ = va + c, L = ½(ŷ − y)²
x = 1, y = 2, η = 0.1

Forward: z = .5, a = .5, ŷ = .5, L = 1.125. Backward: ∂L/∂ŷ = −1.5, then ∂L/∂v = −.75, ∂L/∂c = −1.5, ∂L/∂z = −1.5, ∂L/∂w = ∂L/∂b = −1.5.

quantitybeforegradientafter
w.500−1.500.650
b.000−1.500.150
v1.000−.7501.075
c.000−1.500.150
ŷ.500−1.5001.010
L1.125—0.490

Try η = 1: ŷ = 7.625, L ≈ 15.8. The gradient was right; the step was too long. This is why schedules exist.

S/V · Lecture 03
01 · OptimizationLecture 03 · The neural world

Noise, momentum, and a per-parameter step

Minibatches and Adam.

SGD

gt = (1/B) Σi∈B ∇ℓi

Unbiased for the full gradient; Var ≈ σ²/B. Small batches: many noisy updates. Large batches: few precise ones.

Adam

mt = β₁mt−1 + (1−β₁)gt
vt = β₂vt−1 + (1−β₂)gt²
θ ← θ − η m̂t / (√v̂t + ε)

Defaults β₁=.9, β₂=.999, ε=1e−8; m̂, v̂ are bias-corrected. A diagonal rescaling, not a second-order method.

The claim that small batches generalize better is a tendency with a contested explanation, not a theorem. Flatter minima are a hypothesis with counterexamples.

S/V · Lecture 03
02 · ArchitecturesLecture 03 · The neural world
02 / 08

Every layer is an assumption.

Locality, weight sharing, recurrence, attention. The prior decides what is easy to learn.

S/V · Lecture 03
02 · ArchitecturesLecture 03 · The neural world

The baseline

Universal, but unstructured.

f(x) = WLφ(…φ(W1x + b1)…)

Every input can interact with every other. Nothing is invariant. The prior is only smoothness.

Universal approximation (Hornik et al. 1989): one hidden layer with enough units can approximate any continuous function on a compact set.

It is an existence theorem. It does not say the units are findable from n examples, and it says nothing about optimization.

Depth is not a convenience. Some functions need exponentially many shallow units but only polynomially many deep ones (Telgarsky, COLT 2016).
S/V · Lecture 03
02 · ArchitecturesLecture 03 · The neural world

Grid data

Locality and weight sharing.

(k ∗ x)[i,j] = Σu,v k[u,v] · x[i+u, j+v] + b

What it assumes

A feature depends on a small neighbourhood; the same detector is useful at every position. Hence conv(Tδx) = Tδconv(x).

What it saves

32×32×3 → 64 dense: 196,672 parameters. 3×3 conv, 3→64: 1,792. About 110× fewer.

The bias is wrong when position is meaningful. Translation equivariance is a property of the layer, not a guarantee about the data.

S/V · Lecture 03
02 · ArchitecturesLecture 03 · The neural world

Sequence data

A state through time.

ht = tanh(Whht−1 + Wxxt + bh)    ŷt = Woht + bo

The prior

Order and variable length. The same weights apply at every step, so a pattern learned early can be reused late.

The cost

∂ht/∂ht−k is a product of k Jacobians. Singular values below 1 vanish; above 1 explode.

The LSTM (Hochreiter & Schmidhuber, 1997) adds gated paths that carry information across many steps. It mitigates the product; it does not remove it. Recurrence is also hard to parallelize.

S/V · Lecture 03
02 · ArchitecturesLecture 03 · The neural world

Set data, and language with positions

Attention is a soft lookup.

Attention(Q, K, V) = softmax(QK⊤/√dk) V

The symmetry

Without positions, permuting the tokens permutes the output the same way. That is right for sets, wrong for language, so positions are added.

The trade

The prior is weak: locality and syntax must be learned from data. A strength at scale, a liability on small data. Full attention costs O(n²).

The Transformer stacks multi-head attention with feed-forward blocks, residuals, and layer normalization. Its weak prior is why it scales with data — and why it needs the data.

S/V · Lecture 03
03 · RepresentationLecture 03 · The neural world

The objective decides

A representation is a choice of what to ignore.

Sufficiency

The label is still recoverable: I(y; φ(x)) close to I(y; x).

Invariance

Nuisance factors do not change the vector. Pose, lighting, phrasing.

Smoothness

Nearby inputs map to nearby vectors, so interpolation means something.

Linear accessibility

A linear probe on top solves the task. The usual diagnostic for frozen features.

XOR's hidden layer keeps |x₁ − x₂| and discards x₁ + x₂. For that task the discard is free; for a counting task it is fatal. No objective delivers all four properties at once.

S/V · Lecture 03
03 · RepresentationLecture 03 · The neural world

Three ways to say what matters

Reconstruct, contrast, align.

Autoencoder

min ‖x − D(E(x))‖²

Keeps what redraws the input. Can spend capacity on texture and discard the label. Collapse? No; blur? Yes.

VAE

log p(x) ≥ Eq[log p(x|z)] − KL(q‖p)

A smooth latent neighbourhood. Reparameterize z = μ + σ⊙ε. The decoder can ignore z.

Contrastive / CLIP

−log [ esim(z,z⁺)/τ / Σj esim(z,zj)/τ ]

Keeps what positive pairs share. Without negatives, the constant vector wins. CLIP aligns image and text encoders.

The objective is the prior. A model trained to predict captions learns what captions mention, not everything visible.

S/V · Lecture 03
04 · GeneralizationLecture 03 · The neural world
04 / 08

A low loss is not a promise.

Bias and variance, the interpolation threshold, shift, shortcuts, composition — and then confidence.

S/V · Lecture 03
04 · GeneralizationLecture 03 · The neural world

The classical picture, and its edge

Bias, variance, and the interpolation threshold.

E[(y − f̂(x))²] = bias² + variance + σ²

Underparameterized

High bias, low variance. More capacity helps. The left side of the U-curve.

Interpolation

Just enough capacity to fit the data exactly. The solution is sensitive; test error peaks.

Overparameterized

Many interpolating solutions. The optimizer's implicit bias picks one; error can fall again.

The puzzle: Zhang et al. (2017) fit random labels almost perfectly with standard networks. So “can fit anything” does not predict generalization, and classical uniform-convergence bounds are vacuous at this scale.

S/V · Lecture 03
04 · GeneralizationLecture 03 · The neural world

The curve is not a U

Double descent.

CAPACITY → TEST ERROR → interpolation threshold underparameterized overparameterized
Schematic after Belkin et al. (2019). No measured values; the shape is the claim.

A peak at the threshold, then a second descent as capacity grows.

Not a law. It depends on label noise, the optimizer, early stopping, and how capacity is defined. It can disappear with regularization.

Read it as a warning against a single U-curve, not as a design recipe.

S/V · Lecture 03
04 · GeneralizationLecture 03 · The neural world

Three ways to be right for the wrong reason

Shift, shortcuts, composition.

Distribution shift

P(x) changes, or P(y), or P(y|x). A model of one hospital is a model of that hospital.

Shortcut learning

The background instead of the object; the scanner instead of the pathology. The cue is predictive on the sample, not the task.

Compositional split

A held-out combination of familiar parts. High iid accuracy, chance on the new combination.

The lab's default: 100% on the iid test set, 0% on the held-out quadrant, near 100% confident there. A number without a split is not evidence.
S/V · Lecture 03
05 · UncertaintyLecture 03 · The neural world

Confidence is a statement about a distribution

Calibration is not accuracy.

P(Y = Ŷ | p̂ = p) = p

Among inputs where the model says p, the fraction correct should be p. Summarize with ECE: bin, then average |acc − conf|.

Temperature scaling: divide logits by T, fit T on validation. One parameter; ranking unchanged.

Under shift: accuracy and calibration both degrade (Ovadia et al. 2019). An iid calibration number is not a deployment promise.

CONFIDENCE → ACCURACY → overconfident
Schematic. Below the diagonal: claims more than it delivers.
S/V · Lecture 03
05 · UncertaintyLecture 03 · The neural world

What the model does not know

OOD, ensembles, adversarial.

OOD score

Max softmax, energy, or Mahalanobis distance. All need a threshold, and the threshold encodes a cost.

Ensemble

Train M models; disagreement is a proxy for epistemic uncertainty. Shared bias makes them agree and fail together.

Adversarial

x′ = x + ε sign(∇xℓ). Small, imperceptible, and often confidently wrong.

What none of them is: a guarantee that this answer is true. A probability is not a warrant; a benchmark is not a safety case.

Ilyas et al. (2019): adversarial examples can exploit non-robust but genuinely predictive features, which makes feature admissibility a specification question.

S/V · Lecture 03
06 · What nets get rightLecture 03 · The neural world

The honest ledger

Capability is not accountability.

Right

Perception at scale; sequence modelling; transfer from pretrained representations; generation; the engineering stack of autodiff and accelerators.

Wrong

Opacity; data hunger; hallucination; brittleness under shift and attack; composition; long-horizon state.

“General methods that leverage computation are ultimately the most effective, and by a large margin.” — Sutton, “The Bitter Lesson”, 2019

A claim about capability curves, not about guarantees. Position: scale buys perception and fluency; it does not by itself buy composition, verification, or grounding.

S/V · Lecture 03
07 · The bridgeLecture 03 · The neural world

Networks as grounders, proposers, and the other half of a check

Ground, propose, check.

Ground

φθ: X → Z, then q: Z → Σ. Perception turns raw input into a symbol alphabet.

Propose

The network generates parses, plans, proofs, programs, actions; a symbolic component checks them.

Check

A grammar masks invalid tokens; a verifier rejects invalid structures. The check is independent of the network.

It adds: composition that survives recombination, an independent check, data efficiency, an audit trail.

It costs: specification effort, inference time, semantic loss at the discretization, and the risk of trusting a wrong rule.

The design question is which failure the application can afford. A triage system can wait for a verifier; a drone at 30 Hz cannot.

S/V · Lecture 03
08 · RecapLecture 03 · The neural world

What you should be able to do

Four moves.

Optimize

Write the risk, take the step, and say what backprop caches.

Represent

Read a layer as a prior and a representation as a choice of what to ignore.

Generalize

Name the split, the shift, and the shortcut before quoting a number.

Trust

Separate calibration from correctness; ask what the guarantee is.

S/V · Lecture 03
08 · RecapLecture 03 · The neural world

Next · hands-on

Now break it.

Open the representation lab. Train the linear model on XOR; it stalls. Train the one-hidden-layer model; it fits. Then switch to the compositional split and watch the held-out quadrant fail at high confidence.

Lab 03 · representation playground → open the lab

S/V · Lecture 03
Speaker notes