A small team wants to read handwritten digits from 8 × 8 scans, a thousand of them. They have heard that convolutional networks are "better for images" and want to know why, and what could go wrong.
You'll work at teaching scale: small networks, a thousand images, CPU training in minutes. First, train a plain network and a CNN in Predict and compare them on held-out folds. Then check, by hand in a notebook, that backpropagation computes the gradients it claims to. Read which digits the CNN confuses. Then change one setting that tells the CNN how the pixels are laid out, and watch the advantage disappear while nothing reports an error. Finally, fit a variational autoencoder to the same pixels and see what a generative model learns.
Data: Optical recognition of handwritten digits (1,000 images, 8 × 8) · CC-BY-4.0. Alpaydin E, Kaynak C (1998). Optical Recognition of Handwritten Digits. UCI Machine Learning Repository. CC BY 4.0.
Predict digit from the 64 pixel columns. The sample also has a column odd, which is computed from the digit itself; as a feature it would hand the answer over. Train a torch MLP and a CNN on the same folds.
Which model does better on the held-out folds, and why might the image layout matter?
Open Predict in the sidebar.
Press New experiment, choose digits (sample) and press Create.
Set Target to digit, and make sure odd is not a feature.A column derived from the target makes the model look perfect in validation and useless on new scans, which don't come with that column.
Press Continue, keep the suggested validation plan, and press Continue again.
Select Deep neural network (torch MLP) and Convolutional neural network (CNN), then press Train.
Stage 2 · notebooks · ~15 min
Check the gradients by hand
A falling loss doesn't show that the backward pass is right. In the notebook, compare backpropagation with finite differences on a tiny network, then catch a backward pass that forgot the tanh derivative.
How large is the gap between the buggy gradients and the finite differences?
Notebook exercise: Check a network's gradients by hand. Compare backpropagation with finite differences on a tiny network, then catch a backward pass that forgot a derivative. 3 checks in Python or R.
Stage 3 · model · ~6 min
Read the errors
Open the CNN's run and its Evaluation tab. The confusion matrix shows which digits it mixes up on the held-out folds.
Which pairs of digits does the CNN confuse most, and do they look alike?
Open the CNN's run from the leaderboard, then its Evaluation tab.
Find the two digits the CNN confuses most often.
Stage 4 · model · ~6 min
Break the input contract
The CNN assumes the 64 columns are an 8 × 8 image read row by row. Tell it the image is 16 pixels wide instead and train it again. Nothing errors: the columns are still numbers. Only the scores show that the neighbors it convolves over are no longer neighbors.
What happened to the CNN's score, and why did no error warn you?
On the CNN's card, set Image width (pixels) to 16, then press Train.A shape that fits but means the wrong thing passes every type check. Only a check against the data's real layout, or a drop in held-out score, catches it.
Compare the two CNN runs on the leaderboard with the torch MLP.
Stage 5 · discover · ~9 min
What a generative model learns
Fit a variational autoencoder to the 64 pixels in Discover. It learns a small map of the images and can rebuild and generate digits; a good rebuild is not the same as good generated samples.
How do the rebuilt digits compare with the generated ones?
Open Discover, choose Map the data, choose digits (sample), and open the variational autoencoder.
Use the 64 pixel columns as features (not digit or odd) and press Run.
Compare the rebuilt digits with the generated ones.Reconstruction error rewards copying the input; generated samples show whether the model learned what digits look like in general.
Hints
A column computed from the target is not a feature, however well it scores.
Check gradients by finite differences before trusting a training curve.
A CNN's advantage comes from the image layout; change the layout and the advantage goes, with no error.
model-card
Teaching-scale digit reader
Write a short model card: the data and its leak, the two models and their held-out scores, the gradient check, the CNN's most confused digits, what the wrong image width did, and what the VAE showed.
Data and the leak
Models and scores
Checks that passed
What broke
The generative model
Scale and limits
Rubric
Criterion
Points
Identifies odd as a target-derived column and keeps it out.
2
Compares the MLP and the CNN on the same held-out folds.
1
Reports the gradient check and why a falling loss isn't enough.
2
Names the most confused digits from the Evaluation tab.
1
Explains that the wrong image width broke the CNN's neighborhoods without any error.
2
Distinguishes rebuilt digits from generated ones, and states the teaching-scale limits.
2
Model answer
Show the model answer
Data and the leak. A thousand 8 × 8 digit scans, 64 pixel columns. The column odd is computed from the digit and would leak the answer, so it stayed out of the features.
Models and scores. On the same folds, the CNN scored better than the torch MLP: it convolves small filters over neighboring pixels, so it reuses what it learns about strokes anywhere in the image. The MLP treats the 64 pixels as an unordered list.
Checks that passed. In the notebook, backpropagation agreed with central finite differences to about six digits, while a backward pass missing the tanh derivative was off by a large fraction even though it would still lower the loss at first.
What broke. Telling the CNN the image is 16 pixels wide glued pairs of rows together. Nothing errored, but its held-out score fell toward the MLP's: the advantage came entirely from the layout contract. Read the CNN's confusion matrix the same way; its common confusions are digits whose strokes overlap.
The generative model. The VAE rebuilds digits closely but its generated digits are blurrier and sometimes ambiguous; a good rebuild doesn't mean the model generates well.
Scale and limits. Teaching-scale models on a thousand small images, one seed. They show the mechanisms, not production accuracy.