Training at scale, generalization & characterizing units

Reader-friendly version of the 54 lecture slides: the lecture content in normal flow, with figure descriptions and data tables where the figure carries data. Open the presentation.

Slide 1

Brown University crest
CPSY 1291 Computational Methods for Mind, Brain & Behavior
Lecture 10 · Theme 2: Learning representations: from neurons to deep networks

Training at scale, generalization & characterizing units

Thursday, October 15 · Fall 2026

Return to contents

Slide 2

Last lecture: hidden layers and backpropagation

A fully connected network drawn left to right: inputs x1 to xD, hidden layer 1, hidden layer 2 and an output layer y-hat. Every unit connects to every unit of the next layer; the weight matrices W superscript 1, 2 and 3 label the gaps

A fully connected network drawn left to right: inputs x1 to xD, hidden layer 1, hidden layer 2 and an output layer y-hat. Every unit connects to every unit of the next layer; the weight matrices W superscript 1, 2 and 3 label the gaps

Open full-size figure
  • Hidden layers re-represent the inputs, so a readout can separate classes that no single line separates, as in XOR
  • Backpropagation gives the gradient of the loss for every weight: error at the output, sent backward, error × activity
  • The training loop: forward pass, loss, backward(), step(), repeated over epochs
  • Each step of gradient descent used all the training images and a fixed learning rate η\eta

Return to contents

Slide 3

Today: three questions about a trained network

Return to contents

Slide 4

Today's three examples

Contour plot of the loss of a linear neuron with two weights, w1 and w2, with a gradient-descent path from a start point to the lowest loss

Contour plot of the loss of a linear neuron with two weights, w1 and w2, with a gradient-descent path from a start point to the lowest loss

Open full-size figure

The two-weight neuron
24 simulated examples

Two panels: a degree-3 polynomial that follows the sine curve through 10 noisy points, and a degree-9 polynomial that passes through every point and swings far off between them; under each, its training and test RMSE

Two panels: a degree-3 polynomial that follows the sine curve through 10 noisy points, and a degree-9 polynomial that passes through every point and swings far off between them; under each, its training and test RMSE

Open full-size figure

The curve fit
10 noisy points of a sine curve

A grid of grayscale renderings, one row per category (animal, vehicle, face, vegetable or fruit, house, man-made object), each with two objects seen from three of their 24 viewpoints

A grid of grayscale renderings, one row per category (animal, vehicle, face, vegetable or fruit, house, man-made object), each with two objects seen from three of their 24 viewpoints

Open full-size figure

The IT readout
100 IT sites, six object categories

Return to contents

Slide 5

The IT readout, in full

A grid of grayscale renderings, one row per category (animal, vehicle, face, vegetable or fruit, house, man-made object), each with two objects seen from three of their 24 viewpoints

A grid of grayscale renderings, one row per category (animal, vehicle, face, vegetable or fruit, house, man-made object), each with two objects seen from three of their 24 viewpoints

Open full-size figure
  • Recordings: neurons in monkey inferotemporal cortex (IT), the object-recognition area (Bao et al. 2020), the data of the first two assignments
  • Images: 51 objects × 24 views = 1,224, in six categories (rows of the grid)
  • Input: each image's average response at 100 IT sites: 100 numbers. Output: its category, one of 6 (chance: 1 in 6)
  • Every readout today learns this same mapping, from a logistic regression to a small network

Return to contents

Slide 6

How do we train on a million images?

Last lecture, every step used all the training images. That is slow, and they do not fit in memory at once

Return to contents

Slide 7

One example, all of them, or a few at a time?

  • One step updates every weight once, using the loss averaged over the examples it is computed on
  • Online, one example per step, like the perceptron and the delta rule: cheap steps, but each gradient is very noisy
  • Full batch, all NN examples per step, like last lecture's loop: an exact gradient, but one step per pass, and a million images do not fit in memory
  • Minibatch, BB examples per step (often 32 to 256): each epoch, shuffle the examples and split them into groups of BB, one step per group. Many cheap steps per pass, so far fewer passes
Twelve numbered training examples in order, then the same twelve shuffled, then cut into three batches of four; each batch is one step, and the three steps make one epoch; the next epoch shuffles again

Twelve numbered training examples in order, then the same twelve shuffled, then cut into three batches of four; each batch is one step, and the three steps make one epoch; the next epoch shuffles again

Open full-size figure

Return to contents

Slide 8

Three tips for training your own network

Shrink the learning rate as training goes · Average the gradients: momentum and Adam · Sweep the learning rate first

Return to contents

Slide 9

Tip 1: shrink the learning rate as training goes

Two contour plots of last lecture's two-weight loss, with identical axes, each showing 600 minibatch updates from the same start using the same batches of two examples. Left, constant step size 0.8: the last 300 steps scatter widely around the star that marks the lowest loss, mean distance 0.12. Right, a step that shrinks as 0.8 divided by 1 plus t over 20: the last 300 steps sit in a tight cluster on the star, mean distance 0.01. Faint trails enter from the start, which lies off the plotted area

