Introduction
Deep learning is often framed as an optimization problem: define a neural network, choose a loss function, and minimize it with stochastic gradient descent. Yet beneath this procedural view lies a statistical one. Each time we minimize cross-entropy, add weight decay, or compare models using validation performance, we are implicitly invoking ideas related to Bayesian inference: uncertainty, evidence, and generalization.
This post develops a Bayesian perspective on deep learning. Rather than viewing training purely as loss minimization, we interpret it as approximate inference in a probabilistic model. This shift in viewpoint helps clarify several familiar concepts:
- the role of priors and regularization,
- why maximum likelihood and MAP estimation arise,
- how model evidence balances data fit and complexity,
- and why flat minima and highly overparameterized models can still generalize.
We will start from Bayes' rule over models and progressively move toward parametric formulations used in modern machine learning. Along the way, we will see how common approximations arise naturally from this perspective and how they relate to the geometry of the loss landscape.
A key insight will emerge: generalization is not governed simply by the number of parameters, but by the effective dimensionality of the parameter space, i.e., the number of directions that the data actually constrain.
The goal of this article is not to claim that deep learning is fully Bayesian in practice. Rather, it is to show that Bayesian reasoning provides a useful conceptual framework for understanding phenomena that might otherwise appear puzzling, such as the remarkable generalization ability of modern heavily overparameterized neural networks.
A Quick Note on Notations
Before tackling the main subject, we first need to define some notations. We will encounter two types of objects: beliefs and noise. These two objects are both represented as random variables, but their roles are very different. Beliefs describe our often imperfect knowledge of the truth. Noise limits the amount of information that an observation brings.
Random variables are denoted with capital letters (e.g. , , ) and their value with lowercase letters (e.g. , , ). We will also use the following abbreviations when there is no ambiguity:
| Abbreviation | Full Notation |
|---|---|
| / | / |
| / | |
| / | / |
| / | / |
| / | / |
The Probabilistic Foundation
Generally, problems are questions with unknown answers, for example, what will the weather be tomorrow, or is there a cat in this image? Machine learning promises to provide a general methodology to answer such questions, leveraging available information. This information is often in the form of a dataset of already answered questions. What we want is to answer new questions, or at least get the probability of possible answers.
To abstract this problem, we will note questions and answers and consider the simple case where the dataset contains pairs of question and answer . Formally, we are thus interested in estimating:
The probability of answer to the question given the available information in the dataset for all possible .
For a question in the dataset, we can estimate by counting the frequency of tuples in . However, for a new question, there is no way to use existing data to generalize without introducing some assumptions. Indeed, without further assumption, nothing prevents answers from being totally random; the structure we may have noticed in our dataset can just be a very (un)lucky coincidence.
Introducing Models
At this point, we introduce models. Models are central in machine learning. They are candidates for how things work. Often, we use statistical models. Statistical models differ from deterministic models in a subtle but very important way: they are uncertain. This changes everything. Indeed, there is a common aphorism that states:
"All models are wrong, but some are useful."
It's not entirely true. If you say that you think temperatures tomorrow will probably be between -10°C and 40°C, you have a mental model that captures part of reality; your model of how the world works is not wrong, probably a bit imprecise, and certainly not very useful, but not wrong. And when expressing uncertainty, you don't say that the temperature tomorrow is determined by fundamentally random stuff, just that you are not able to predict it precisely. It is crucial to distinguish probabilities that describe a belief from those that describe noise, even if both are described by the same mathematical tools.
Models are generally diverse:
- Some are simple, others complex.
- Some explain the data well, while others do not.
- Some make sharp predictions, whereas others only make broad ones.
A model is useful if it agrees with the data and makes sharp predictions which are correct. "Simple" models are often better than complex ones, but it is a story for another time.
The usefulness of models lies in their universality. When using models, we implicitly assume that the dataset and future data follow the same underlying laws. This is what allows us to generalize from available data to new data. Models are what create a connection between what we experience and the future.
Models make predictions: If the model (noted ) is true, then the answer to the question has the probability distribution .
Of course, we generally don't know if a model is true. At best, we can use our experience or intuition to evaluate the plausibility of models. If we define a distribution over models representing our belief in different models from a set of candidates, the probability of an answer given a question and data becomes:
Although the set of all possible models is unrestricted, in practice, we work with a set of models that is rich enough to approximate any relevant one while excluding models that are implausible a priori. For example, linear regression restricts attention to linear relationships between and . Nevertheless, it can approximate more complex relationships.
In practice, we cannot evaluate all possible models and compute their likelihood. We have to rely on approximations of this sum. A common approximation consists of searching for one or a few probable models and computing the weighted average of their predictions. This approach is called "model averaging", and it is usually effective.
The prohibitive cost of averaging many models leads to the idea of posterior maximization (MAP). The principle is to search for one or a few models which are the most likely after observing the data:
The likelihood of models can be computed with Bayes' rule :
- The term is the a priori probability of models (our guess of model probability before observing the data from ) it is called the prior
- The term is the likelihood of the dataset if the model is true.
- The term is a constant normalization term.
Prior over models
The prior is chosen freely by the practitioner and can theoretically be selected to get any result. It is sometimes argued that we should choose following the maximum entropy principle. For example, choosing a uniform distribution over models.
However, the entropy is related to the set of models you have and how you parameterize them. For example, you could have a thousand similar models and one radically different one, or just two different models. The maximum likelihood principle will yield very different predictions. Supposing that the likelihood of observed data is the same for all models. When we make predictions, we average the models' predictions; the first case will produce a very different prediction from the second one, as in the first case, the average prediction will be dominated by the thousand similar models, while in the second case, the two different predictions will be weighted equally.
When models live in a continuous space, the maximum entropy principle is not well defined, as the entropy of a continuous distribution is not invariant to reparameterization.
So, defining a theoretically "neutral" prior is challenging; the choice of the prior is a crucial part of the modeling process and can have a significant impact on the results. However, as we will see in the next section, as more data becomes available, the influence of the prior diminishes, and the likelihood of the data given the model becomes the dominant factor in determining which models are probable.
Data vs Prior
If there is no "neutral" prior, how can we choose a reasonable one? Basic advice is to try not to introduce obviously bad biases and avoid too complex models. If you follow this advice, you should be fine, but keep in mind that the prior is important and can cause issues. However, as the dataset gets larger, the prior term becomes less important.
Indeed, consider two models & for which if is sampled from the data generating process (DGP), we have:
i.e., the expected log likelihood of a sample from the DGP is for model and for model on average. If , we can say that model fits the data better than model . If the dataset is composed of i.i.d. samples, the term can be expressed as a product over dataset samples, thus:
Taking the logarithm of the ratio of model probabilities divided by : , we have that the expected value of this term is:
And its variance is:
Thus, it converges in probability to :
We can conclude that:
Thus, when the prior is fixed, the weight of the model that best fits the data dominates the weight of the other model exponentially fast as the dataset size increases. The prior influence diminishes as more data is available. The choice of a good prior is thus less important when a lot of data is available.
However, this isn't the full story. Indeed, for finite datasets, it is not uncommon to have several different models fit the data equally well (even for large datasets). For example, when models are over-parametrized. In this case, the data likelihood is the same for all these models. In this case, only the prior influences the relative weights of selected models. In a sense, data filters out bad models, and the prior weights the remaining ones.
Parametric models
One way to define the set of possible models is the use of a parametric model. Formally we define the parametric model as a set of models defined by a function that takes as input parameters and outputs a model :
Do not get confused by the terminology "parametric model". The term "model" is used here both to refer to the function that defines the family of models or to the set of models itself. In this post, we will use the term "parametric model" to refer to the set of models defined by the function , and we will call the "model function". The model function is a way to define a family of models whose behavior can be tuned by changing its parameters (also called weights), noted .
Using parametric models allows us to substitute the search for good models with the search for good parameters, as we now have a mapping between models and parameters. We switch to the continuous Bayes rule (note that here denotes a density, not the "model function"):
With the likelihood of the answer given the question and data :
Again, as the sum over models, this integral is generally intractable, and we need to rely on approximations. One common approximation is to search for the most likely parameters and use the model as an approximation of the true model:
Going beyond MAP
Often, Gaussian priors are used for parameters, leading to L2 regularization. This is a common regularization technique in deep learning that encourages the parameters to have a small norm. The rationale behind this prior is that a smaller parameter norm is related to model simplicity and thus better expected generalization. This is a good example of how the choice of the prior can have a significant impact on the results.
However, it is often overlooked that choosing the parameters that maximize the posterior is not the only way to approximate the true model. Indeed, maximizing the posterior is just one way to approximate the integral over parameters. Choosing the prediction from the model with the highest weight in the sum over models in the discrete case is quite a bold move, as this model can represent a very small fraction of the total weight of the sum over models.
In the continuous case, the situation is even worse. How can we justify approximating the full integral with a single point estimate with effectively zero probability mass? The only justification is that we can expect some regularity such that models that are close in parameter space make similar predictions.
What we can do to go beyond MAP is to consider a set of nearly equivalent models close to the one we found and compute its posterior probability mass. The problem become equivalent to finding the set that maximize:
Equivalently, we can minimize:
In itself, this expression is already interesting. Intuitively, the first term corresponds to the likelihood of the data given our model; it's a term that accounts for how well we fit the data. The interpretation of the second term is more subtle. When considering a point-like ensemble of models, it is proportional to and can be thought of as the likelihood of the model given our prior. However, now we have the negative log of a probability of an event () also known as the information content of the event (i.e. the number of bits needed to describe this event). It is thus the minimum description length (MDL) of .
This provides a theoretical justification for the MDL (Minimum Description Length) principle, which states that when two models are equally good at explaining the data, the one with the shortest description should be chosen. This connection is classical and described in (MacKay, 2003, p. 349) as:
The log of the Occam factor can be interpreted as the amount of information we gain about the model when the data arrive.
However I think it's worth to make explicit the idea that this amount of information is directly the number of bits needed to describe the model and thus is directly related to the MDL principle. This principle is very powerful as it encapsulates ideas about the precision of model parameters and the simplicity of programs.
Let's now try to get an expression for this Loss. The term can be easily approximated by considering the expected negative log likelihood:
given a dataset of size . We can approximate the likelihood of the dataset given the parameters by:
This means that as the dataset size increases, the likelihood of the dataset given the parameters becomes more peaked around the parameters that minimize the expected negative log likelihood .
For the second term, we can consider a natural set of models verifying these two conditions:
- : i.e. parameters are sufficiently close to for the predictions to be similar (or for the predictions to average to the predictions of )
- : parameters fit data reasonably well.
Approximating the second term is more involved, so we will jump directly to the result. However, you can find the derivation here:
Approximating the loss function using the second order Taylor expansion around the second condition becomes:
The probability mass spanned by the that satisfy both of these conditions is the intersection of a ball and an ellipsoid, for which computation will give no closed-form formula. Nevertheless, we can approximate these hard constraints with soft Gaussian windows to get a closed-form approximation of the probability mass of this region.
We can then compute the probability mass of :
Let's introduce the notation
And taking the negative log to get the information content of (i.e. the number of bits needed to describe the random event ):
Expressing it in terms of the eigenvalues of , the last term is:
Supposing that , the last term becomes negligible and we get:
Supposing that is of rank we get:
Note: It's possible to obtain a similar result using Laplace approximation, with simpler maths, but I hope that the way I presented it here is more intuitive. In addition, the Laplace approximation derivation does not include the contribution of to account for the regularity of the parameter space.
This is interesting as usually in deep learning the prior term is just , here we have a much richer prior that takes into account the rank of the Hessian, number of parameters, regularity of the parameterization and the curvature of the hessian in addition to the usual prior.
We can first notice that only one term increases with , thus in the infinite data limit, we can keep only one term: the Occam factor.
This result is interesting because the Occam factor is not the usual one: . The Occam factor is generally used in the Bayesian Information Criterion (BIC) to select models and to balance fitting and overfitting, penalizing models with a high number of parameters that can fit the data better but are more prone to overfitting. What our derivation suggests is that effective dimensionality (the rank of the Hessian), rather than raw parameter count, plays a central role. This is a candidate explanation of why a heavily overparametrized model can still generalize reasonably well.
Indeed, in deep neural networks, the loss landscape is rarely shaped like a sharp bowl. Instead, we often observe flat regions and directions along which the loss hardly changes. Mathematically, this is manifested as a Hessian with many near-zero eigenvalues (a.k.a. close to low rank matrices). Rather than a single isolated minimum, this suggests the existence of a low-dimensional manifold of equivalent or near-equivalent solutions.
This phenomenon is extensively studied in modern deep learning: flat minima (Hochreiter & Schmidhuber, 1997; Keskar et al., 2017) tend to correlate with better generalization; Hessians in deep nets are empirically found to be highly singular (Sagun et al., 2016); minima are connected by low-loss paths (Draxler et al., 2018; Garipov et al., 2018); and (Chizat & Bach, 2020) showed that for infinite width 2-layers ReLU networks, we have dimension independent generalization bounds.
In practice, however, the dimension of the parameter space can be quite large compared to the number of samples we have. Thus, the following approximation is often valid:
The first term does not depend on the choice of , thus we are left with an L2 weight penalty. However, the first term is related to the choice of the architecture used and how "regular" it is. Note that here we suppose that the rank of the Hessian does not increase with the number of parameters. This is actually supported by (Sagun et al., 2016) as discussed above.
Conclusion
Viewing deep learning through a Bayesian lens clarifies many ideas that are often introduced heuristically. Training corresponds to searching for parameters with high posterior probability, regularization reflects prior assumptions, and generalization emerges from a balance between data fit and model complexity.
From this perspective, what matters is not only how well a single parameter configuration fits the data, but how much posterior mass surrounds it. Regions of parameter space where many nearby models perform similarly well contribute more to the evidence than isolated sharp minima.
This leads to an important insight: the effective complexity of a model is not determined by the total number of parameters, but by the number of directions in parameter space that the data actually constrain. In our derivation, this appears through the rank of the Hessian rather than the raw parameter count. When many directions remain flat, large networks can still occupy broad high-probability regions and thus generalize well.
Deep learning is not fully Bayesian in practice, since exact posterior inference is infeasible. However, the Bayesian viewpoint provides a useful conceptual framework: it explains why flat minima matter, why overparameterized models can generalize, and how architectural and optimization choices implicitly shape the space of plausible models.
References
Citing this blog post
@misc{plumerault2026bayesian,
author = {Plumerault Antoine},
title = {Beyond Loss Minimization: A Bayesian View of Deep Learning},
year = {2026},
}
