Keeping Neural Networks Simple by Minimizing the Description Length of the Weights
A network generalises when its weights carry little information. Make every weight a noisy Gaussian, count the bits it costs to send, and you get the objective behind Bayesian neural nets and VAEs, in 1993.
Start here (no maths needed)
A network learns better when its settings are kept simple, and you can measure "simple" by how few bits it would take to send those settings to a friend.
Think of it like this
Imagine texting a friend the answers to a maths worksheet. You could send every answer, digit by digit. Or you could send a short rule ("each answer is the question number times 3") plus a few corrections. The short message is cheaper, and the rule will probably work on the next worksheet too. This paper also notices that you do not need to send every setting exactly. "About 0.3" is a shorter text than "0.31827", and often works just as well.
How it works
- A neural network has lots of number settings called weights.
- Instead of one exact number, each weight becomes a fuzzy range, like "somewhere around 0.3".
- Fuzzy weights are cheap to describe. But too much fuzz makes the answers worse.
- Training looks for the best balance: as fuzzy as possible while still giving good answers.
- A clever trick called "bits back" shows exactly how to count the cost of a fuzzy weight.
Why robots care
A robot that has learned how its arm moves should also know when it is unsure, for example when it is holding a heavy object it has never lifted before. Fuzzy weights give the robot a "how sure am I?" signal, so it can move more carefully when it is unsure.
Try it
- Describe your bedroom to a friend in exactly 10 words, then in 50 words. Which details did you drop in the short one? Those were the ones that did not matter much. That is the trade-off this paper makes.
- In the demo further down, drag the Weight noise s slider and find the lowest point of the Total curve. Then move the Training cases N slider to the right. With more data, the best amount of fuzz gets smaller.
Words to know
- Weight
- One of the adjustable numbers inside a neural network.
- Bit
- The smallest piece of information: a single 0 or 1.
- Description length
- How many bits it takes to describe something.
- Noise
- Random wobble added on purpose, here to a weight.
- Prior
- What both sides agree to expect before seeing any data.
Going deeper: everything below is the full version, with some maths. On a first read, skim the headings and the "Why it matters for robotics" box, and come back for the rest later.
1. Summary
TL;DR
Hinton and van Camp frame learning as communication. A sender must transmit the training targets to a receiver who already has the inputs. She can send a network plus its errors. A good network makes the errors cheap, but costs bits itself. Instead of sending exact weights, she sends noisy ones: each weight is a Gaussian with a mean and a variance. Using a clever "bits back" argument, the true cost of a noisy weight turns out to be the KL divergence between its Gaussian and a shared prior. Noisy weights are cheap. Precise weights are expensive. Learning trades the two off against the extra error the noise causes.
- Principle: Minimum Description Length (Rissanen). Best model = shortest total message: model bits + misfit bits. Day 05 covers MDL properly.
- Weight decay falls out as the crude case: fixed-precision weights coded with a fixed Gaussian.
- Noisy weights let imprecise weights be described cheaply, which crude coding ignores.
- Exact gradients for one hidden layer with linear outputs, no sampling, using lookup tables.
- Result: on a tiny, high-dimensional task it beat carefully tuned weight decay, slightly. The authors called the results preliminary.
2. The core idea
Total description length is two terms. Each weight w has a posterior Q = N(μ, s²) that learning controls, and both parties agree a prior P = N(μ_p, s_p²).
Cost = Σ_weights KL(Q ‖ P) + Σ_cases Σ_outputs E_Q[(d − y)²] / (2σ_d²)
KL(Q ‖ P) = log(s_p / s) + (s² + (μ − μ_p)²) / (2 s_p²) − 1/2 # nats
- KL(Q ‖ P) is the bits to send one weight. Wide
sand a mean near the prior make it small. - EQ[(d − y)²] is expected squared error with weights drawn from Q. Noise adds variance to the outputs, so the error grows with
s. - σd is the width of the Gaussian used to code the errors. Only the ratio between the two widths matters.
Bits back, in one paragraph. The sender picks a precise weight by sampling from Q, using random bits, then codes it under P. That costs about −log P(w), which is a lot. But once the receiver has all weights and errors, he can rerun the same learning algorithm, recover Q, and therefore recover the random bits used to sample. Those bits were sent for free, so they are refunded. Expected cost: E_Q[−log P(w) + log Q(w)] = KL(Q ‖ P).
If you set s → 0 and fix P, the KL term becomes a scaled μ²: plain weight decay. The paper says weight decay's success is a vindication of this crude MDL view.
3. Deep dive
The trade-off, made concrete
Take a single weight in a toy linear model y = w·x, keep its mean at the best fit, and vary only its noise s. The KL term falls as s grows. The error term rises as s² Σx². The best s sits in between, and it shrinks as data grows: more data makes precision worth paying for.
Interactive: how noisy should a weight be?
Toy problem: N points, x uniform in [−1, 1], targets 0.8·x plus noise (σd = 0.5), prior N(0, 1). Curves show the parts of the cost that depend on s, in bits. Total, weight cost (KL), extra error from noise.
The last two numbers always match. Setting the derivative to zero gives 1/s² = 1/s_p² + Σx²/σ_d², which is exactly the posterior precision of Bayesian linear regression. Minimising description length with noisy weights is variational Bayes in disguise.
Mixture priors and a free-energy bound
One Gaussian prior can't model weights that cluster, say, near 0 and near 1. The paper adapts a mixture of Gaussians as the coding prior, extending Nowlan & Hinton's soft weight sharing (1992) to noisy weights. The KL to a mixture has no closed form, so they use an upper bound that has the same form as a Helmholtz free energy. They derive it with a second bits-back argument: picking which mixture component to use also costs random bits that come back.
Results, read honestly
- Task: predict the effectiveness of peptide molecules from 128 input features. 105 training cases, 420 test cases. A net with 4 hidden units has 521 weights, far more than the data.
- Relative test error (1.0 = guessing the mean): 0.286 with noisy weights and a 5-component mixture prior, 0.967 with no penalty, 0.317 for the best weight decay chosen by validation.
- They had to ramp the weight-cost coefficient from 0.05 up to 1. At full cost from the start, optimisation collapsed to weights that carry almost no information.
- Embarrassingly, the solution with the lowest total description length was that trivial one, with relative error near 1.0. The authors said so plainly.
What came after
- Variational autoencoders (Kingma & Welling, 2013) use the same "expected error + KL" objective on latent codes, and the same warm-up of the KL weight turns up in VAE training. See Day 23.
- Bayes by Backprop (Blundell et al., 2015) is this paper scaled up: Gaussian weights trained with the reparameterisation trick and sampled gradients instead of lookup tables.
- Bits-back coding later became a practical lossless compression method with latent-variable models.
- The diagonal Gaussian ignores correlations between weights. The paper flags this as an open question.
4. Why it matters for robotics
- Knowing what you don't know. A distribution over weights gives a distribution over predictions. A learned dynamics model that says "I'm unsure here" lets a planner avoid or probe that region. In practice, probabilistic ensembles are the more common choice in robot learning, but the reasoning is the same.
- Small data, many inputs. The paper's setting, 105 examples and 128 features, looks like many real robot tasks: few demonstrations, high-dimensional observations. Controlling information in the weights is what stops memorisation.
- Imprecise weights are cheap weights. A weight that tolerates noise also tolerates quantisation. That is the same property you need to squeeze a policy onto edge hardware (see Module 04).
- Honest limit: exact Bayesian treatment of large policies is still too expensive for real-time control. Use this as a mental model and a source of tools, not a recipe.
5. How to study it
- Read the paper (9 short pages). Sections 2–5 are the core. Section 7 (mixture coding) can wait for a second pass.
- Derive the Gaussian KL formula yourself, then derive weight decay as its
s → 0limit. - In the 30u30 Day 4 folder, read
implementation.py. It uses the modern sampled-gradient version, not the paper's lookup tables. Runtrain_minimal.py. - Do the exercises: reparameterisation, the generalisation gap experiment, the β weight on the KL term, Monte Carlo predictions, and the advanced MDL exercise.
- Stretch: ramp β from 0.05 to 1 as the paper does, and compare against β = 1 from the start.
6. Self-check
What do the sender and receiver each know?
Both know the inputs and the architecture. Only the sender knows the target outputs. She sends weights plus errors so the receiver can reconstruct the targets.
Why do the "bits back" get refunded?
The receiver can rerun the learning algorithm, recover the posterior Q, and so recover the random bits used to sample each precise weight. Those bits carried information for free, so they're subtracted from the cost.
Why does more data make the best weight noise smaller?
The extra error from noise grows with the number of cases, while the weight cost doesn't. With more data, precision pays for itself.
How does weight decay appear in this framework?
Code precise weights under a fixed zero-mean Gaussian. The cost is proportional to the sum of squared weights, which is the weight-decay penalty.
What is the main weakness the authors admit?
The global minimum of description length was a useless solution, and the method needed a hand-designed ramp of the weight cost to avoid it. The results were preliminary and on one task.
7. Further reading
- The original paper, and Blundell et al. (2015), Weight Uncertainty in Neural Networks
- 30u30 Day 4: implementation, notebook, cheatsheet, exercises
- Next: Day 05, A Tutorial Introduction to the MDL Principle