Bayesian Neural Networks
A Bayesian neural network replaces each single learned weight with a distribution of plausible values, so a prediction comes with a built-in measure of how uncertain the network actually is, instead of one confident number with no idea how confident it should be.
Prerequisites: The Multilayer Perceptron, Bayes' Theorem
A standard neural network learns one specific value for every weight, and gives you one specific answer for a new input — with no indication of whether that's a well-supported prediction or a coin flip it happens to have committed to. An input from the middle of the training data and one wildly out of distribution can produce equally confident-looking predictions, because the architecture has no built-in way to say "I've never seen anything like this."
A Bayesian neural network treats every weight not as one fixed number but as a range of plausible values, weighted by how consistent each value is with the training data — the same logic as an analyst who says "the fair value is probably around $52, most likely somewhere between $48 and $56, and I'd bet heavily against it being outside $40–$65" instead of just stating "$52" with no sense of how firm that number is. When the model has seen plenty of relevant data, that range of plausible weights is narrow and predictions are tight; when the input looks unfamiliar, the range widens and the model's own uncertainty grows along with it.
The mechanics, one symbol at a time
Standard training finds a single best weight vector by minimizing a loss. Bayesian training instead computes a full distribution over given the data , using Bayes' rule:
In words: the posterior — what you believe about the weights after seeing the data — is proportional to how well weights explain the data (the likelihood, ) times what you believed about the weights before seeing any data (the prior, , typically a simple assumption like "small weights are more plausible than huge ones"). is just a normalizing constant that makes probabilities sum to 1 and doesn't change which weights are more or less plausible relative to each other.
Computing this exactly is intractable for any network with more than a handful of weights, so in practice it's approximated — commonly with variational inference, which fits a simpler, tractable distribution (like an independent Gaussian per weight, with a learned mean and spread) to be as close as possible to the true posterior. A prediction is then made by sampling several different weight settings from that approximate posterior, running the network forward with each one, and looking at how much the resulting predictions agree or disagree.
Worked example 1: uncertainty from disagreement across sampled weights
A Bayesian network's approximate posterior for a single output weight is — a fairly narrow distribution, reflecting confidence built from lots of relevant training data. Draw three samples: , , (all close together, as expected from a small ).
For an input with hidden activation , the three predictions are , , — a tight spread of roughly to , about around a mean near .
Now consider an input the network is far less sure about, where the relevant weight's posterior has widened to — say, because this input activates a part of the network rarely exercised by training data. Samples might be , , : predictions , , — a spread of , over 15 times wider. Same input activation, same mean weight, but the disagreement across samples reveals the model's genuine uncertainty about that region of its parameter space.
Worked example 2: how the prior pulls weights toward simplicity
With a Gaussian prior on a weight, the posterior for a small dataset is pulled noticeably toward zero relative to what an unconstrained fit would give. Suppose the likelihood alone (ignoring the prior — what a standard network would converge to) would place the weight's best estimate at , but with only 10 training examples supporting that estimate. Weighing that weak, small-sample evidence against a prior centered at 0 pulls the posterior mean well short of 3.0, say to around — with so little data, the prior dominates. With 10,000 supporting examples instead of 10, the same weighing lands almost exactly at : the data overwhelms the prior once there's enough of it. This is the same mechanism as L2 regularization, made explicit: a prior favoring small weights defends against overfitting to a handful of examples.
Standard training (visualized in the explorer above) finds the single point at the bottom of the loss surface. A Bayesian network instead tries to characterize the whole shape of the loss surface near good solutions — a wide, flat bowl means many weight settings fit almost equally well (high uncertainty); a narrow, steep bowl means the data pins the weight down tightly (low uncertainty).
What this means in practice
Bayesian neural networks are used wherever knowing how much to trust a prediction matters as much as the prediction itself — position sizing that shrinks when the model is uncertain, flagging live conditions unlike anything in training data, or risk models where overconfident tails are costly. The practical cost is real: exact Bayesian inference is intractable at neural-network scale, so every deployed method is an approximation (variational inference, or a cheaper proxy like Monte Carlo dropout — running a dropout-trained network multiple times with dropout left on and treating the output spread as an uncertainty estimate), and that approximation's quality determines how trustworthy the resulting numbers are.
A Bayesian neural network learns a distribution over weights instead of a single point estimate, which turns model uncertainty into something you can read off a prediction directly — tight agreement across sampled weights means confidence, wide disagreement means the model genuinely doesn't know.
The classic confusion: treating the uncertainty a Bayesian network reports as automatically well-calibrated, meaning a stated 90% confidence interval really does contain the truth 90% of the time. Because exact Bayesian inference is intractable and every practical method is an approximation, the reported uncertainty is only as good as that approximation and the chosen prior — a poorly-fit variational posterior can report confident-looking but badly miscalibrated uncertainty, so calibration should be checked against held-out data, never assumed from the method's name alone.
Practice in interviews
Further reading
- Blundell et al., Weight Uncertainty in Neural Networks
- Goodfellow, Bengio & Courville, Deep Learning, ch. 5, 19