Introduction to
Neural Networks
November 12, 2026
Reading Handwritten Digits
Each image: 28 × 28 = 784 numbers.
Each pixel between 0 (paper) and 1 (ink).
4,000 training, 1,000 validation, 1,000 test images in this deck.
Start from logistic regression
Class $k$ has a weight vector $\cw{\btheta_k} \in \R^{784}$, one weight per pixel, and an intercept $\cw{b_k}$.
Its weight map: red pixels raise the score for $k$, blue lower it.
The softmax turns the ten scores into probabilities.
90% test accuracy. Each boundary between two classes is flat in $\cx{\bx}$.
A hidden layer learns features
Two inputs here instead of 784, so the boundary can be drawn.
$\ch{\bh}(\cx{\bx})$: the hidden layer's output, the learned features of $\cx{\bx}$.
Each hidden unit: a weighted sum, then $\varphi(z) = \max(0, z)$.
Its sum is zero along one line (small panels).
Softmax on $\ch{\bh}$: straight in $\ch{\bh}$, bent in $\cx{\bx}$.
Forward Pass
Pretrained: 64 ReLU units, 97% test accuracy.
Draw a digit: 784 inputs, 64 features, 10 probabilities.
The loss: negative log-likelihood
$\cp{p_{y_i}}$: the probability the network assigns to the true class.
Maximum likelihood, as in logistic regression.
A confident wrong answer costs the most: $-\log p \to \infty$ as $p \to 0$.
Accuracy cannot be the objective: its gradient is zero almost everywhere.
Learning: gradient descent
Not convex, 50,890 parameters, no closed form: take steps.
$-\cl{\nabla L}$ is the steepest way down near $\btheta$. It does not point at the minimum.
$\cl{\nabla L} = \mathbf{0}$ at every minimum, but also at saddle points.
Too small an $\eta$ is slow. Too large overshoots.
Backpropagation: the chain rule, organized
$z = \cw{\theta}\cx{x} + \cw{b}$, $\ch{a} = \sigma(z) = \frac{1}{1+e^{-z}}$, $L = -\log \ch{a}$ for $y = 1$.
Forward: each node from the nodes before it.
Backward: multiply local derivatives back to each weight.
Train on MNIST, live
Each step uses a random mini-batch of 32 images, and one epoch is one pass over the 4,000. The epoch is chosen on validation, and test is reported once.
What the hidden units learned
Each tile: one row of $\cw{\bTheta_1}$ as a 28 × 28 image.
Each weight map is concentrated on a stroke, not a whole digit.
Right: the validation digits that activate it, and its ten output weights.
Overfitting
500 images, 101,770 parameters: training hits 100%, validation stalls.
Remedies: more data, weight decay $\lambda$, early stopping on validation.
On this run, weight decay at these values does not help. 4,000 training images give 94% validation accuracy.
With its features fixed, a network is a weighting estimator
$\ch{\bh}(\bx)$: the 64 hidden features of $\bx$. $\ch{\tilde{\bh}}(\bx) = \ch{\bh}(\bx) - \ch{\bar{\bh}}$, where $\ch{\bar{\bh}}$ is their average over the $n = 4{,}000$ training images. $S = \sum_i \ch{\tilde{\bh}}(\bx_i)\,\ch{\tilde{\bh}}(\bx_i)^{\!\top} + \lambda I$. $Y_i$ is the one-hot label.
Freeze the features and ridge-regress the labels on them.
$w_i(\bx)$ ignores the labels: a linear smoother, like ridge and splines.
The $\tfrac{1}{n}$ makes the weights sum to one. Some are negative.
Summary and reading
A neuron: a weighted sum, then a nonlinearity.
A hidden layer learns features, and softmax regression uses them.
Training: gradient descent on the average negative log-likelihood.
Backpropagation: the chain rule, one backward pass.
Many parameters: validation set, weight decay, early stopping.
Reading: ISLR §10.1–10.2 and §10.7. Goodfellow, Bengio, Courville, Deep Learning (2016), ch. 6 and 8. Hastie, Tibshirani, Friedman, ESL, ch. 11. Nielsen, Neural Networks and Deep Learning (online).
Data: MNIST (LeCun, Cortes, Burges). Maths: KaTeX. Every figure is plain JavaScript in this folder. index_full.html has nine more slides.