TL;DR
Bayes by Backprop trains a neural network in which every weight is a probability distribution rather than a single number. The training objective is the variational free energy, a KL divergence term that keeps the weights close to a prior plus a data-fit term, and the authors optimise it with a small change to ordinary Backpropagation. On MNIST digit classification the method matches Dropout, and the learned uncertainty helps in a regression toy problem and in a contextual bandit task.
Builds on: Variational Lower Bound (ELBO), Reparameterization Trick, Bayesian Neural Network · Leads to: the later line of work on practical Bayesian deep learning and on uncertainty-driven exploration
Why it mattered
The paper showed that the Bayesian treatment of a network's weights could be trained at the scale of an ordinary feedforward network. Before it, variational methods for neural weights had closed-form cost terms that limited which prior and posterior pairs could be used. The authors dropped the closed form and used Monte Carlo samples throughout, which made the prior freely choosable.
Its ideas now show up in three places. First, the weight-distribution view of a Bayesian Neural Network, where each sample of the weights is one network in an ensemble. Second, the observation that a network's uncertainty about its weights gives a principled way to explore, which is the basis of Thompson sampling for bandits. Third, the reparameterisation of a random variable as a fixed function of noise, which the paper generalised from hidden units to every weight of a network.
The problem
A plain network is trained to find one weight setting by maximum likelihood. Such a network has two known weaknesses, which the introduction states directly: it overfits, and it makes overly confident decisions where the training data are thin. Regularisers such as early stopping, weight decay and Dropout address the first problem by heuristics. The paper asks for a principled regulariser that also gives calibrated uncertainty.
The Bayesian answer is to keep a distribution over the weights, the posterior given the data. That posterior cannot be computed exactly for a network with thousands or millions of weights. So the paper uses a variational approximation: choose a simple distribution q over the weights, with parameters θ, and make it as close as possible to the true posterior. Closeness is measured by a KL divergence, and minimising it reduces to minimising a single cost. Two parts of that cost are the key: a complexity term that penalises q for moving far from the prior, and a likelihood term that rewards q for explaining the data.
How it works
Take one weight, one training example and one gradient step. The weight has a distribution with mean μ = 0.5 and standard deviation σ = 0.1. Because the paper parameterises σ = log(1 + exp(ρ)), this corresponds to ρ ≈ -2.25. The numbers below are illustrative and were worked by hand. They are not from the paper.
- Describe the weight by two numbers. The variational posterior is a Gaussian with mean μ and standard deviation σ. Store ρ instead of σ, so that σ = log(1 + exp(ρ)) is always positive. Check: with ρ = -2.25, log(1 + exp(-2.25)) is about 0.10.
- Draw noise. Draw ε from a standard normal distribution, with mean 0 and variance 1. Suppose the draw is ε = 1.5. The network never sees ε directly, only the weight built from it.
- Build the weight from the noise. Set w = μ + σ ε = 0.5 + 0.1 × 1.5 = 0.65. This is the reparameterisation: the random choice is moved into ε, and the weight becomes a fixed function of μ, ρ and ε. Check: the weight is 0.65, which lies above the mean by 1.5 standard deviations, as the draw said it should.
- Run the network with this weight and measure the cost. The cost for the sample is the complexity term minus the log-likelihood term. Suppose the backward pass gives ∂f/∂w = 0.8 for this sample.
- Turn the gradient into updates for μ and ρ. For this sample, take the direct terms ∂f/∂μ and ∂f/∂ρ as zero, so only the path through w counts. Then Δμ = ∂f/∂w = 0.8, and Δρ = ∂f/∂w × ε / (1 + exp(-ρ)) = 0.8 × 1.5 / 10.5 ≈ 0.11. The same backward pass gives both. Check: the only extra work is multiplying by ε and by a sigmoid factor.
- Step downhill. With a learning rate of 0.1, μ becomes 0.5 - 0.1 × 0.8 = 0.42, and ρ changes by about -0.011. So σ shrinks from 0.100 to about 0.099. Check: μ and σ both moved in the direction that lowers the cost on this sample.
- Repeat with a fresh draw of ε. Each step uses new noise, so over many steps the averaged gradient estimates the true gradient of the variational cost.
flowchart LR A["Draw noise eps from a standard normal"] --> B["Build weights w = mu + sigma times eps"] B --> C["Forward pass and cost"] C --> D["Backprop gives the gradient with respect to w"] D --> E["Scale and shift it into updates for mu and rho"] E --> A
The math
Let be the training data and the weights. The variational posterior is , with the parameters that the method learns. The cost is the variational free energy:
The first term is the complexity cost, which keeps q close to the prior P(w). The second is the likelihood cost, which rewards weights that explain the data. Minimising this cost is the same as maximising the expected lower bound on the marginal likelihood, which is the evidence lower bound.
Step 3 in symbols: the reparameterisation
For a diagonal Gaussian posterior, the paper draws and sets
where is element-wise multiplication. The paper's Proposition 1 says that the derivative of an expectation over can be written as an expectation of a derivative, once the sample is written as a deterministic function of noise. This is the Reparameterization Trick applied to every weight.
Step 4 and 5 in symbols: the gradients
Write , the cost of one sample. The gradients for the two parameter vectors are
The term is the usual backpropagation gradient, shared by both. The factor is the derivative of , the function that turns ρ into σ. The paper's point is that learning a distribution costs only a scale and a shift on top of ordinary backprop.
Step 6 in symbols
The update is gradient descent with learning rate α: and .
The prior: a scale mixture
The paper uses a prior that is a mixture of two zero-mean Gaussians for each weight:
The first component has the larger variance, which gives a heavy tail. The second has a small variance, which concentrates most weights near zero. The prior is a Mixture Model of two Gaussians, and its settings π, σ1 and σ2 are fixed during training and chosen by cross-validation where possible, rather than learned, because the paper found learning them performed worse.
Minibatches
When the data are split into M minibatches, the paper weights the complexity term for minibatch i by
These weights sum to 1, since the powers of 2 from to add up to . For M = 4 they are 8/15, 4/15, 2/15 and 1/15. The early minibatches therefore carry most of the complexity cost, and the later ones are driven mostly by the data.
Results
MNIST classification. The data are the standard MNIST digits, with 60,000 training images and 10,000 test images of size 28 by 28. To tune hyperparameters, the authors trained on 50,000 digits and kept 10,000 for validation. The network has two hidden layers of rectified linear units and a softmax output with 10 units. The test error results are in the paper's Table 1:
| Method | Units per layer | Weights | Test error |
|---|---|---|---|
| SGD, dropout | 400 | 500k | 1.51% |
| SGD, dropout | 800 | 1.3m | 1.33% |
| SGD, dropout | 1200 | 2.4m | 1.36% |
| Bayes by Backprop, Gaussian prior | 400 | 500k | 1.82% |
| Bayes by Backprop, Gaussian prior | 800 | 1.3m | 1.99% |
| Bayes by Backprop, Gaussian prior | 1200 | 2.4m | 2.04% |
| Bayes by Backprop, scale mixture prior | 400 | 500k | 1.36% |
| Bayes by Backprop, scale mixture prior | 800 | 1.3m | 1.34% |
| Bayes by Backprop, scale mixture prior | 1200 | 2.4m | 1.32% |
The scale mixture prior is the variant that matches dropout, with 1.32% at the largest size. The Gaussian prior is clearly worse, which is why the mixture is central to the paper. The authors also quote a plain SGD network without regularisation at 1.6%, from earlier work. They note the Bayesian method takes about twice as long per iteration as dropout. Over long training it eventually reaches a lower test error than dropout, after about 600 epochs.
Pruning. The authors rank weights by the ratio of their mean to their standard deviation, the signal-to-noise ratio, and remove the lowest-ranked. Table 2 of the paper gives the error of a 1200-unit, two-layer network after pruning:
| Proportion removed | Weights remaining | Test error |
|---|---|---|
| 0% | 2.4m | 1.24% |
| 50% | 1.2m | 1.24% |
| 75% | 600k | 1.24% |
| 95% | 120k | 1.29% |
| 98% | 48k | 1.39% |
Removing 95% of weights costs 0.05 percentage points. The drop becomes significant only at 98%. This is a useful result, but the paper is careful to say that the network used for pruning is the one from the end of training, not the one with the lowest validation cost.
Regression. On a noisy one-dimensional curve, a standard network becomes overconfident where no training data lie. The Bayesian network's interquartile ranges widen in those gaps. This is an illustration on toy data, not a benchmark.
Contextual bandit. On the UCI Mushroom data, an oracle that eats every edible mushroom and skips every poisonous one earns 5 per edible mushroom and 0 per poisonous one. Regret is the gap between the oracle's total reward and the agent's. The Bayesian agent scores each action by averaging two outputs from two samples of its weights, so its exploration comes from the weight uncertainty itself. This is close in spirit to Thompson sampling, which draws one plausible model and acts as if it were true. It is compared with epsilon-greedy agents with ε of 0%, 1% and 5%, averaged over five runs. The Bayesian agent explores from the start, and its cumulative regret is almost flat after it converges. The greedy agent eats nothing for the first roughly 1,000 steps. The paper's own reading is that its 5% agent over-explores.
Limits. The MNIST comparison is on one dataset, the regression is a toy, and the bandit is a single simulated task. The prior's settings were chosen by cross-validation where possible, and the paper reports that learning them during training performed worse.
Reading guide
- Section 1, Introduction. Read after Bayesian Neural Network and Dropout. It states the three motivations: regularisation, model averaging and exploration.
- Section 2, Point estimates. Needs Maximum Likelihood Estimation, Prior Distribution and the link between a Gaussian prior and weight decay in L2 Regularization.
- Section 3, Being Bayesian by backpropagation. The core. Needs Posterior Distribution, Kullback–Leibler Divergence and Variational Lower Bound (ELBO). Proposition 1 needs Reparameterization Trick and Monte Carlo Method.
- Section 3.2, Gaussian posterior. Needs Gaussian (Normal) Distribution and the chain rule from Backpropagation.
- Section 3.3, Scale mixture prior. Needs Mixture Model.
- Section 3.4, Minibatches. Needs Stochastic Gradient Descent.
- Section 4, Contextual bandits. Needs Multi-Armed Bandit, Epsilon-Greedy Policy and Reinforcement Learning.
- Section 5, Experiments. Needs Rectified Linear Unit (ReLU) and Softmax for the MNIST network, and the earlier definitions for the tables.