On Bayesian Deep Learning, an outsider’s view

Created: February 6, 2020 10:59 PM

Jialin Lu

Basically this is an outsider who does not work on Bayesian methods, but somehow was volunteered to do a survey and give a presentation of the pros/cons of Bayesian Deep Learning. I will not talk about the math, but only the ideas intuitively.


Please see the typesetted pdf if you prefer reading as a short paper.

This is a supplementary version in PDF.

This is a supplementary version in PDF.

This is the corresponding slide for the presentation

This is the corresponding slide for the presentation


Why I am doing this

Lab mates at NeurIPS 2019 (I am the one in the rightest, wearing the volunteer shirt)

Lab mates at NeurIPS 2019 (I am the one in the rightest, wearing the volunteer shirt)

But anyway I read some papers and organize a short survey into this topic of Bayesian Deep Learning. The outline of this post can be summarized as follows

Introduction

Part 1: Bayesian Deep Learning, but why?

Motivations for combining Bayesian learning and deep learning

Bayesian Learning is great, deep learning is also great.

These two methods is complementary.

image source, Emtiyaz Khan 2019

image source, Emtiyaz Khan 2019

As shown in the above figure, Bayesian learning handles the uncertainty as the key priority of modeling and can flexibly consider adaptive learning; the only problem is that it is not so efficient. Applying to large datasets is generally infeasible, as the computational cost is quite high.

Deep Learning, on the contrary, results in a fully deterministic model (in terms of the weights of the model). It scales well on very large datasets and easily handles various types of data.

Combining these two methods to get the best of both worlds, and to eliminate the disadvantages of each other is really a natural thing we’d like to expect. Can we combine DL and BL so that we can get

Can we get all these four points?

The problem is really about how to combine these two methods. There are mainly two general ways on how to combine BL and DL

But “how to”? Two ways of combining

Here I summarize two ways on “how to” combine DL and BL, which are DL→BL and BL→DL respectively.

In this post, I will not talk about the DL→BL direction but only talk about BL→DL. Just to clarify the terminology, I will also use the term “Bayesian Treatment of Neural Networks” to emphasize that we are talking about “BL→DL”. People also uses Bayesian Deep Learning, or Bayesian Neural Networks. You just need to know that these are the same thing, just alias names.

Part 2: Bayesian Treatment of Neural Networks

The Bayesian Treatment of Neural Networks means that we are after one single resultant model, but a distribution of all possible models, the posterior. It is better to think that we have a set of possible resulted models, and each is also weighted by some “fitness” value. Bayesian inference implicit performs model comparison and selection in this posterior.

Well it is called Bayesian because the posterior is computed by the Bayes rule.

The posterior is of desire because there are a lot of things we can do with it. We can use to do model selection, we can marginalize to to Bayesian Model Averaging to do prediction, we also enables to do prediction with uncertainty. This is really an important and principled way to do a lot of things, but the vital question, again, is not to obtain or not to obtain it, but rather how to obtain it.

Now I introduce two categories of approaches that approximates the posterior, namely the variational-inference-based approximation and interpolation-based approximation.

Note that the the name of the latter approach is my own invention and may not be consistent with the literature. But I found it intuitively summarizes the key aspect of this track of approaches. We will talk about this anyway later.

Option 1: Variational Inference-based Approximation

The variational-inference-based approach will first require you to predefine the form of a distribution q, and then, you adjust the parameters of q to fit the true posterior.

suppose the circle (a Gaussian)  is **q** , you can adjust the mean and variance to fit the true posterior

suppose the circle (a Gaussian) is q , you can adjust the mean and variance to fit the true posterior

The trick of variational inference is not uncommon, basically you can define a distance between the true posterior and the q which you can optimize. Usually this is done by doing some math manipulations and you can get one thing called ELBO (the evidence lower bound) and then you just optimize this ELBO to get the things you want.

One thing for using variational-inference-based approximation is because it is kind of universal and general.

Remember the textbook example, when we start to view linear regression in a Bayesian view, and if we set the distribution of error to be a Gaussian, then we find that in the end it turns out that we are optimizing the least square error.

I guess this is the same thing going on here. As in the NeurIPS tutorial from Khan.

He first introduced the following general learning rule, the Bayes learning rule

And then by filling the holes by the right assumptions, you find out that it is just some standard learning optimizers like SGD.

There are also more sophisticated cases! By play the assumptions right, you can also get optimizers like RMSprop and Adam.

Of course, it also means you can run further, you can derive more complicated algorithms, for example, by assuming the posterior to be not just a gaussian, but a mixture of gaussian.

However, the problem of variational-inference based approximation is that it is very computational costy. In fact, some methods only do this variational inference for the last layer. This is really an important and practical issue.

In the paper called , it finally makes to be practical.

But really, how good is it?

as a representative work of variational inference based method, , a NeurIPS 2019 paper, it says:

By applying techniques such as batch normalisation, data augmentation, and distributed training, we achieve similar performance in about the same number of epochs as the Adam optimiser, even on large datasets such as ImageNet.

The author says it only takes twice to three times of the time compared with Adam, from what I understand, I think this is very impressive.

But you can see the tricky situation here, remember the reason we start to be Bayesian, we want this posterior to give us better accuracy, better generalization, better uncertainty measure. But after you paid so much efforts, derived such a general framework and spent so much time into the techniques for the practical implementation, and in the end, this “similar performance to Adam” is what you get.

