Code of "Max-margin Deep Generative Models" (NIPS15)
Deep generative models (DGMs) are effective on learning multilayered representations of complex data and performing inference of input data by exploring the generative ability. However, little work has been done on examining or empowering the discriminative ability of DGMs on making accurate predictions. This paper presents max-margin deep generative models (mmDGMs), which explore the strongly discriminative principle of max-margin learning to improve the discriminative power of DGMs, while retaining the generative capability. We develop an efficient doubly stochastic subgradient algorithm for the piecewise linear objective. Empirical results on MNIST and SVHN datasets demonstrate that (1) max-margin learning can significantly improve the prediction performance of DGMs and meanwhile retain the generative ability; and (2) mmDGMs are competitive to the state-of-the-art fully discriminative networks by employing deep convolutional neural networks (CNNs) as both recognition and generative models.READ FULL TEXT VIEW PDF
Deep generative models (DGMs) are effective on learning multilayered
Metrics specifying distances between data points can be learned in a
This thesis investigates unsupervised time series representation learnin...
Building models capable of generating structured output is a key challen...
Humans have an impressive ability to reason about new concepts and
A primary goal of computational phenotype research is to conduct medical...
A deep generative model is developed for representation and analysis of
Code of "Max-margin Deep Generative Models" (NIPS15)
Max-margin learning has been effective on learning discriminative models, with many examples such as univariate-output support vector machines (SVMs) and multivariate-output max-margin Markov networks (or structured SVMs) [30, 1, 31]. However, the ever-increasing size of complex data makes it hard to construct such a fully discriminative model, which has only single layer of adjustable weights, due to the facts that: (1) the manually constructed features may not well capture the underlying high-order statistics; and (2) a fully discriminative approach cannot reconstruct the input data when noise or missing values are present.
To address the first challenge, previous work has considered incorporating latent variables into a max-margin model, including partially observed maximum entropy discrimination Markov networks , structured latent SVMs  and max-margin min-entropy models . All this work has primarily focused on a shallow structure of latent variables. To improve the flexibility, learning SVMs with a deep latent structure has been presented in . However, these methods do not address the second challenge, which requires a generative model to describe the inputs. The recent work on learning max-margin generative models includes max-margin Harmoniums , max-margin topic models [34, 35], and nonparametric Bayesian latent SVMs  which can infer the dimension of latent features from data. However, these methods only consider the shallow structure of latent variables, which may not be flexible enough to describe complex data.
Much work has been done on learning generative models with a deep structure of nonlinear hidden variables, including deep belief networks[25, 16, 23]13, 9], and stochastic variations of neural networks . For such models, inference is a challenging problem, but fortunately there exists much recent progress on stochastic variational inference algorithms [12, 24]
. However, the primary focus of deep generative models (DGMs) has been on unsupervised learning, with the goals of learning latent representations and generating input samples. Though the latent representations can be used with a downstream classifier to make predictions, it is often beneficial to learn a joint model that considers both input and response variables. One recent attempt is the conditional generative models, which treat labels as conditions of a DGM to describe input data. This conditional DGM is learned in a semi-supervised setting, which is not exclusive to ours.
In this paper, we revisit the max-margin principle and present a max-margin deep generative model (mmDGM), which learns multi-layer representations that are good for both classification and input inference. Our mmDGM conjoins the flexibility of DGMs on describing input data and the strong discriminative ability of max-margin learning on making accurate predictions. We formulate mmDGM as solving a variational inference problem of a DGM regularized by a set of max-margin posterior constraints, which bias the model to learn representations that are good for prediction. We define the max-margin posterior constraints as a linear functional of the target variational distribution of the latent presentations. Then, we develop a doubly stochastic subgradient descent algorithm, which generalizes the Pagesos algorithm  to consider nontrivial latent variables. For the variational distribution, we build a recognition model to capture the nonlinearity, similar as in [12, 24].
We consider two types of networks used as our recognition and generative models: multiple layer perceptrons (MLPs) as in[12, 24] and convolutional neural networks (CNNs) . Though CNNs have shown promising results in various domains, especially for image classification, little work has been done to take advantage of CNN to generate images. The recent work  presents a type of CNN to map manual features including class labels to RBG chair images by applying unpooling, convolution and rectification sequentially; but it is a deterministic mapping and there is no random generation. Generative Adversarial Nets  employs a single such layer together with MLPs in a minimax two-player game framework with primary goal of generating images. We propose to stack this structure to form a highly non-trivial deep generative network to generate images from latent variables learned automatically by a recognition model using standard CNN. We present the detailed network structures in experiments part. Empirical results on MNIST  and SVHN  datasets demonstrate that mmDGM can significantly improve the prediction performance, which is competitive to the state-of-the-art methods [33, 17, 8, 15], while retaining the capability of generating input samples and completing their missing values.
We start from a general setting, where we have i.i.d. data . A deep generative model (DGM) assumes that each is generated from a vector of latent variables
, which itself follows some distribution. The joint probability of a DGM is as follows:
where is the prior of the latent variables and is the likelihood model for generating observations. For notation simplicity, we define . Depending on the structure of , various DGMs have been developed, such as the deep belief networks [25, 16], deep sigmoid networks , deep latent Gaussian models , and deep autoregressive models . In this paper, we focus on the directed DGMs, which can be easily sampled from via an ancestral sampler.
However, in most cases learning DGMs is challenging due to the intractability of posterior inference. The state-of-the-art methods resort to stochastic variational methods under the maximum likelihood estimation (MLE) framework,. Specifically, let be the variational distribution that approximates the true posterior . A variational upper bound of the per sample negative log-likelihood (NLL) is:
where is the Kullback-Leibler (KL) divergence between distributions and . Then, upper bounds the full negative log-likelihood .
It is important to notice that if we do not make restricting assumption on the variational distribution , the lower bound is tight by simply setting . That is, the MLE is equivalent to solving the variational problem: . However, since the true posterior is intractable except a handful of special cases, we must resort to approximation methods. One common assumption is that the variational distribution is of some parametric form, , and then we optimize the variational bound w.r.t the variational parameters . For DGMs, another challenge arises that the variational bound is often intractable to compute analytically. To address this challenge, the early work further bounds the intractable parts with tractable ones by introducing more variational parameters . However, this technique increases the gap between the bound being optimized and the log-likelihood, potentially resulting in poorer estimates. Much recent progress [12, 24, 21] has been made on hybrid Monte Carlo and variational methods, which approximates the intractable expectations and their gradients over the parameters
via some unbiased Monte Carlo estimates. Furthermore, to handle large-scale datasets, stochastic optimization of the variational objective can be used with a suitable learning rate annealing scheme. It is important to notice that variance reduction is a key part of these methods in order to have fast and stable convergence.
Most work on directed DGMs has been focusing on the generative capability on inferring the observations, such as filling in missing values [12, 24, 21], while little work has been done on investigating the predictive power, except the semi-supervised DGMs  which builds a DGM conditioned on the class labels and learns the parameters via MLE. Below, we present max-margin deep generative models, which explore the discriminative max-margin principle to improve the predictive ability of the latent representations, while retaining the generative capability.
We consider supervised learning, where the training data is a pairwith input features and the ground truth label . Without loss of generality, we consider the multi-class classification, where
. A max-margin deep generative model (mmDGM) consists of two components: (1) a deep generative model to describe input features; and (2) a max-margin classifier to consider supervision. For the generative model, we can in theory adopt any DGM that defines a joint distribution overas in Eq. (1). For the max-margin classifier, instead of fitting the input features into a conventional SVM, we define the linear classifier on the latent representations, whose learning will be regularized by the supervision signal as we shall see. Specifically, if the latent representation is given, we define the latent discriminant function where is an -dimensional vector that concatenates subvectors, with the th being and all others being zero, and is the corresponding weight vector.
We consider the case that is a random vector, following some prior distribution . Then our goal is to infer the posterior distribution , which is typically approximated by a variational distribution for computational tractability. Notice that this posterior is different from the one in the vanilla DGM. We expect that the supervision information will bias the learned representations to be more powerful on predicting the labels at testing. To account for the uncertainty of , we take the expectation and define the discriminant function and the final prediction rule that maps inputs to outputs is:
Note that different from the conditional DGM , which puts the class labels upstream, the above classifier is a downstream model, in the sense that the supervision signal is determined by conditioning on the latent representations.
We want to jointly learn the parameters and infer the posterior distribution . Based on the equivalent variational formulation of MLE, we define the joint learning problem as solving:
where is the difference of the feature vectors;
is the loss function that measures the cost to predictif the true label is ; and is a nonnegative regularization parameter balancing the two components. In the objective, the variational bound is defined as , and the margin constraints are from the classifier (3). If we ignore the constraints (e.g., setting at 0), the solution of will be exactly the Bayesian posterior, and the problem is equivalent to do MLE for .
By absorbing the slack variables, we can rewrite the problem in an unconstrained form:
where the hinge loss is: Due to the convexity of function, it is easy to verify that the hinge loss is an upper bound of the training error of classifier (3), that is, . Furthermore, the hinge loss is a convex functional over the variational distribution because of the linearity of the expectation operator. These properties render the hinge loss as a good surrogate to optimize over. Previous work has explored this idea to learn discriminative topic models , but with a restriction on the shallow structure of hidden variables. Our work presents a significant extension to learn deep generative models, which pose new challenges on the learning and inference.
The variational formulation of problem (5) naturally suggests that we can develop a variational algorithm to address the intractability of the true posterior. We now present a new algorithm to solve problem (5). Our method is a doubly stochastic generalization of the Pegasos (i.e., Primal Estimated sub-GrAdient SOlver for SVM) algorithm  for the classic SVMs with fully observed input features, with the new extension of dealing with a highly nontrivial structure of latent variables.
First, we make the structured mean-field (SMF) assumption that . Under the assumption, we have the discriminant function as Moreover, we can solve for the optimal solution of in some analytical form. In fact, by the calculus of variations, we can show that given the other parts the solution is where are the Lagrange multipliers (See  for details). If the prior is normal, , we have the normal posterior: Therefore, even though we did not make a parametric form assumption of , the above results show that the optimal posterior distribution of is Gaussian. Since we only use the expectation in the optimization problem and in prediction, we can directly solve for the mean parameter instead of . Further, in this case we can verify that and then the equivalent objective function in terms of can be written as:
where is the total hinge loss, and the per-sample hinge-loss is . Below, we present a doubly stochastic subgradient descent algorithm to solve this problem.
The first stochasticity arises from a stochastic estimate of the objective by random mini-batches. Specifically, the batch learning needs to scan the full dataset to compute subgradients, which is often too expensive to deal with large-scale datasets. One effective technique is to do stochastic subgradient descent , where at each iteration we randomly draw a mini-batch of the training data and then do the variational updates over the small mini-batch. Formally, given a mini batch of size
, we get an unbiased estimate of the objective:
The second stochasticity arises from a stochastic estimate of the per-sample variational bound and its subgradient, whose intractability calls for another Monte Carlo estimator. Formally, let be a set of samples from the variational distribution, where we explicitly put the conditions. Then, an estimate of the per-sample variational bound and the per-sample hinge-loss is
where . Note that is an unbiased estimate of , while is a biased estimate of . Nevertheless, we can still show that is an upper bound estimate of under expectation. Furthermore, this biasedness does not affect our estimate of the gradient. In fact, by using the equality , we can construct an unbiased Monte Carlo estimate of as:
where the last term roots from the hinge loss with the loss-augmented prediction . For and , the estimates of the gradient and the subgradient are easier, which are:
Notice that the sampling and the gradient only depend on the variational distribution, not the underlying model.
The above estimates consider the general case where the variational bound is intractable. In some cases, we can compute the KL-divergence term analytically, e.g., when the prior and the variational distribution are both Gaussian. In such cases, we only need to estimate the rest intractable part by sampling, which often reduces the variance . Similarly, we could use the expectation of the features directly, if it can be computed analytically, in the computation of subgradients (e.g., and ) instead of sampling, which again can lead to variance reduction.
With the above estimates of subgradients, we can use stochastic optimization methods such as SGD  and AdaM  to update the parameters, as outlined in Alg. 1. Overall, our algorithm is a doubly stochastic generalization of Pegasos to deal with the highly nontrivial latent variables.
Now, the remaining question is how to define an appropriate variational distribution to obtain a robust estimate of the subgradients as well as the objective. Two types of methods have been developed for unsupervised DGMs, namely, variance reduction  and auto-encoding variational Bayes (AVB) . Though both methods can be used for our models, we focus on the AVB approach. For continuous variables , under certain mild conditions we can reparameterize the variational distribution using some simple variables . Specifically, we can draw samples from some simple distribution and do the transformation to get the sample of the distribution . We refer the readers to  for more details. In our experiments, we consider the special Gaussian case, where we assume that the variational distribution is a multivariate Gaussian with a diagonal covariance matrix:
whose mean and variance are functions of the input data. This defines our recognition model. Then, the reparameterization trick is as follows: we first draw standard normal variables and then do the transformation to get a sample. For simplicity, we assume that both the mean and variance are function of only. However, it is worth to emphasize that although the recognition model is unsupervised, the parameters are learned in a supervised manner because the subgradient (7) depends on the hinge loss. Further details of the experimental settings are presented in Sec. 4.1.
We now present experimental results on the widely adopted MNIST  and SVHN  datasets. Though mmDGMs are applicable to any DGMs that define a joint distribution of and , we concentrate on the Variational Auto-encoder (VA) 
, which is unsupervised. We denote our mmDGM with VA by MMVA. In our experiments, we consider two types of recognition models: multiple layer perceptrons (MLPs) and convolutional neural networks (CNNs). We implement all experiments based on Theano. 111The source code is available at https://github.com/zhenxuan00/mmdgm.
with convolution and max-pooling operation as the recognition model to obtain more competitive classification results. For the generative model, we use unconvnets with a “symmetric” structure as the recognition model, to reconstruct the input images approximately. More specifically, the top-down generative model has the same structure as the bottom-up recognition model but replacing max-pooling with unpooling operation  and applies unpooling, convolution and rectification in order. The total number of parameters in the convolutional network is comparable with previous work [8, 17, 15]. For simplicity, we do not involve mlpconv layers [17, 15] and contrast normalization layers in our recognition model, but they are not exclusive to our model. We illustrate details of the network architectures in appendix A.
In both settings, the mean and variance of the latent are transformed from the last layer of the recognition model through a linear operation. It should be noticed that we could use not only the expectation of but also the activation of any layer in the recognition model as features. The only theoretical difference is from where we add a hinge loss regularization to the gradient and back-propagate it to previous layers. In all of the experiments, the mean of has the same nonlinearity but typically much lower dimension than the activation of the last layer in the recognition model, and hence often leads to a worse performance. In the MLP case, we concatenate the activations of 2 layers as the features used in the supervised tasks. In the CNN case, we use the activations of the last layer as the features. We use AdaM 
to optimize parameters in all of the models. Although it is an adaptive gradient-based optimization method, we decay the global learning rate by factor three periodically after sufficient number of epochs to ensure a stable convergence.
We denote our mmDGM with MLPs by MMVA. To perform classification using VA, we first learn the feature representations by VA, and then build a linear SVM classifier on these features using the Pegasos stochastic subgradient algorithm . This baseline will be denoted by VA+Pegasos. The corresponding models with CNNs are denoted by CMMVA and CVA+Pegasos respectively.
We present both the prediction performance and the results on generating samples of MMVA and VA+Pegasos with both kinds of recognition models on the MNIST  dataset, which consists of images of 10 different classes (0 to 9) of size with 50,000 training samples, 10,000 validating samples and 10,000 testing samples.
|Stochastic Pooling ||0.47|
|Network in Network ||0.47|
|Maxout Network ||0.45|
In the MLP case, we only use 50,000 training data, and the parameters for classification are optimized according to the validation set. We choose for MMVA and initialize it with an unsupervised pre-training procedure in classification. First three rows in Table 1 compare VA+Pegasos, VA+Class-condtionVA and MMVA, where VA+Class-condtionVA refers to the best fully supervised model in . Our model outperforms the baseline significantly. We further use the t-SNE algorithm  to embed the features learned by VA and MMVA on 2D plane, which again demonstrates the stronger discriminative ability of MMVA (See Appendix B for details).
In the CNN case, we use 60,000 training data. Table 2 shows the effect of on classification error rate and variational lower bound. Typically, as gets lager, CMMVA learns more discriminative features and leads to a worse estimation of data likelihood. However, if is too small, the supervision is not enough to lead to predictive features. Nevertheless, is quite a good trade-off between the classification performance and generative performance and this is the default setting of CMMVA on MNIST throughout this paper. In this setting, the classification performance of our CMMVA model is comparable to the recent state-of-the-art fully discriminative networks (without data augmentation), shown in the last four rows of Table 1.
|C||Error Rate (%)||Lower Bound|
We further investigate the generative capability of MMVA on generating samples. Fig. 1 illustrates the images randomly sampled from VA and MMVA models where we output the expectation of the gray value at each pixel to get a smooth visualization. We do not pre-train our model in all settings when generating data to prove that MMVA (CMMVA) remains the generative capability of DGMs.
SVHN  is a large dataset consisting of color images of size . The task is to recognize center digits in natural scene images, which is significantly harder than classification of hand-written digits. We follow the work [27, 8] to split the dataset into 598,388 training data, 6000 validating data and 26, 032 testing data and preprocess the data by Local Contrast Normalization (LCN).
We only consider the CNN recognition model here. The network structure is similar to that in MNIST. We set for our CMMVA model on SVHN by default.
|Stochastic Pooling ||2.80|
|Maxout Network ||2.47|
|Network in Network ||2.35|
Table 3 shows the predictive performance. In this more challenging problem, we observe a larger improvement by CMMVA as compared to CVA+Pegasos, suggesting that DGMs benefit a lot from max-margin learning on image classification. We also compare CMMVA with state-of-the-art results. To the best of our knowledge, there is no competitive generative models to classify digits on SVHN dataset with full labels.
We further compare the generative capability of CMMVA and CVA to examine the benefits from jointly training of DGMs and max-margin classifiers. Though CVA gives a tighter lower bound of data likelihood and reconstructs data more elaborately, it fails to learn the pattern of digits in a complex scenario and could not generate meaningful images. Visualization of random samples from CVA and CMMVA is shown in Fig. 2. In this scenario, the hinge loss regularization on recognition model is useful for generating main objects to be classified in images.
Finally, we test all models on the task of missing data imputation. For MNIST, we consider two types of missing values: (1) Rand-Drop: each pixel is missing randomly with a pre-fixed probability; and (2) Rect
: a rectangle located at the center of the image is missing. Given the perturbed images, we uniformly initialize the missing values between 0 and 1, and then iteratively do the following steps: (1) using the recognition model to sample the hidden variables; (2) predicting the missing values to generate images; and (3) using the refined images as the input of the next round. For SVHN, we do the same procedure as in MNIST but initialize the missing values with Guassian random variables as the input distribution changes. Visualization results on MNIST and SVHN are presented in Appendix C and Appendix D respectively.
|Rect (6 6)||0.0637||0.0645||0.0585||0.0597|
|Rect (8 8)||0.0850||0.0841||0.0754||0.0724|
|Rect (10 10)||0.1100||0.1079||0.0978||0.0884|
|Rect (12 12)||0.1450||0.1342||0.1299||0.1090|
Intuitively, generative models with CNNs could be more powerful on learning patterns and high-level structures, while generative models with MLPs lean more to reconstruct the pixels in detail. This conforms to the MSE results shown in Table 4: CVA and CMMVA outperform VA and MMVA with a missing rectangle, while VA and MMVA outperform CVA and CMMVA with random missing values. Compared with the baseline, mmDGMs also make more accurate completion when large patches are missing. All of the models infer missing values for 100 iterations.
We also compare the classification performance of CVA, CNN and CMMVA with Rect missing values in testing procedure in Appendix E. CMMVA outperforms both CVA and CNN.
Overall, mmDGMs have comparable capability of inferring missing values and prefer to learn high-level patterns instead of local details.
We propose max-margin deep generative models (mmDGMs), which conjoin the predictive power of max-margin principle and the generative ability of deep generative models. We develop a doubly stochastic subgradient algorithm to learn all parameters jointly and consider two types of recognition models with MLPs and CNNs respectively. In both cases, we present extensive results to demonstrate that mmDGMs can significantly improve the prediction performance of deep generative models, while retaining the strong generative ability on generating input samples as well as completing missing values. In fact, by employing CNNs in both recognition and generative models, we achieve low error rates on MNIST and SVHN datasets, which are competitive to the state-of-the-art fully discriminative networks.
The work was supported by the National Basic Research Program (973 Program) of China (Nos. 2013CB329403, 2012CB316301), National NSF of China (Nos. 61322308, 61332007), Tsinghua TNList Lab Big Data Initiative, and Tsinghua Initiative Scientific Research Program (Nos. 20121088071, 20141080934).
Journal of Machine Learning, 20(3):273–297, 1995.
Stochastic backpropagation and approximate inference in deep generative models.In ICML, 2014.
Deep Boltzmann machines.In AISTATS, 2009.
In all of our experiments, (C)VA and (C)MMVA share same structures and settings.
We set the dimension of the latent variables to 50 in all of the experiments on MNIST.
In MLP case, both the recognition and generative models employ a two-layer MLP with 500 hidden units in each layer. We illustrate the network architecture of MMVA with Gaussian hidden variables and Bernoulli visible variables in Fig. 3.
In CNN case, our convolutional network contains 5 convolution layers. There are 32 feature maps in the first two convolutional layers and 64 feature maps in the last three convolutional layers. We use filters of size 3 throughout the network except filters of size 5 in the first layer. Instead of global average pooling, a MLP with 500 hidden units is adopted at the end of the convolutional nets to obtain a tighter lower bound and better generation results. We also involve three dropout layers with keeping ratio 0.5. We illustrate the network architecture of CMMVA in Fig. 4.
We only consider CNN case here and the structure is similar with the CNN case on MNIST. We use 256 latent variables to capture the variation of data in pattern and scale and no MLP layer is adopted. There are 64 feature maps in the first three layers and 96 feature maps in the last two layers. We involve three dropout layers with keeping ratio 0.7.
We use a fully supervised CNN without dropout layers to initialize the recognition model of CMMVA to speed-up the convergence of the parameters and the initial error rate is 5.03%.
T-SNE embedding results of the features learned by VA and MMVA on 2D plane are shown in Fig. 5 (a) and Fig. 5 (b) respectively, using the same data points randomly sampled from the MNIST dataset. Compared to the VA’s embedding, MMVA separates the images from different categories better, especially for the confusable digits such as digit “4” and “9”. These results show that MMVA, which benefits from the max-margin principle, learns more discriminative representations of digits than VA.
The imputation results of CVA and CMMVA are shown in Fig. 6. CMMVA makes fewer mistakes and refines the images better, which accords with the MSE results as reported in the main text.
We visualize the inference procedure of MMVA for 20 iterations in Fig. 7. Considering both types of missing values, MMVA could infer the unknown values and refine the images in several iterations even with a large ratio of missing pixels.
We visualize the imputation results of CVA and CMMVA in Fig. 8 with Rect () noise. In most cases, CMMVA could complete the images with missing values on this much harder SVHN dataset. In the remaining cases, CMMVA fails potentially due to the changeful digit patterns and less color contrast compared with hand-writing digits dataset. Nevertheless, CMMVA achieves comparable results with CVA on inferring missing data.
We present classification results with missing values on MNIST in Table 5. CNN makes prediction on the incomplete data directly. CVA and CMMVA infer missing data for 100 iterations at first and then make prediction on the refined data. In this scenario, CMMVA outperforms both CVA and CNN, which demonstrates the advantages of our mmDGMs, which have both strong discriminative and generative capabilities.
|Rect (6 6)||7.5||2.5||1.9|
|Rect (8 8)||18.8||4.2||3.7|
|Rect (10 10)||30.3||8.4||7.7|
|Rect (12 12)||47.2||18.3||15.9|