owned this note
owned this note
Published
Linked with GitHub
---
title: DeepNN Notes on Why Deep Networks Generalize
tags: DeepNN, Teaching, Lecture Notes
description: Lecture notes on how classical learning theory and generalisation theory was unable to explain the good performance of deep neural netwoks, and new insights that were needed
---
# Deep Learning Shouldn't Work (But it Does)
In these notes, to accompany lecture 3 of the DeepNN module, I'm going to illustrate the classical learning theory view on generarlisation in machine learning, and explain how it fails to predict the surprisingly good generalisation performance of huge deep neural networks. I'm then going to briefly mention a few new insights and tools that allow us to understand why deep learning works.
## Classical view on generalisation.
Recall components of the classical view of genearlisation from [Neil's notes](https://mlatcl.github.io/deepnn/background/background-generalisation.html):
* expected error/risk/generalisation error $R(\mathbf{w})$: how well a model with parameters $\mathbf{w}$ does on a test distribution
* empirical loss $\hat{R}(\mathbf{w}, \mathcal{D}) = \frac{1}{N}\sum L(x_n, y_n, \mathbf{w})$: the expected loss on a finite training dataset $\mathcal{D} = \{(x_n, y_n), n=1\ldots N\}$
* a model class: the different values $\mathbf{w}$ can take, or the different predictors we can implement by setting the value of $\mathbf{w}$
The following picture illustrates how traditional learning theory reasons about generalisation of various models:
![](https://i.imgur.com/qNXjBnc.png)
Our ultimate goal is to find parameters within the model class which have sufficiently low risk or test loss, which is illustrated by the magenta set. In empirical risk minimization (ERM), we do this by minimising the empirical loss on a given training dataset assumed to be sampled from the same distribution that appears in the definition of the risk. The model that minimises the empirical risk (or perhaps a regularised version of it) is shown by the green star.
The question of generalisation is, under what assumptions can we guarantee that the green star falls within the magenta set with high probability (we can't guarantee that this happens all the time, which is what the so called *no free lunch* theoems state). Most results in learning theory gave guarantees in tems of the size or complexity of the model class: If the model class is sufficiently small, with sufficient data we can guarantee that minimising empirical risk leads to low (test) risk.
There are a number of different results along these lines and a number of different ways to capture the richness of model class, including [Rademacher complexity](https://en.wikipedia.org/wiki/Rademacher_complexity) and the [VC-dimension](https://en.wikipedia.org/wiki/Vapnik%E2%80%93Chervonenkis_dimension). But the story has largely been the same: the larger the model class, the less we can expect machine learning to generalise.
However, the model class described by deep neural networks is very rich. Thus, based on the complexity of model class, we shouldn't expect deep learning to work. A lot of people were skeptical about ever-growing neural networks, and expected them to stop working once the model class is too rich for generalisation
## The missing piece of the story
But despite these predictions, deep neural networks do seem to generalise well (i.e. the gap between training and test loss is often small). So what's going on?
### Multiple "global" minima
There are a number of ways deep learning is different from the classical view. One important difference is that the minimum of the empirical risk is not unique, in the following sense. The loss function in deep learning is non-convex, and as such it may have many local minima. People initially thought this is a problem, because gradient-based optimisation might get stuck in a poor local minimum and achieve sub-optimal performance.
However, what seems to be the case, at least in some applications, is that although there are many local optima, most of these are virtually equally good. For example, in image classification with large enough neural networks, there are several local minima, each of which achieve zero misclassiciation error on the training set. In this sense, it makes sense to think of these very good local minima as if they were all multiple global minima, as Neil likes to say. So the following picture is more appropriate in this situation:
![](https://i.imgur.com/8QF5yp4.png)
Instead of a single green star, we now have a whole set of models which are virtually indistinguishably good on the training set. The reasoning of generalisation theory would be to guarantee that the green set to be inside the magenta set with a high probability. However, this **does not happen** for large neural networks. Several papers demonstrate that it is possible to find neural networks that have zero training error (green set) yet arbitrarily poor test error. One of the first paper that highlighted this was ([Zhang et al, 2016](https://arxiv.org/abs/1611.03530)) with the title "Understanding deep learning requires rethinking generalization".
So, if classical genealisation theory doesn't work, how can we explain why deep learning works at all? Turns out, we have to consider more than just the model class and loss function, and also take into account the optimisation algorithm we use to find one of the minima in the green set.
Let's run a thought experiment where we train a neural netwok on the same dataset multiple times, but from a different randomly chosen initialization each time. Because the initialisation is random, we'll end up with a distibution of trained models, it's likely we will find a different "global" minimum each time:
![](https://i.imgur.com/dykku9I.png)
What seems to be the case is that stochastic gradient descent (SGD) with random initialisation does not find all of the minima of the training loss with equal probability. It seems to prefer certain minima over others, and this bias or preference turns out to be in favour of minima that generalise well. In other words, while the whole of the green set cannot be guaranteed to be inside the magenta set, the majority of the solutions that SGD finds inside this green set are. Making this kind of statement required completely new approaches to generalisation theory, which also considers the *implicit regularisation* of optimization methods.
## Further reading: new insights
Here I give a few pointers to new insights that the community has developed in the past 5 years to help us understand why deep learning works.
### Infinite-width networks, neural tangent kernels
Interesting insights can be gained by studying the limit where we increase the number of units at every layer of a neural network to infinity. This regime has been studied before, and when we randomly choose the weight of such an infinitely wide network, they start to behave like Gaussian processes ([Neal, 1994](https://arxiv.org/pdf/1912.02803.pdf)). However, we know know a bit more about infinitely wide networks: we can also tell how they evolve during gradient descent optimisation. This allows us to connect neural network training with kernel methods, whose generalisation properties are better understood. I wrote a [blog post](https://arxiv.org/pdf/1912.02803.pdf) on NTKs if you're intersted in more detail.
### Study of deep linear models
As I mentioned elsewhere in the notes, the study of deep linear networks can teach us a lot about the implicit regularisation behaviour of gradient descent. [Arora et al, (2019)](https://papers.nips.cc/paper/2019/file/c0c783b5fc0d7d808f1d14a6e9c8280d-Paper.pdf) consider the problem of matrix completion, with deep linear models. As discussed above, deep linear models (deep nets without the nonlinearity $\phi$) are the same as ordinary linear models, because the composition of linear functions is still a linear function. Yet, it turns out that if you redundantly parametrise linear functions in this way, and train them using gradient descent, you get different solutions depending on the parametrization and initialization. The reason why I mention this here is to highlight that reasoning about the model class neural networks can represent only tells you a small part of the story as to why they are useful.
### New generalisation theory
Since the seminal paper of [Zhang et al, (2016)](https://arxiv.org/abs/1611.03530), researchers have been trying to develop new bounds on the generalisation of various deep learning algorithms. There are several avenues for current research, a recent paper titled "Fantastic Generalization Measures and Where to Find Them" ([Jiang et al, 2020](https://arxiv.org/abs/1912.02178)) surveys the most promising current approaches. There was even a competition held at the NeurIPS 2020 conference on which theory can predict the generalisation error of neural networks better ([Jiang et al, 2020](https://arxiv.org/abs/2012.07976)).