Seriously. It is not okay.

Option 2: Interpolation-based Approximation

The above mentioned variational inference-based approximation may seems too complicated to be useful, consider all the math and implementational efforts paid to make it work. But the interpolation-based method described below, might seem like the contrary, it seems too simple to be useful (but in fact it works)

Also there are many works categorized in this name, which I list below

But I would like to start simply, just when we run the standard optimizer, such as Adam, interpolation-based approximation only requires to select and keep record of some points that are visited during the trajectory of the optimization. And then after you’re done, you use some of collected point to do interpolation to approximate the posterior. ( In extreme case, suppose you only want the mean of the posterior, then simply do weighted average, even unweighted average)

This is in fact, quite straight forward, collecting some points during the optimization trajectory does not require extra computation, there is only some requirement of space to store these points.

Of course, how to collect the points and how to interpolate are still an unexplored space of investigation. Any heuristics that makes sense and happen to work well can be applied here. For curiosity, I would recommend you to look into the above mentioned papers on interpolation-based methods. I assure you that even seems to be complicated and full of math, these methods are essentially very simple and intuitive to follow.

How good is it? From what I understand, it should be slightly better than Adam. So yes, it should be much better than variational inference based approximations. Not to mention that it does not require extra computation (unlike variational inference based)

Part 3: What goes wrong? A simple baseline and a simple experiment

One thing that I want to remind readers is that, we start using bayesian neural network, because of the promises. It says, or people claimed that it will improve the accuracy, give calibrated uncertainty, robustness and generalization, etc. But in practice, it is hard to achieve such promises.

A simple baseline

In fact, there is a very simple baseline, to use an ensemble of neural networks. We initialize many different models with different random initialization, and train them independently.

see Simple and scalable predictive uncertainty estimation using deep ensembles.

At the end we can get many models, we say these set of models can approximate the true posterior. For example, we can average the prediction by these many models and say it is a approximation of the Bayesian Model average.

A simple experiment

It is shown that this simple baseline of making an ensemble, is actually better in terms of both accuracy and uncertainty.

I refer to a experiment from

Can You Trust Your Model’s Uncertainty? Evaluating Predictive Uncertainty Under Dataset Shift, NeurIPS 2019

It benchmarks a lot of Bayesian Deep Learning methods see Bayesian Deep Learning Benchmarks.

Basically in the paper it uses a experiment setting of gradually shifting the distribution of data. This enables to see the gradual trend of degradation of different methods.

for left to right is the shift of data. The top figure is accuracy (the higher the better) the bottom figure is the metric for uncertainty (the lower the better)

for left to right is the shift of data. The top figure is accuracy (the higher the better) the bottom figure is the metric for uncertainty (the lower the better)

You can see that Deep Ensemble is really good in both accuracy and uncertainty, but wait…

A simple explanation

Why this simple baseline of ensemble is so good? What is missing? I will now give a simple explanation.

The reason is that, the DNN is different from simple linear regression, it is different because it is overparameterized and is so complicated. According the lottery ticket hypothesis, there could be many many high-performing local minima you can find in a network. With different random initialization you can result in a diverse set of high-performing local minima.

Let me introduce this figure to show what goes wrong.

Now you can see why comparing ensemble is really not fair. To be fair, what we need this

In order to compare with ensemble:

Part 4: A New Hope

Advice 1: Structure, not weights

Right now the estimate of posterior is focused on the weights of a neural network, but in fact we know

And this is not new either, MacKay proposes to do so in the 90s. But the problem is again the overparameterization, how can we possibly eunmerate all possible architectures in this world?

Sure, so heuristic can be employed. Let us wait and see what will happen.

Advice 2: Think of the purpose and more specific use of the posterior

Advice 1 might be too hard and too fundamental a question to ask, let us know consider a more practical one. The logic is quite simple, in practice, we are not actually interested in \(P(\theta \vert D)\) itself, but rather the things we can do with the posterior.

I believe this should have some impact on more specific usage of neural networks, such as transfer or meta-learning, which are the exact case where we need posterior of parameters.

Suppose we have a posterior, and we might be able to determine when it can transfer useful information, and when it transfers non-sense. There are really many technical possiblities we can do with a posterior (approximated using ensemble). In fact, there is an interesting paper on how we can use uncertainty to detect at test time, whether the test input is out-of-distribution.

[Detecting Extrapolation with Local Ensembles](https://arxiv.org/abs/1910.09573) ICLR 2020

Note that It makes a post-hoc ensemble to approximate the posterior.

To Conclude

So to conclude, I give a short survey of the so-called Bayesian Deep Learning. In PART 1: I give the motivation of Bayesian Deep Learning. PART 2: for the goal of obtaining a posterior distribution of models, not just a single model, I introduce two technical approach namely variational-inference based, and interpolation-based approximations. In PART 3: I talk about ensemble as simple baseline, and discuss why ensemble works so well by visiting a diverse set of high-performing local minima. In PART 4 I give two personal advice. The first is to also consider the possible architectures, not just the weight, and the second is to consider the potential benefits of posterior, not just in standard setting, but for transfer or meta learning.

I list some interesting materials for reading. Note that these are not technical papers.