Towards Principled Methods for Training Generative Adversarial Networks
Martin Arjovsky, Léon Bottou
Introduction
Generative adversarial networks (GANs)(Goodfellow et al., 2014a) have achieved great success at generating realistic and sharp looking images. However, they are widely general methods, now starting to be applied to several other important problems, such as semisupervised learning, stabilizing sequence learning methods for speech and language, and 3D modelling. (Denton et al., 2015; Radford et al., 2015; Salimans et al., 2016; Lamb et al., 2016; Wu et al., 2016)
However, they still remain remarkably difficult to train, with most current papers dedicated to heuristically finding stable architectures. (Radford et al., 2015; Salimans et al., 2016)
Despite their success, there is little to no theory explaining the unstable behaviour of GAN training. Furthermore, approaches to attacking this problem still rely on heuristics that are extremely sensitive to modifications. This makes it extremely hard to experiment with new variants, or to use them in new domains, which limits their applicability drastically. This paper aims to change that, by providing a solid understanding of these issues, and creating principled research directions towards adressing them.
It is interesting to note that the architecture of the generator used by GANs doesn’t differ significantly from other approaches like variational autoencoders (Kingma & Welling, 2013). After all, at the core of it we first sample from a simple prior , and then output our final sample , sometimes adding noise in the end. Always, is a neural network parameterized by , and the main difference is how is trained.
If , then is a point with higher probability of coming from the data than being a generated sample. This is the core of the phenomenon commonly described as ‘mode dropping’: when there are large regions with high values of , but small or zero values in . It is important to note that when but , the integrand inside the KL grows quickly to infinity, meaning that this cost function assigns an extremely high cost to a generator’s distribution not covering parts of the data.
If , then has low probability of being a data point, but high probability of being generated by our model. This is the case when we see our generator outputting an image that doesn’t look real. In this case, when and , we see that the value inside the KL goes to 0, meaning that this cost function will pay extremely low cost for generating fake looking samples.
Generative adversarial networks are formulated in two steps. We first train a discriminator to maximize
One can show easily that the optimal discriminator has the shape
Why do updates get worse as the discriminator gets better? Both in the original and the new cost function.
Is the new cost function following a similar divergence to the ? If so, what are its properties?
Is there a way to avoid some of these issues?
The fundamental contributions of this paper are the answer to all these questions, and perhaps more importantly, to introduce the tools to analyze them properly. We provide a new direction designed to avoid the instability issues in GANs, and examine in depth the theory behind it. Finally, we state a series of open questions and problems, that determine several new directions of research that begin with our methods.
Sources of instability
Let be a function composed by affine transformations and pointwise nonlinearities, which can either be rectifiers, leaky rectifiers, or smooth strictly increasing functions (such as the sigmoid, tanh, softplus, etc). Then, is contained in a countable union of manifolds of dimension at most . Therefore, if the dimension of is less than the one of , will be a set of measure 0 in .
Since and are compact and disjoint, the distance between both sets. We now define
In the next theorem, we take away the disjoint assumption, to make it general to the case of two different manifolds. However, if the two manifolds match perfectly on a big part of the space, no discriminator could separate them. Intuitively, the chances of two low dimensional manifolds having this property is rather dim: for two curves to match in space in a specific segment, they couldn’t be perturbed in any arbitrarilly small way and still satisfy this property. To do this, we will define the notion of two manifolds perfectly aligning, and show that this property never holds with probability 1 under any arbitrarilly small perturbations.
We say that two manifolds without boundary and perfectly align if there is an such that and don’t intersect transversally in .
We shall note the boundary and interior of a manifold by and respectively. We say that two manifolds and (with or without boundary) perfectly align if any of the boundary free manifold pairs or perfectly align.
The interesting thing is that we can safely assume in practice that any two manifolds never perfectly align. This can be done since an arbitrarilly small random perturbation on two manifolds will lead them to intersect transversally or don’t intersect at all. This is precisely stated and proven in Lemma 2.
As stated by Lemma 3, if two manifolds don’t perfectly align, their intersection will be a finite union of manifolds with dimensions strictly lower than both the dimension of and the one of .
We now state our perfect discrimination result for the case of two manifolds.
Let . Therefore, (the complement of ) which is an open set, so there exists a ball of radius such that . This way, we define
Note that these divergences will be maxed out even if the two manifolds lie arbitrarilly close to each other. The samples of our generator might look impressively good, yet both KL divergences will be infinity. Therefore, Theorem 2.3 points us to the fact that attempting to use divergences out of the box to test similarities between the distributions we typically consider might be a terrible idea. Needless to say, if these divergencies are always maxed out attempting to minimize them by gradient descent isn’t really possible. We would like to have a perhaps softer measure, that incorporates a notion of distance between the points in the manifolds. We will come back to this topic later in section 3, where we explain an alternative metric and provide bounds on it that we are able to analyze and optimize.
2 The consequences, and the problems of each cost function
Theorems 2.1 and 2.2 showed one very important fact. If the two distributions we care about have supports that are disjoint or lie on low dimensional manifolds, the optimal discriminator will be perfect and its gradient will be zero almost everywhere.
We will now explore what happens when we pass gradients to the generator through a discriminator. One crucial difference with the typical analysis done so far is that we will develop the theory for an approximation to the optimal discriminator, instead of working with the (unknown) true discriminator. We will prove that as the approximaton gets better, either we see vanishing gradients or the massively unstable behaviour we see in practice, depending on which cost function we use.
In what follows, we denote by the norm
The use of this norm is to make the proofs simpler, but could have been done in another Sobolev norm for covered by the universal approximation theorem in the sense that we can guarantee a neural network approximation in this norm (Hornik, 1991).
Under the same assumptions of Theorem 2.4
This shows that as our discriminator gets better, the gradient of the generator vanishes. For completeness, this was experimentally verified in Figure 2. The fact that this happens is terrible, since the fact that the generator’s cost function being close to the Jensen Shannon divergence depends on the quality of this approximation. This points us to a fundamental: either our updates to the discriminator will be inacurate, or they will vanish. This makes it difficult to train using this cost function, or leave up to the user to decide the precise amount of training dedicated to the discriminator, which can make GAN training extremely hard.
2.2 The −logD𝐷-\log D alternative
To avoid gradients vanishing when the discriminator is very confident, people have chosen to use a different gradient step for the generator.
We now state and prove for the first time which cost function is being optimized by this gradient step. Later, we prove that while this gradient doesn’t necessarily suffer from vanishing gradients, it does cause massively unstable updates (that have been widely experienced in practice) under the prescence of a noisy approximation to the optimal discriminator.
We already know by Goodfellow et al. (2014a) that
Furthermore, as remarked by Huszar (2016),
Taking derivatives in at we get
Substracting this last equation with the result for the JSD, we obtain our desired result. ∎
We now turn to our result regarding the instability of a noisy version of the true distriminator.
is a centered Cauchy distribution with infinite expectation and variance.Note that the theorem holds regardless of the variance of and . As the approximation gets better, this error looks more and more as centered random noise due to the finite precision.
Since is a centered Gaussian distribution, multiplying by a matrix doesn’t change this fact. Furthermore, when we divide by , a centered Gaussian independent from the numerator, we get a centered Cauchy random variable on every coordinate. Averaging over the different independent Cauchy random variables again yields a centered Cauchy distribution. A note on technicality: when is defined as such, the remaining process is not measurable in , so we can’t take the expectation in trivially. This is commonly bypassed, and can be formally worked out by stating the expectation as the result of a stochastic differential equation. ∎
Note that even if we ignore the fact that the updates have infinite variance, we still arrive to the fact that the distribution of the updates is centered, meaning that if we bound the updates the expected update will be 0, providing no feedback to the gradient.
Since the assumption that the noises of and are decorrelated is albeit too strong, we show in Figure 3 how the norm of the gradient grows drastically as we train the discriminator closer to optimality, at any stage in training of a well stabilized DCGAN except when it has already converged. In all cases, using this updates lead to a notorious decrease in sample quality. The noise in the curves also shows that the variance of the gradients is increasing, which is known to delve into slower convergence and more unstable behaviour in the optimization (Bottou et al., 2016).
Towards softer metrics and distributions
An important question now is how to fix the instability and vanishing gradients issues. Something we can do to break the assumptions of these theorems is add continuous noise to the inputs of the discriminator, therefore smoothening the distribution of the probability mass.
If then
If then
If then
and we want to calculate what the gradient passed to the generator is.
where and are positive functions. Furthermore, if and only if , and if and only if .
In the same as with Theorem 3.2, and will have the same properties. The main difference is that we will be moving all our noisy samples towards the data manifold, which can be thought of as moving a small neighbourhood of samples towards it. This will protect the discriminator against measure 0 adversarial examples.
Since the discriminator is assumed fixed when backproping to the generator, the only thing that depends on is for every . By taking derivatives on our cost function
Let the density of be . We now define
Trivially, and are positive functions. Since , we know that if and only if , and if and only if as we wanted. Continuing the proof, we know
We recall the definition of the Wasserstein metric for and two distributions over . Namely,
where is the set of all possible joints on that have marginals and .
The Wasserstein distance also goes by other names, most commonly the transportation metric and the earth mover’s distance. This last name is most explicative: it’s the minimum cost of transporting the whole probability mass of from its support to match the probability mass of on ’s support. This identification of transporting points from to is done via the coupling . We refer the reader to Villani (2009) for an in-depth explanation of these ideas. It is easy to see now that the Wasserstein metric incorporates the notion of distance (as also seen inside the integral) between the elements in the support of and the ones in the support of , and that as the supports of and get closer and closer, the metric will go to 0, inducing as well a notion of distance between manifolds.
If is a random vector with mean 0, then we have
where the last inequality was due to Jensen. ∎
The first author would like to especially thank Luis Scoccola for help with the proof of Lemma 1.
The authors would also like to thank Ishmael Belghazi, Yoshua Bengio, Gerry Che, Soumith Chintala, Caglar Gulcehre, Daniel Jiwoong Im, Alex Lamb, Luis Scoccola, Pablo Sprechmann, Arthur Szlam, Jake Zhao for insightful comments and advice.
References
Appendix A Proofs of things
The proof for the second case is technical and slightly more involved. When is a pointwise smooth strictly increasing nonlinearity, then applying it vectorwise it’s a diffeomorphism to its image. Therefore, it sends a countable union of manifolds of dimension to a countable union of manifolds of dimension . If we can prove the same thing for affine transformations we will be finished, since is just a composition of these applied to a dimensional manifold. Of course, it suffices to prove that an affine transformation sends a manifold to a countable union of manifolds without increasing dimension, since a countable union of countable unions is still a countable union. Furthermore, we only need to show this for linear transformations, since applying a bias term is a diffeomorphism.
Now we consider the case where and are manifolds with boundary. By a simple union bound,
Let and . We again consider first the case where and are manifolds without boundary. If , then so the statement is obviously true. If , then and intersect transversally. This implies that is a manifold of dimension . Since is a submanifold of both and that has lower dimension, it has measure 0 on both of them.
We now tackle the case where and have boundaries. Let us remember that and the union is disjoint (and analogously for ). By using elementary properties of sets, we can trivially see that
where the unions are disjoint. This is the disjoint union of 4 strictly lower dimensional manifolds, by using the first part of the proof. Since each one of these intersections has measure 0 on either the interior or boundary of (again, by the first part of the proof), and interior and boundary are contained in , each one of the four intersections has measure 0 in . Analogously, they have measure 0 in , and by a simple union bound we see that has measure 0 in and finishing the remaining case of the proof. ∎
Appendix B Further Clarifications
In this appendix we further explain some of the terms and ideas mentioned in the paper, which due to space constrains, and to keep the flow of the paper, couldn’t be extremely developed in the main text. Some of these have to do with notation, others with technical elements of the proofs. On the latter case, we try to convey more intuition than we previously could. We present these clarifications in a very informal fashion in the following item list.
The annoying part is that in everyday paper writing when we talk about continuous random variables, we omit the ‘absolutely’ word to keep the text concise and actually talk about absolutely continuous random variables (ones that have a density), this is done through almost all sciences and throughout mathematics as well, annoying as it is. However we made the clarification in here since it’s relevant to our paper not to mistake the two terms.
In the proof of Theorem 2.1, the distance between sets is defined as the usual distance between sets in a metric space
where is the distance between points (in our case the Euclidean distance).
Whatever happens elsewhere is irrelevant (as it is also reflected by the cost of the discriminator)