Two contour plots of last lecture's two-weight loss, with identical axes, each showing 600 minibatch updates from the same start using the same batches of two examples. Left, constant step size 0.8: the last 300 steps scatter widely around the star that marks the lowest loss, mean distance 0.12. Right, a step that shrinks as 0.8 divided by 1 plus t over 20: the last 300 steps sit in a tight cluster on the star, mean distance 0.01. Faint trails enter from the start, which lies off the plotted area

Open full-size figure

Return to contents

Slide 10

Tip 2: average the gradients (momentum)

Contours of the squared-error loss of the two-weight neuron, weight w1 horizontal and w2 vertical on equal scales, with its second input on a scale five times larger, so the loss is a long narrow valley running along w1. From the same start, 40 steps each at the same learning rate: plain gradient descent zigzags up and down across the valley; momentum swings in a few slow, smooth waves along it toward the lowest loss. Up-and-down travel along w2: 4.4 for plain descent, 0.8 for momentum

Contours of the squared-error loss of the two-weight neuron, weight w1 horizontal and w2 vertical on equal scales, with its second input on a scale five times larger, so the loss is a long narrow valley running along w1. From the same start, 40 steps each at the same learning rate: plain gradient descent zigzags up and down across the valley; momentum swings in a few slow, smooth waves along it toward the lowest loss. Up-and-down travel along w2: 4.4 for plain descent, 0.8 for momentum

Open full-size figure

Return to contents

Slide 11

Tip 2, continued: Adam, a step size for each weight

The same valley of the two-weight neuron and the same start, w1 horizontal and w2 vertical. Plain gradient descent zigzags faintly in the background; momentum swings in slow waves as on the previous slide; Adam follows one smoother curve down the valley to the lowest loss. Up-and-down travel along w2: plain 4.4, momentum 0.8, Adam 0.6

The same valley of the two-weight neuron and the same start, w1 horizontal and w2 vertical. Plain gradient descent zigzags faintly in the background; momentum swings in slow waves as on the previous slide; Adam follows one smoother curve down the valley to the lowest loss. Up-and-down travel along w2: plain 4.4, momentum 0.8, Adam 0.6

Open full-size figure

Return to contents

Slide 12

Adam: the update

𝐦←β1𝐦+(1−β1) ∇L,𝐯←β2𝐯+(1−β2) (∇L)2,θ←θ−η 𝐦𝐯+ϵ\mathbf{m}\leftarrow\beta_1\mathbf{m}+(1-\beta_1)\,\nabla\mathcal{L},\qquad \mathbf{v}\leftarrow\beta_2\mathbf{v}+(1-\beta_2)\,(\nabla\mathcal{L})^2,\qquad \boldsymbol{\theta}\leftarrow\boldsymbol{\theta}-\eta\,\frac{\mathbf{m}}{\sqrt{\mathbf{v}}+\epsilon}

θ: all weights and biases · operations are per weight · Adam's first-step correction omitted

Return to contents

Slide 13

Tip 3: sweep the learning rate first

Training loss on a log scale against epoch for four learning rates of one network reading the six object categories from 100 monkey IT sites. At 10 to the minus 5, dotted grey, the loss barely falls (test accuracy 0.18); at 10 to the minus 3, dashed blue, it falls slowly (test 0.62); at 0.1, solid magenta, it falls to about 0.015 (test 0.91); at 3, dash-dotted black, it jumps off the top of the axis in the first epoch and diverges

Training loss on a log scale against epoch for four learning rates of one network reading the six object categories from 100 monkey IT sites. At 10 to the minus 5, dotted grey, the loss barely falls (test accuracy 0.18); at 10 to the minus 3, dashed blue, it falls slowly (test 0.62); at 0.1, solid magenta, it falls to about 0.015 (test 0.91); at 3, dash-dotted black, it jumps off the top of the axis in the first epoch and diverges

Open full-size figure
  • The IT readout with a small network: 100 IT responses → 64 hidden units (ReLU) → 6 outputs. Training loss: cross-entropy
  • Plain gradient steps; four runs differing only in η\eta
  • Too small: the loss barely moves. Too large: it explodes
  • η\eta is a hyperparameter, set by us. Good values span orders of magnitude: sweep on a log scale

Return to contents

Slide 14

Does what a network learned hold for images it never saw?

Generalization: when does a trained network's fit carry over to new data, and how do we make it?

Return to contents

Slide 15

Recall: train on some images, test on others

Two panels for a readout of animate versus inanimate from 480 monkey IT neurons, trained on 102 images and tested on 306. Left: accuracy bars; with true labels, training 1.00 and test 0.96; with shuffled training labels, training 1.00 and test 0.56 on average, below a dashed majority-class line at 0.63. Right: histogram of the test accuracy over 1,000 label shuffles, centred near 0.55, with its 95th percentile marked near 0.67 and the true-label test accuracy, 0.96, far to the right

