Skip to content

Block 02 / 07

Function approximation

A model is a parameterized function fitted by optimization.

A model is a parameterized function. You show it inputs and desired outputs. A loss scores the miss. Gradient descent nudges the parameters so the miss shrinks. CNNConvolutional neural network. Learns local filters that slide across the input, exploiting spatial structure. The default shape for images before Vision Transformers arrived., RNNRecurrent neural network. Processes a sequence one step at a time, carrying a hidden state forward. Stepping through that state sequentially is hard to parallelize, part of why attention displaced it., TransformerThe architecture built on self-attention (block 03). Every token attends to every other token in the window, computed in parallel rather than stepped through sequentially like an RNN., state-spaceState-space model. Processes a sequence through a compressed, continuously updated state, built for the parallel training and long-context efficiency that made Transformers dominant. Mamba is a current example., mixture-of-expertsA layer made of several parallel sub-networks, the experts, plus a router that sends each token to only a few of them. Total parameter count grows while inference cost stays close to that of a much smaller model.: different shapes, same job. Inference is running the fitted function. Fine-tuning is a smaller write to the same parameters.

A new architecture is a new parameterization of the same problem. The relevant questions are inductive bias, training cost, and inference cost. Alignment and instruction tuning change the objective, not the kind of object being optimized.

Figure

FitLossdatastep 0, referencestep ≈20, referencestep 200, referencehigh0200 steps

Step 0 of 200 · barely trained, gradients just started

Drag the slider to scrub through training steps.

Thirteen points, one hidden pattern, and now a dial to move through the fit. Near step 0 the curve sits close to flat: no gradients have been applied yet. Somewhere around step 20 to 40 it grows a rough hump, underfit but pointed the right way. By step 200 it tracks the data closely, and the loss curve on the right, the same run, the same steps, drops from high and flattens near its floor at exactly the same moment. Three faint curves stay in place at step 0, step 20, and step 200, marking the fixed snapshots this figure showed before it could move.

Algorithms

Three families of optimizer do the walking that turns a computed gradient into an updated parameter. Each answers the same question, how far to step and in what direction, with a different tradeoff among speed, memory, and stability.

Reference

In practice

A model is a fitted function. Inference is running that function. The following systems are that job under different inputs and losses.

Laboratory

One training loop, two function shapes

In numpy (or a thin autograd), implement SGD on a tiny MLP that fits a known function (a 2D surface, a toy classifier). Then swap the MLP for a small attention block, or a tiny conv net, without changing the training loop: batch, loss, backward, step. Plot train and held-out loss for both shapes.