LLM + RoboticsUnit 1 · The foundations · Day 04

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.

AuthorsGeoffrey E. Hinton, Drew van Camp
Year / venue1993 · COLT
Core ideaWeight cost = KL(posterior ‖ prior), via "bits back"
Study time3–4 h

Original: cs.toronto.edu (PDF) · Code, notebook and exercises: 30u30 Day 4

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

  1. A neural network has lots of number settings called weights.
  2. Instead of one exact number, each weight becomes a fuzzy range, like "somewhere around 0.3".
  3. Fuzzy weights are cheap to describe. But too much fuzz makes the answers worse.
  4. Training looks for the best balance: as fuzzy as possible while still giving good answers.
  5. 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

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.

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

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.

Weight bits
–
Error bits
–
Best s
–
Bayes posterior sd
–

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

What came after

4. Why it matters for robotics

5. How to study it

  1. Read the paper (9 short pages). Sections 2–5 are the core. Section 7 (mixture coding) can wait for a second pass.
  2. Derive the Gaussian KL formula yourself, then derive weight decay as its s → 0 limit.
  3. In the 30u30 Day 4 folder, read implementation.py. It uses the modern sampled-gradient version, not the paper's lookup tables. Run train_minimal.py.
  4. Do the exercises: reparameterisation, the generalisation gap experiment, the β weight on the KL term, Monte Carlo predictions, and the advanced MDL exercise.
  5. 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