Two panels for a readout of animate versus inanimate from 480 monkey IT neurons, trained on 102 images and tested on 306. Left: accuracy bars; with true labels, training 1.00 and test 0.96; with shuffled training labels, training 1.00 and test 0.56 on average, below a dashed majority-class line at 0.63. Right: histogram of the test accuracy over 1,000 label shuffles, centred near 0.55, with its 95th percentile marked near 0.67 and the true-label test accuracy, 0.96, far to the right

Open full-size figure

Return to contents

Slide 16

A perfect training score can hide poor generalization

Two panels for a readout of animate versus inanimate from 480 monkey IT neurons, trained on 102 images and tested on 306. Left: accuracy bars; with true labels, training 1.00 and test 0.96; with shuffled training labels, training 1.00 and test 0.56 on average, below a dashed majority-class line at 0.63. Right: histogram of the test accuracy over 1,000 label shuffles, centred near 0.55, with its 95th percentile marked near 0.67 and the true-label test accuracy, 0.96, far to the right

Two panels for a readout of animate versus inanimate from 480 monkey IT neurons, trained on 102 images and tested on 306. Left: accuracy bars; with true labels, training 1.00 and test 0.96; with shuffled training labels, training 1.00 and test 0.56 on average, below a dashed majority-class line at 0.63. Right: histogram of the test accuracy over 1,000 label shuffles, centred near 0.55, with its 95th percentile marked near 0.67 and the true-label test accuracy, 0.96, far to the right

Open full-size figure

Return to contents

Slide 17

Training fits a function from inputs to outputs

A model neuron with two inputs, x1 and x2, with weights w1 and w2, summed with a bias b into z, passed through the nonlinearity g, giving the output a = g(w1 x1 + w2 x2 + b)

A model neuron with two inputs, x1 and x2, with weights w1 and w2, summed with a bias b into z, passed through the nonlinearity g, giving the output a = g(w1 x1 + w2 x2 + b)

Open full-size figure
  • A neuron, a readout or a network computes an output from an input: y^=f(𝐱;θ)\hat y = f(\mathbf{x};\textcolor{#B5396B}{\boldsymbol\theta})
  • Training chooses the parameters θ\textcolor{#B5396B}{\boldsymbol\theta} so that y^\hat y matches yy on the training pairs (𝐱,y)(\mathbf{x}, y)
  • Generalization asks whether ff is also right for inputs it never saw
  • With hundreds of inputs we cannot draw ff; with one input we can

Return to contents

Slide 18

Too rigid, or too flexible

Computed: 10 noisy samples of a sine curve, after Bishop (2006), Fig. 1.4

Four panels, each with the same 10 magenta points scattered around a dashed sine-shaped curve, and a blue fitted curve. Degree 0: a flat line, training error 0.63, error on new points 0.76. Degree 1: a falling straight line, 0.48 and 0.56. Degree 3: a curve close to the dashed one, 0.19 and 0.33. Degree 9: a curve through every point that swings far off between and beyond them, training error 0.00, error on new points 0.86. Open green circles: 25 of the new points the error on new points is measured on

Four panels, each with the same 10 magenta points scattered around a dashed sine-shaped curve, and a blue fitted curve. Degree 0: a flat line, training error 0.63, error on new points 0.76. Degree 1: a falling straight line, 0.48 and 0.56. Degree 3: a curve close to the dashed one, 0.19 and 0.33. Degree 9: a curve through every point that swings far off between and beyond them, training error 0.00, error on new points 0.86. Open green circles: 25 of the new points the error on new points is measured on

Open full-size figure

Return to contents

Slide 19

Same model, more examples

Computed: the same curve and noise, after Bishop (2006), Fig. 1.6

Four panels of the same degree-9 polynomial fitted to more and more noisy points from the dashed sine-shaped curve. N equals 10: the curve swings far off, error on new points 0.86. N equals 15: close to the dashed curve, 0.34. N equals 30: 0.35. N equals 100: the fitted curve follows the dashed one, training error 0.28, error on new points 0.31. Open green circles: 25 of the new points the error on new points is measured on

Four panels of the same degree-9 polynomial fitted to more and more noisy points from the dashed sine-shaped curve. N equals 10: the curve swings far off, error on new points 0.86. N equals 15: close to the dashed curve, 0.34. N equals 30: 0.35. N equals 100: the fitted curve follows the dashed one, training error 0.28, error on new points 0.31. Open green circles: 25 of the new points the error on new points is measured on

Open full-size figure

Return to contents

Slide 20

How do we choose a model and measure how well it generalizes?

Every choice made while looking at a score can fit that score's images

Return to contents

Slide 21

Three data splits

A horizontal bar split into three parts. Training, the largest part, in magenta: fit the weights. Validation, in green: choose settings and when to stop. Test, in dark grey: report once, at the end

A horizontal bar split into three parts. Training, the largest part, in magenta: fit the weights. Validation, in green: choose settings and when to stop. Test, in dark grey: report once, at the end

Open full-size figure

Return to contents

Slide 22

Cross-validation: each example validates once

Five rows, fold 1 to fold 5, each showing the training data cut into five equal parts: one part in green, a different one in each row, the other four in magenta; each row ends in its own score. A separate dark block on the right is the test set, set aside and used once. Caption: train on the magenta parts, score on the green one; the cross-validation score is the mean of the five scores

Five rows, fold 1 to fold 5, each showing the training data cut into five equal parts: one part in green, a different one in each row, the other four in magenta; each row ends in its own score. A separate dark block on the right is the test set, set aside and used once. Caption: train on the magenta parts, score on the green one; the cross-validation score is the mean of the five scores

Open full-size figure

Return to contents

Slide 23

Learning curves: when to stop training

Two panels against epoch, 0 to 400, for a network reading out the six object categories from 100 monkey IT sites, trained on 300 images with a fifth of their labels redrawn at random. Left, loss: training loss in magenta falls to near 0; validation loss in green is lowest near epoch 20, about 0.56, then rises to about 0.97. Right, accuracy: training accuracy rises to 1.0; validation accuracy is highest, 0.82, at epoch 8, marked by a dashed line labelled checkpoint kept, and drifts down to about 0.78. A dotted line marks chance, one in six

Two panels against epoch, 0 to 400, for a network reading out the six object categories from 100 monkey IT sites, trained on 300 images with a fifth of their labels redrawn at random. Left, loss: training loss in magenta falls to near 0; validation loss in green is lowest near epoch 20, about 0.56, then rises to about 0.97. Right, accuracy: training accuracy rises to 1.0; validation accuracy is highest, 0.82, at epoch 8, marked by a dashed line labelled checkpoint kept, and drifts down to about 0.78. A dotted line marks chance, one in six

Open full-size figure

Return to contents

Slide 24

Why stop before the bottom of the training loss?

Left: the curve fit's 10 training points and the dashed sine curve, with a degree-9 polynomial trained by gradient descent shown at three moments: after 10 steps, a smooth curve that is still too flat; after 1,467 steps, a curve close to the sine; after 10 to the 10 steps, the curve that passes through every point and swings far off between them. Right: training RMSE and test RMSE against gradient steps on a log axis; training RMSE falls to zero, test RMSE is lowest, 0.33, at step 1,467, marked stop, and rises to 0.86

Left: the curve fit's 10 training points and the dashed sine curve, with a degree-9 polynomial trained by gradient descent shown at three moments: after 10 steps, a smooth curve that is still too flat; after 1,467 steps, a curve close to the sine; after 10 to the 10 steps, the curve that passes through every point and swings far off between them. Right: training RMSE and test RMSE against gradient steps on a log axis; training RMSE falls to zero, test RMSE is lowest, 0.33, at step 1,467, marked stop, and rises to 0.86

Open full-size figure

Return to contents

Slide 25

A test accuracy from few images is imprecise

Test accuracy of the running readout, six categories from 100 monkey IT sites, against the number of test images, 25 to 800, on a log axis. Each point has a vertical bootstrap interval. With 25 test images the interval runs from 0.76 to 1.00; with 800, from 0.83 to 0.88. A dashed line marks the accuracy on all 924 other images, 0.86

Test accuracy of the running readout, six categories from 100 monkey IT sites, against the number of test images, 25 to 800, on a log axis. Each point has a vertical bootstrap interval. With 25 test images the interval runs from 0.76 to 1.00; with 800, from 0.83 to 0.88. A dashed line marks the accuracy on all 924 other images, 0.86

Open full-size figure
  • The IT readout as a logistic regression, trained on 300 images; the dashed line is its accuracy on all 924 other images (0.86)
  • The bootstrap (baselines lecture): resample the test images with replacement; the middle 95% of the accuracies is a 95% confidence interval
  • With 25 test images, the accuracy could be anywhere from 0.76 to 1.00; with 800, from 0.83 to 0.88
  • Compare models on enough test images that their intervals do not overlap

Return to contents

Slide 26

Shortcut learning: texture over shape

Reproduced from Geirhos et al. 2019, Fig. 1: three images with ResNet-50's top three answers. (a) A texture image of elephant skin: Indian elephant 81.4 percent, indri 10.3, black swan 8.2. (b) A photograph of a tabby cat: tabby cat 71.1 percent, grey fox 17.3, Siamese cat 3.3. (c) The cat's shape with elephant-skin texture, a texture-shape cue conflict: Indian elephant 63.9 percent, indri 26.4, black swan 9.6

Reproduced from Geirhos et al. 2019, Fig. 1: three images with ResNet-50's top three answers. (a) A texture image of elephant skin: Indian elephant 81.4 percent, indri 10.3, black swan 8.2. (b) A photograph of a tabby cat: tabby cat 71.1 percent, grey fox 17.3, Siamese cat 3.3. (c) The cat's shape with elephant-skin texture, a texture-shape cue conflict: Indian elephant 63.9 percent, indri 26.4, black swan 9.6

Open full-size figure

Return to contents

Slide 27

How do we make a network generalize better?

A penalty on the weights, more data, and switching units off

Return to contents

Slide 28

A penalty on the weights

L(θ)  =  Ltrain(θ)⏟fit  +    λ∥θ∥2⏟strength    ∥θ∥2⏟size of the parameters\mathcal{L}(\textcolor{#B5396B}{\boldsymbol\theta}) \;=\; \underbrace{\mathcal{L}_{\text{train}}(\textcolor{#B5396B}{\boldsymbol\theta})}_{\text{fit}} \;+\;\; \underbrace{\lambda\vphantom{\lVert\textcolor{#B5396B}{\boldsymbol\theta}\rVert^2}}_{\text{strength}}\;\;\underbrace{\lVert\textcolor{#B5396B}{\boldsymbol\theta}\rVert^2}_{\text{size of the parameters}}

Computed: the curve fit's 10 points, after Bishop (2006), Fig. 1.7

Four panels of the degree-9 polynomial fitted to the same 10 points, with an increasing penalty. No penalty: through every point, swinging far off, error on new points 0.86. Lambda 10 to the minus 7: a smooth curve close to the dashed one, 0.34. Lambda 10 to the minus 3: smooth, 0.34. Lambda 1: an almost flat line, training error 0.49, error on new points 0.61. Open green circles: 25 of the new points the error on new points is measured on

Four panels of the degree-9 polynomial fitted to the same 10 points, with an increasing penalty. No penalty: through every point, swinging far off, error on new points 0.86. Lambda 10 to the minus 7: a smooth curve close to the dashed one, 0.34. Lambda 10 to the minus 3: smooth, 0.34. Lambda 1: an almost flat line, training error 0.49, error on new points 0.61. Open green circles: 25 of the new points the error on new points is measured on

Open full-size figure

Return to contents

Slide 29

Without a penalty, a readout's weights keep growing

Two panels for the running readout, six categories from 100 IT sites, as a logistic regression trained on 300 images. Left: the size of the weights against gradient steps on a log axis; without a penalty it keeps rising, to about 10.7; with weight decay it levels off near 3.5. Right: the training cross-entropy on a log axis; without a penalty it falls toward zero, to 0.0015; with weight decay it levels off near 0.11

Two panels for the running readout, six categories from 100 IT sites, as a logistic regression trained on 300 images. Left: the size of the weights against gradient steps on a log axis; without a penalty it keeps rising, to about 10.7; with weight decay it levels off near 3.5. Right: the training cross-entropy on a log axis; without a penalty it falls toward zero, to 0.0015; with weight decay it levels off near 0.11

Open full-size figure

Return to contents

Slide 30

More data, or altered copies of it

Four versions of one photograph of a pink orchid: the original; flipped left to right; cropped and enlarged; and with its colour faded and raised

Four versions of one photograph of a pink orchid: the original; flipped left to right; cropped and enlarged; and with its colour faded and raised

Open full-size figure

Return to contents

Slide 31

Regularization: penalties and dropout

Three copies of the same small network: in the first two, a different random half of the hidden units is switched off for one training step each, with their connections removed; in the third, at test time, all units are on

Three copies of the same small network: in the first two, a different random half of the hidden units is switched off for one training step each, with their connections removed; in the third, at test time, all units are on

Open full-size figure

Return to contents

Slide 32

Try it: overfit, then regularize

Return to contents

Slide 33

A model of a neuron: regression with a penalty

Two panels for one monkey IT recording site and 512 features of the trained network's late layer. Left: predicted against recorded responses for a ridge fit; training images faint grey, held-out images red, both scattered along the diagonal, R-squared 0.71 on training and 0.69 on held-out images. Right: R-squared against the penalty lambda on a log axis; with almost no penalty, training R-squared is 0.85 and held-out R-squared 0.28; as the penalty grows, training R-squared falls while held-out R-squared rises to meet it near 0.69 at the penalty chosen on the training images, then both fall

Two panels for one monkey IT recording site and 512 features of the trained network's late layer. Left: predicted against recorded responses for a ridge fit; training images faint grey, held-out images red, both scattered along the diagonal, R-squared 0.71 on training and 0.69 on held-out images. Right: R-squared against the penalty lambda on a log axis; with almost no penalty, training R-squared is 0.85 and held-out R-squared 0.28; as the penalty grows, training R-squared falls while held-out R-squared rises to meet it near 0.69 at the penalty chosen on the training images, then both fall

Open full-size figure

Computed: one monkey IT site (Bao et al. 2020), 1,224 object images, 512 late-layer units of ResNet-18; a random fifth held out

Return to contents

Slide 34

Does a trained network see like the visual cortex?

Nobody told AlexNet about V1. Measure its units the way physiologists measure neurons, and compare

Return to contents

Slide 35

What a trained network's first layer learns

First-layer weights of AlexNet shown as small color images: oriented edges, stripe patterns and color blobs

First-layer weights of AlexNet shown as small color images: oriented edges, stripe patterns and color blobs

Open full-size figure
  • AlexNet, trained to label 1.2 million photos, was never shown a receptive field
  • Its first-layer filters, each drawn as a small image: oriented edges, stripes, colour blobs
  • Do these look like the receptive fields of V1 cells? And how would we measure "look like"?

Return to contents

Slide 36

Real V1 receptive fields look like Gabors

Reproduced from Ringach 2002, Fig. 2: six macaque V1 simple cells in three blocks. Each row shows the measured receptive field (Data), the best-fitting two-dimensional Gabor (Fit) and what is left over (Residual). The fields range from round blobs to elongated stripes of alternating sign; each fit reproduces its field's shape, and the residuals are faint, unstructured speckle. A colour bar runs from minus 1, blue, through 0, green, to plus 1, red

Reproduced from Ringach 2002, Fig. 2: six macaque V1 simple cells in three blocks. Each row shows the measured receptive field (Data), the best-fitting two-dimensional Gabor (Fit) and what is left over (Residual). The fields range from round blobs to elongated stripes of alternating sign; each fit reproduces its field's shape, and the residuals are faint, unstructured speckle. A colour bar runs from minus 1, blue, through 0, green, to plus 1, red

Open full-size figure

Return to contents

Slide 37

The Gabor function, fitted, and two numbers from it

G(x,y)=A exp⁡ ⁣(−x′22σx2−y′22σy2)cos⁡ ⁣(2πfx′+ϕ)G(x,y)=A\,\exp\!\Big(-\frac{x'^2}{2\sigma_x^2}-\frac{y'^2}{2\sigma_y^2}\Big)\cos\!\big(2\pi f x'+\phi\big)

Left, a toy receptive field with pixel noise, the Gabor fitted to it, and the residual, which is only noise; R-squared 0.87. Right, three noise-free toy Gabors: A with nx 0.20 and ny 0.20, a small spot; B with nx 0.35 and ny 0.50, a few short stripes; C with nx 0.90 and ny 1.20, many long stripes

Left, a toy receptive field with pixel noise, the Gabor fitted to it, and the residual, which is only noise; R-squared 0.87. Right, three noise-free toy Gabors: A with nx 0.20 and ny 0.20, a small spot; B with nx 0.35 and ny 0.50, a few short stripes; C with nx 0.90 and ny 1.20, many long stripes

Open full-size figure

Return to contents

Slide 38

Where do V1 simple cells sit?

Scatter of Gabor width nx against length ny, both in cycles, for 93 macaque V1 simple cells: most cluster near the origin, below about 0.6 on both axes, with a few longer fields. Three blue stars mark the toy units A, B and C of the Gabor-fit slide: A and B sit among the cells, C lies beyond most of them

Scatter of Gabor width nx against length ny, both in cycles, for 93 macaque V1 simple cells: most cluster near the origin, below about 0.6 on both axes, with a few longer fields. Three blue stars mark the toy units A, B and C of the Gabor-fit slide: A and B sit among the cells, C lies beyond most of them

Open full-size figure
  • Ringach (2002) fit Gabors to 93 simple cells of macaque V1 (cells that respond to a grating only at some phases) and released the fits
  • Most cells sit below 0.6 on both axes (medians 0.32 and 0.41): a window of one or two stripes
  • Toy unit C, with many long stripes, lies beyond most real cells
  • The same two numbers can place any receptive field on this plot, a network unit's included

Return to contents

Slide 39

Quantified: V1 cells and AlexNet's first layer

The same scatter and axes as the previous slide, with the toy units removed: macaque V1 simple cells as grey squares near the origin, and AlexNet's first-layer filters that a Gabor fits well as open green circles; the filters overlap the cells but sit systematically larger

The same scatter and axes as the previous slide, with the toy units removed: macaque V1 simple cells as grey squares near the origin, and AlexNet's first-layer filters that a Gabor fits well as open green circles; the filters overlap the cells but sit systematically larger

Open full-size figure
  • Filled squares: macaque V1 simple cells. Open circles: AlexNet's first-layer filters, each fit by a Gabor
  • The same two numbers place a cell and a network unit on one plot
  • Do the network's filters look like V1 cells, and where do they differ?

Return to contents

Slide 40

What does a unit respond to? Its tuning curve

Top: the weights of four hand-built units, three Gabors at different orientations and window lengths, labelled with orientation selectivity indices 1.00, 1.00 and 0.90, and a centre-surround unit with index 0.00. Bottom: their tuning curves to gratings at 24 orientations, each scaled to its peak; the three Gabors peak at different orientations, the long one narrowly, the short one broadly, and the centre-surround unit is flat

Top: the weights of four hand-built units, three Gabors at different orientations and window lengths, labelled with orientation selectivity indices 1.00, 1.00 and 0.90, and a centre-surround unit with index 0.00. Bottom: their tuning curves to gratings at 24 orientations, each scaled to its peak; the three Gabors peak at different orientations, the long one narrowly, the short one broadly, and the centre-surround unit is flat

Open full-size figure
  • Hubel and Wiesel's method: show gratings (stripes) at many orientations and record the response. Here, four units built by hand, so we can check the method
  • Top: each unit's weights, its receptive field: three Gabors and a round centre-surround unit
  • Orientation selectivity index (OSI), (max − min) / (max + min) of the responses: near 1 when the weakest response is near zero. Bandwidth: the half-width of the tuning curve at half its height
  • A and C both have indices near 1, yet C is far more broadly tuned: the index does not measure tuning width

Return to contents

Slide 41

Why rectify before averaging over phase?

Bar chart for one Gabor unit and a grating at its preferred orientation shown at four phases: the weighted sums are plus one, plus one, minus one, minus one and average to zero; after rectifying, the responses are one, one, zero, zero and average to one half. Thumbnails of the four gratings and of the unit's weights sit under the bars

Bar chart for one Gabor unit and a grating at its preferred orientation shown at four phases: the weighted sums are plus one, plus one, minus one, minus one and average to zero; after rectifying, the responses are one, one, zero, zero and average to one half. Thumbnails of the four gratings and of the unit's weights sit under the bars

Open full-size figure

Return to contents

Slide 42

Deeper in: how selective is one IT site for objects?

Responses of two IT sites to 51 objects, 24 views each: dots for single views, bars for object means. Site A, object selectivity index 0.60, has object means that differ widely, highest for a swan, shown as a thumbnail; site B, index 0.22, has object means that barely differ compared with the spread of the views

Responses of two IT sites to 51 objects, 24 views each: dots for single views, bars for object means. Site A, object selectivity index 0.60, has object means that differ widely, highest for a swan, shown as a thumbnail; site B, index 0.22, has object means that barely differ compared with the spread of the views

Open full-size figure
  • Past the first layer, weights no longer look like images: measure selectivity from responses alone. Show each of 51 objects from 24 views (the images of the first assignments); split one IT site's variance into between objects and within an object
  • Object selectivity index = between / total: near 1 when the response depends on which object, near 0 when the object means barely differ compared with the spread of the views
  • Site A: the bars (one per object, its mean over 24 views) differ much more than the views of one object do: 0.60. Site B: the bars are nearly level and the views vary as much: 0.22
  • This ranks units by how they respond. Whether a unit is needed is another measurement: next slide

Return to contents

Slide 43

Is a selective unit needed? Remove it and see

Return to contents

Slide 44

Recap

Return to contents

Slide 45

Further reading for the research trail

Optional: a few research-trail entries over the semester. Any paper mentioned in any lecture qualifies.

Return to contents

Slide 46

Minute paper

Submit on Canvas → Minute papers → Minute Paper 11 (access code read out in class).

Write three brief points in your own words:

  1. In plain words: how can a readout score 100% on its training images and still do poorly on new ones?
  2. Something you do not yet understand, or a question still open
  3. Another idea you found interesting, and why it matters for brains, behavior or AI

Credit for a thoughtful attempt, not for being correct.

Return to contents

Slide 47

Appendix

Slides cut from the lecture for time: schedules, bias and variance, many dimensions, five-photo results, the PyTorch checkpoint loop

Return to contents

Slide 48

Four ways to shrink the learning rate

Two stacked panels. Top: the learning rate against step for four schedules: constant, step decay that halves it at fixed intervals, 1 over 1 plus t over tau, and cosine decay. Bottom: the training loss for each; the shrinking schedules settle lower and more smoothly than the constant one

Two stacked panels. Top: the learning rate against step for four schedules: constant, step decay that halves it at fixed intervals, 1 over 1 plus t over tau, and cosine decay. Bottom: the training loss for each; the shrinking schedules settle lower and more smoothly than the constant one

Open full-size figure
  • One readout, trained four times with the same minibatches; only the schedule of η\eta differs. Top: the step size at each step. Bottom: the training loss
  • Constant never changes. Step decay halves η\eta every 200 steps. Cosine lowers it smoothly to near 0. 1/(1+t/τ)1/(1+t/\tau) shrinks it a little at every step
  • Inset, last 200 steps: every shrinking schedule ends steadier than the constant step
  • A common recipe for image networks: start at 0.1 and divide by 10 every 30 epochs, or follow a cosine

Return to contents

Slide 49

Same model, different training sets

Computed: the polynomial example; 20 fits shown, numbers from 2,000 training sets

Three panels, each with 20 thin blue curves fitted to 20 training sets of 10 noisy points, their average in red, and the true curve dashed. Degree 1, too simple: the lines agree with each other but their average misses the curve; the gap between the average and the true curve is shaded and labelled bias. Degree 3, about right: the fits cluster tightly around the true curve. Degree 9, too flexible: the average lies on the true curve but the individual fits swing wildly

Three panels, each with 20 thin blue curves fitted to 20 training sets of 10 noisy points, their average in red, and the true curve dashed. Degree 1, too simple: the lines agree with each other but their average misses the curve; the gap between the average and the true curve is shaded and labelled bias. Degree 3, about right: the fits cluster tightly around the true curve. Degree 9, too flexible: the average lies on the true curve but the individual fits swing wildly

Open full-size figure

Return to contents

Slide 50

Bias and variance

E[(y−y^)2]=(f(x)−E[y^])2⏟bias2+E[(y^−E[y^])2]⏟variance+σnoise2,y=f(x)+noise\mathbb{E}\big[(y-\hat y)^2\big] = \underbrace{\textcolor{#B5396B}{\big(f(x)-\mathbb{E}[\hat y]\big)^2}}_{\textcolor{#B5396B}{\text{bias}^2}} + \underbrace{\textcolor{#3F7A6B}{\mathbb{E}\big[(\hat y-\mathbb{E}[\hat y])^2\big]}}_{\textcolor{#3F7A6B}{\text{variance}}} + \sigma^2_{\text{noise}}, \qquad y = f(x) + \text{noise}

Squared error against the degree of the polynomial, 0 to 9. Bias squared in magenta falls from 0.50 at degree 0 to near 0 from degree 3 on. Variance in green rises slowly, then steeply to 0.55 at degree 9. Their sum plus the noise, in dark ink, is U-shaped, lowest at degree 3, 0.13. A dotted line marks the noise, 0.09

Squared error against the degree of the polynomial, 0 to 9. Bias squared in magenta falls from 0.50 at degree 0 to near 0 from degree 3 on. Variance in green rises slowly, then steeply to 0.55 at degree 9. Their sum plus the noise, in dark ink, is U-shaped, lowest at degree 3, 0.13. A dotted line marks the noise, 0.09

Open full-size figure

Computed: 2,000 training sets

  • ff: the true curve; y^\hat y: the fitted prediction at xx; E\mathbb{E} averages over training sets. σnoise2\sigma^2_{\text{noise}}: the noise variance, 0.302=0.090.30^2 = 0.09 (squared errors here, not RMSE)
  • Bias falls and variance rises with the degree: the best model balances the two, here at degree 3

Return to contents

Slide 51

Many dimensions, few examples

Accuracy against the number of input dimensions on a log axis, from 1 to 1024, with 100 training points. Training accuracy, in magenta, stays near 1.0 throughout. Accuracy on new points, in green, starts at 1.0 and falls to about 0.58 at 1024 dimensions; the shaded gap between the curves widens. A dashed line marks 100 dimensions, as many as training points

Accuracy against the number of input dimensions on a log axis, from 1 to 1024, with 100 training points. Training accuracy, in magenta, stays near 1.0 throughout. Accuracy on new points, in green, starts at 1.0 and falls to about 0.58 at 1024 dimensions; the shaded gap between the curves widens. A dashed line marks 100 dimensions, as many as training points

Open full-size figure
  • Simulated points: the label is the sign of the first input; every other input is random noise. A linear readout, 100 training points
  • Training accuracy stays near 1.0; accuracy on new points falls toward chance
  • The curse of dimensionality (baselines lecture): the examples needed grow quickly with the number of dimensions. With 1,024 weights and 100 examples, the readout fits the training labels partly through the noise dimensions
  • The fix: a representation, or a limit on the readout, that ignores the irrelevant dimensions

Return to contents

Slide 52

Learning a new category from five photos

Reproduced from Sorscher, Ganguli and Sompolinsky 2022, Fig. 1A and B. A: four photographs each of two animals the network was never trained on, a coati and a numbat, and a new photograph marked with a question mark. B: the primate ventral stream from the retina to IT drawn above a deep network trained on ImageNet; each image becomes a point in the network's feature space, the labelled examples of each animal are averaged into a prototype, and a straight boundary halfway between the two prototypes labels the new image

Reproduced from Sorscher, Ganguli and Sompolinsky 2022, Fig. 1A and B. A: four photographs each of two animals the network was never trained on, a coati and a numbat, and a new photograph marked with a question mark. B: the primate ventral stream from the retina to IT drawn above a deep network trained on ImageNet; each image becomes a point in the network's feature space, the labelled examples of each animal are averaged into a prototype, and a straight boundary halfway between the two prototypes labels the new image

Open full-size figure

Return to contents

Slide 53

Five photos are enough, in a good representation

Reproduced from Sorscher, Ganguli and Sompolinsky 2022: accuracy of the prototype readout on new categories against the number of examples per category, for the trained network, an untrained network and raw pixels, and the five-photo accuracy read from monkey IT and V4 recordings compared with network layers

Reproduced from Sorscher, Ganguli and Sompolinsky 2022: accuracy of the prototype readout on new categories against the number of examples per category, for the trained network, an untrained network and raw pixels, and the five-photo accuracy read from monkey IT and V4 recordings compared with network layers

Open full-size figure

Return to contents

Slide 54

In PyTorch: keep the best checkpoint

best_acc = -float("inf") # best validation accuracy so far for epoch in range(num_epochs): # one epoch = one pass over the training set model.train() # training mode (dropout on) for X, y in train_loader: # one minibatch at a time optimizer.zero_grad() # clear last step's gradients loss_fn(model(X), y).backward() # loss on this batch, then backprop optimizer.step() # update every weight model.eval() # evaluation mode (dropout off) with torch.no_grad(): # no gradients needed to score correct = sum((model(X).argmax(1) == y).sum().item() for X, y in val_loader) # count right answers val_acc = correct / len(val_loader.dataset) if val_acc > best_acc: # better than every earlier epoch? best_acc = val_acc torch.save(model.state_dict(), "best.pt") # save the weights: a checkpoint model.load_state_dict(torch.load("best.pt")) # end: reload the best weights

Return to contents