Hybrid Models with Deep and Invertible Features

Eric Nalisnick, Akihiro Matsukawa, Yee Whye Teh, Dilan Gorur, Balaji Lakshminarayanan

Introduction

In the majority of applications, deep neural networks model conditional distributions of the form p(y∣x)p(y|{\bm{x}}), where yy denotes a label and x{\bm{x}} features or covariates. However, modeling just the conditional distribution is insufficient in many cases. For instance, if we believe that the model may be subjected to inputs unlike those of the training data, a model for p(x)p({\bm{x}}) can possibly detect an outlier before it is passed to the conditional model for prediction. Thus modeling the joint distribution p(y,x)p(y,{\bm{x}}) provides a richer and more useful representation of the data. Models defined by combining a predictive model p(y∣x)p(y|{\bm{x}}) with a generative one p(x)p({\bm{x}}) are known as hybrid models (Jaakkola & Haussler, 1999; Raina et al., 2004; Lasserre et al., 2006; Kingma et al., 2014). Hybrid models have been shown to be useful for novelty detection (Bishop, 1994), semi-supervised learning (Druck et al., 2007), and information regularization (Szummer & Jaakkola, 2003).

Crafting a hybrid model usually requires training two models, one for p(y∣x)p(y|{\bm{x}}) and one for p(x)p({\bm{x}}), that share a subset (Raina et al., 2004) or possibly all (McCallum et al., 2006) of their parameters. Unfortunately, training a high-fidelity p(x)p({\bm{x}}) model alone is difficult, especially in high dimensions, and good performance requires using a large neural network (Brock et al., 2019). Yet principled probabilistic inference is hard to implement with neural networks since they do not admit closed-form solutions and running Markov chain Monte Carlo takes prohibitively long. Variational inference then remains as the final alternative, and this now introduces a third model, which usually serves as the posterior approximation and/or inference network (Kingma & Welling, 2014; Kingma et al., 2014). To make matters worse, the p(y∣x)p(y|{\bm{x}}) model may require a separate approximate inference scheme, leading to additional computation and parameters.

In this paper, we propose a neural hybrid model that overcomes many of the aforementioned computational challenges. Most crucially, our model supports exact inference and evaluation of p(x)p({\bm{x}}). Furthermore, in the case of regression, Bayesian inference for p(y∣x)p(y|{\bm{x}}) is exact and available in closed-form as well. Our model is made possible by leveraging recent advances in deep invertible generative models (Rezende & Mohamed, 2015; Dinh et al., 2017; Kingma & Dhariwal, 2018). These models are defined by composing invertible functions, and therefore the change-of-variables formula can be used to compute exact densities. These invertible models have been shown to be expressive enough to perform well on prediction tasks (Gomez et al., 2017; Jacobsen et al., 2018). We use the invertible function as a natural feature extractor and define a linear model at the level of the latent representation, which is memory-efficient as the bulk of the parameters are shared between p(x)p({\bm{x}}) and p(y∣x)p(y|{\bm{x}}). Furthermore, with just one feed-forward pass we can obtain both p(x)p({\bm{x}}) and p(y∣x)p(y|{\bm{x}}), with the only additional cost being the log-determinant-Jacobian term required by the change of variables. While this term could be expensive to compute for general functions, much recent work has been done on defining expressive invertible neural networks with easy-to-evaluate volume elements (Dinh et al., 2015, 2017; Kingma & Dhariwal, 2018; Grathwohl et al., 2019).

Defining a neural hybrid model with exact inference and evaluation of p(y,x)p(y,{\bm{x}}), which can be computed in one feed-forward pass and without any Monte Carlo approximations.

Evaluating the model’s predictive accuracy and uncertainty on both classification and regression problems.

Using the model’s natural ‘reject’ rule based on the generative component p(x)p({\bm{x}}) to filter out-of-distribution (OOD) inputs.

Showing that our hybrid model performs well at semi-supervised classification.

Background

We begin by establishing notation and reviewing the necessary background material. We denote matrices with upper-case and bold letters (e.g. X{\bm{X}}), vectors with lower-case and bold (e.g. x{\bm{x}}), and scalars with lower-case and no bolding (e.g. xx). Let the collection of all observations be denoted D={X,y}={(xn,yn)n=1N}\mathcal{D}=\{{\bm{X}},{\bm{y}}\}=\{({\bm{x}}_{n},y_{n})_{n=1}^{N}\} with x{\bm{x}} representing a vector containing features and yy a scalar representing the corresponding label. We define a predictive model’s density function to be p(y∣x;θ)p(y|{\bm{x}};{\bm{\theta}}) and a generative density to be p(x;θ)p({\bm{x}};{\bm{\theta}}), where θ∈Θ{\bm{\theta}}\in\boldsymbol{\Theta} are the shared model parameters. Let the joint likelihood be denoted p(y,X;θ)=∏n=1Np(yn∣xn;θ)p(xn;θ)p({\bm{y}},{\bm{X}};{\bm{\theta}})=\prod_{n=1}^{N}p(y_{n}|{\bm{x}}_{n};{\bm{\theta}})p({\bm{x}}_{n};{\bm{\theta}}).

Deep invertible transformations are the first key building block in our approach. These are simply high-capacity, bijective transformations with a tractable Jacobian matrix and inverse. The best known models of this class are the real non-volume preserving (RNVP) transform (Dinh et al., 2017) and its recent extension, the Glow transform (Kingma & Dhariwal, 2018). The bijective nature of these transforms is crucial as it allows us to employ the change-of-variables formula for exact density evaluation:

where f(⋅;ϕ)f(\cdot;{\bm{\phi}}) denotes the transform with parameters ϕ{\bm{\phi}}, ∣∂f/∂x∣\left|\partial{\bm{f}}/\partial{\bm{x}}\right| the determinant of the Jacobian of the transform, and pz(z=f(⋅;ϕ))p_{z}({\bm{z}}=f(\cdot;{\bm{\phi}})) a distribution on the latent variables computed from the transform. The modeler is free to choose pzp_{z}, and therefore it is often set as a factorized standard Gaussian for computational simplicity. The affine coupling layer (ACL) (Dinh et al., 2017) is the key building block used by RNVP and Glow to define f(⋅;ϕ)f(\cdot;{\bm{\phi}}). It consists of transforming half of the representation with translation and scaling operations and copying the other half forward to the output. See Appendix A in the supplementary material for a detailed description of the ACL. Glow (Kingma & Dhariwal, 2018) introduces 1×11\times 1 convolutions between ACLs. The parameters ϕ{\bm{\phi}} are estimated via maximizing the exact log-likelihood log⁡p(X;ϕ)\log p({\bm{X}};{\bm{\phi}}).

While the invertibility requirements imposed on ff may seem too restrictive to define an expressive model, recent work using invertible transformations for classification (Jacobsen et al., 2018) reports metrics comparable to non-invertible residual networks, even on challenging benchmarks such as ImageNet, and recent work by Kingma & Dhariwal (2018) has shown that invertible generative models can produce sharp samples. Sampling from a flow is done by first sampling from the latent distribution and then passing that sample through the inverse transform: z^∼pz,\hat{{\bm{z}}}\sim p_{z}, x^=f−1(z^)\hat{{\bm{x}}}=f^{-1}(\hat{{\bm{z}}}).

2 Generalized Linear Models

Generalized linear models (GLMs) (Nelder & Baker, 1972) are the second key building block that we employ. They model the expected response yy as follows:

where σ0\sigma_{0} is the response noise. In the case of logistic regression, the posterior is no longer conjugate but can be closely approximated (Jaakkola & Jordan, 1997).

Combining Deep Invertible Transforms and Generalized Linear Models

We propose a neural hybrid model consisting of a deep invertible transform coupled with a GLM. Together the two define a deep predictive model with both the ability to compute p(x)p({\bm{x}}) and p(y∣x)p(y|{\bm{x}}) exactly, in a single feed-forward pass. The model defines the following joint distribution over a label-feature pair (yn,xn)(y_{n},{\bm{x}}_{n}):

where zn=f(xn,ϕ){\bm{z}}_{n}=f({\bm{x}}_{n},{\bm{\phi}}) is the output of the invertible transformation, pz(z)p_{z}({\bm{z}}) is the latent distribution (also referred to as the prior or base distribution), and p(yn∣f(xn;ϕ);β)p(\mathbf{y}_{n}|f({\bm{x}}_{n};{\bm{\phi}});{\bm{\beta}}) is a GLM with the latent variables serving as its input features. For simplicity, we assume a factorized latent distribution p(z)=∏dp(zd)p({\bm{z}})=\prod_{d}p(z_{d}), following previous work (Dinh et al., 2017; Kingma & Dhariwal, 2018). Note that ϕ={ϕt,l,ϕs,l}l=1L{\bm{\phi}}=\{{\bm{\phi}}_{t,l},{\bm{\phi}}_{s,l}\}_{l=1}^{L} are the parameters of the generative model and that θ={ϕ,β}{\bm{\theta}}=\{{\bm{\phi}},{\bm{\beta}}\} are the parameters of the joint model. Sharing ϕ{\bm{\phi}} between both components allows the conditional distribution to influence the generative distribution and vice versa. We term the proposed neural hybrid model the deep invertible generalized linear model (DIGLM). Given labeled training data {(xn,yn)}n=1N\{({\bm{x}}_{n},y_{n})\}_{n=1}^{N} sampled from the true distribution of interest p∗(x,y)p^{*}({\bm{x}},y), the DIGLM can be trained by maximizing the exact joint log-likelihood, i.e.

Figure 1 shows a diagram of the DIGLM. We see that the computation pipeline is essentially that of a traditional neural network but one defined by stacking ACLs. The input x{\bm{x}} first passes through fϕf_{{\bm{\phi}}}, and the latent representation and the stored Jacobian terms are enough to compute p(x)p({\bm{x}}). In particular, evaluating pz(f(xn;ϕ))p_{z}(f({\bm{x}}_{n};{\bm{\phi}})) has an O(D)\mathcal{O}(D) run-time cost for factorized distributions, and ∣∂fϕ/∂xn∣\left|\partial{\bm{f}}_{{\bm{\phi}}}/\partial{\bm{x}}_{n}\right| has a O(LD)\mathcal{O}(LD) run-time for RNVP architectures, where LL is the number of affine coupling layers and DD is the input dimensionality. Evaluating the predictive model adds another O(D)\mathcal{O}(D) cost in computation, but this cost will be dominated by the prerequisite evaluation of fϕf_{{\bm{\phi}}}.

In practice we found the DIGLM’s performance improved by introducing a scaling factor on the contribution of p(x)p({\bm{x}}). The factor helps control for the effect of the drastically different dimensionalities of yy and x{\bm{x}}. We denote this modified objective as:

1 Semi-supervised learning

As mentioned in the introduction, having a representation of the joint density enables the model to be trained on data sets that do not have a label for every feature vector—i.e. semi-supervised data sets. When a label is not present, the principled approach is to integrate out the variable:

Thus we should use the unpaired x{\bm{x}} observations to train just the generative component.

2 Selective Classification

Equation 6 above also suggests a strategy for evaluating the model in real-world situations. One can imagine the DIGLM being deployed as part of a user-facing system and that we wish to have the model ‘reject’ inputs that are unlike the training data. In other words, the inputs are anomalous with respect to the training distribution, and we cannot expect the p(y∣x)p(y|{\bm{x}}) component to make accurate predictions when x{\bm{x}} is not drawn from the training distribution. In this setting we have access only to the user-provided features x∗{\bm{x}}^{*}, and thus should evaluate by way of Equation 6 again, computing p(x∗;ϕ)p({\bm{x}}^{*};{\bm{\phi}}). This observation then leads to the natural rejection rule:

where τ\tau is some threshold, which we propose setting as τ=min⁡x∈Dp(x;ϕ)−c\tau=\min_{{\bm{x}}\in\mathcal{D}}p({\bm{x}};{\bm{\phi}})-c where the minimum is taken over the training set and cc is a free parameter providing slack in the margin. When rejecting a sample, we output the unconditional p(y)p(y), e.g. uniform probabilities for classification problems, hence the prediction for x∗{\bm{x}}^{*} is given by

where \mathds1[⋅]\mathds{1}[\cdot] denotes an indicator function. Similar generative-model-based rejection rules have been proposed previously (Bishop, 1994). This idea is also known as selective classification or classification with a reject option (Hellman, 1970; Cordella et al., 1995; Fumera & Roli, 2002; Herbei & Wegkamp, 2006; Geifman & El-Yaniv, 2017).

Bayesian Treatment

We next describe a Bayesian treatment of the DIGLM, deriving some closed-form quantities of interest and discussing connections to Gaussian processes. The Bayesian DIGLM (B-DIGLM) is defined as follows:

The material difference from the earlier formulation is that a prior p(β)p({\bm{\beta}}) is now placed on the regression parameters. The B-DIGLM defines the joint distribution of three variables—p(yn,xn,β;ϕ)p(y_{n},{\bm{x}}_{n},{\bm{\beta}};{\bm{\phi}})—and to perform proper Bayesian inference, we should marginalize over p(β)p({\bm{\beta}}) when training, resulting in the modified objective:

where p(yn∣f(xn;ϕ))p(y_{n}|f({\bm{x}}_{n};{\bm{\phi}})) is the marginal likelihood of the regression model.

While p(yn∣f(xn;ϕ))p(y_{n}|f({\bm{x}}_{n};{\bm{\phi}})) is not always available in closed-form, it is in some cases. For instance, if we assume that the likelihood model is Gaussian as in linear regression, and that β{\bm{\beta}} is given a zero-mean Gaussian prior, i.e.

then the marginal likelihood can be written as:

From Equation 4 we see that B-DIGLMs are related to Gaussian processes (GPs) (Rasmussen & Williams, 2006). GPs are defined through their kernel function k(xi,xj;ψ)k({\bm{x}}_{i},{\bm{x}}_{j};{\bm{\psi}}), which in turn characterizes the class of functions represented. The marginal likelihood under a GP is defined as

with ψ{\bm{\psi}} denoting the kernel parameters. Comparing this equation to the B-DIGLM’s marginal likelihood in Equation 4, we see that they become equal by setting Kψ=λ−1ZϕZϕT{\bm{K}}_{{\bm{\psi}}}=\lambda^{-1}{\bm{Z}}_{{\bm{\phi}}}{\bm{Z}}_{{\bm{\phi}}}^{T}, and thus we have the implied kernel k(xi,xj)=λ−1f(xi;ϕ)Tf(xj;ϕ)k({\bm{x}}_{i},{\bm{x}}_{j})=\lambda^{-1}f({\bm{x}}_{i};{\bm{\phi}})^{T}f({\bm{x}}_{j};{\bm{\phi}}). Perhaps there are even deeper connections to be made via Fisher kernels (Jaakkola & Haussler, 1999) or probability product kernels (Jebara et al., 2004)—kernel functions derived from generative models—but we leave this investigation to future work.

If the marginal likelihood is not available in closed form, then we must resort to approximate inference. In this case, understandably, our model loses the ability to compute exact marginal likelihoods. We can use one of the many lower bounds developed for variational inference to bypass the intractability. Using the usual variational Bayes evidence lower bound (ELBO) (Jordan et al., 1999), we have

where q(β)q({\bm{\beta}}) is a variational approximation to the true posterior. We leave thorough investigation of approximate inference to future work, and in the experiments we use either conjugate Bayesian inference or point estimates for β{\bm{\beta}}.

One may ask: why stop the Bayesian treatment at the predictive component? Why not include a prior on the flow’s parameters as well? This could be done, but Riquelme et al. (2018) showed that Bayesian linear regression with deep features (i.e. computed by a deterministic neural network) is highly effective for contextual bandit problems, which suggests that capturing the uncertainty in prediction parameters β{\bm{\beta}} is more important than the uncertainty in the representation parameters ϕ{\bm{\phi}}.

Related Work

We are unaware of any work that uses normalizing flows as the generative component of a hybrid model. The most related work is the class conditional variant of Glow (Kingma & Dhariwal, 2018, Appendix D). For this model, Kingma & Dhariwal (2018) use class-conditional latent distributions and introduce a (down-weighted) classification loss to the penultimate layer of the flow. However, they do not evaluate the model for its predictive capabilities and instead (qualitatively) evaluate its class-conditional generative abilities.

While several works have studied the trade-offs between generative and predictive models (Efron, 1975; Ng & Jordan, 2002), Jaakkola & Haussler (1999) were perhaps the first to meaningfully combine the two, using a generative model to define a kernel function that could then be employed by classifiers such as SVMs. Raina et al. (2004) took the idea a step further, training a subset of a naive Bayes model’s parameters with an additional predictive objective. McCallum et al. (2006) extended this framework to train all parameters with both generative and predictive objectives. Lasserre et al. (2006) showed that a simple convex combination of the generative and predictive objectives does not necessarily represent a unified model and proposed an alternative prior that better couples the parameters. Druck et al. (2007) empirically compared Lasserre et al. (2006)’s and McCallum et al. (2006)’s hybrid objectives specifically for semi-supervised learning. Recent advances in deep generative models and stochastic variational inference have allowed the aforementioned frameworks to include neural networks as the predictive and/or generative components. Deep neural hybrid models haven been defined by (at least) Kingma et al. (2014), Maaløe et al. (2016), Kuleshov & Ermon (2017), Tulyakov et al. (2017), and Gordon & Hernández-Lobato (2017). However, these models, unlike ours, require approximate inference to obtain the p(x)p({\bm{x}}) component.

As mentioned in the introduction, invertible residual networks have been shown to perform as well as non-invertible architectures on popular image benchmarks (Gomez et al., 2017; Jacobsen et al., 2018). While the change-of-variables formula could be calculated for these models, it is computationally difficult to do so, which prevents their application to generative modeling. The concurrent work of Behrmann et al. (2019) shows how to preserve invertibility in general residual architectures and describes a stochastic approximation of the volume element to allow for high-dimensional generative modeling. Hence their work could be used to define a hybrid model similar to ours, which they mention as area for future work.

Experiments

We now report experimental findings for a range of regression and classification tasks. Unless otherwise stated, we used the Glow architecture (Kingma & Dhariwal, 2018) to define the DIGLM’s invertible transform and factorized standard Gaussian distributions as the latent prior p(z)p({\bm{z}}).

We first report a one-dimensional regression task to provide an intuitive demonstration of the DIGLM. We draw xx-observations from a Gaussian mixture with parameters μ={−4,0,+4}\mu=\{-4,0,+4\}, σ={.4,.6,.4}\sigma=\{.4,.6,.4\}, and equal component weights. We simulate responses with the function y=x3+ϵ(k)y=x^{3}+\epsilon(k) where ϵ(k)\epsilon(k) denotes observation noise as a function of the mixture component kk. Specifically we chose ϵ(k)∼\mathds1[k∈{1,3}]N(0,3)+\mathds1[k=2]N(0,20)\epsilon(k)\sim\mathds{1}[k\in\{1,3\}]N(0,3)+\mathds{1}[k=2]N(0,20). We train a B-DIGLM on 250 observations sampled in this way, use standard Normal priors for p(z)p({\bm{z}}) and p(β)p({\bm{\beta}}), and three planar flows (Rezende & Mohamed, 2015) to define f(x)f({\bm{x}}). We compare this model to a Gaussian process (GP) and a kernel density estimate (KDE), which both use squared exponential kernels.

Figure 2(a) shows the predictive distribution learned by the GP, and Figure 2(b) shows the DIGLM’s predictive distribution. We see that the models produce similar results, with the only conspicuous difference being the GP has a stronger tendency to revert to its mean at the plot’s edges. Figure 2(c) shows the p(x)p(x) density learned by the DIGLM’s flow component (black line), and we plot it against the KDE (gray shading) for comparison. The single B-DIGLM is able to achieve comparable results to the separate GP and KDE models.

Thinking back to the rejection rule defined in Equation 7, this result, albeit on a toy example, suggests that density thresholding would work well in this case. All data observations fall within x∈x\in, and we see from Figure 2(c) that the DIGLM’s generative model smoothly decays to the left and right of this range, meaning that there does not exist an x∗x^{*} that lies outside the training support and has p(x∗)≥min⁡x∈Dp(x)p({\bm{x}}^{*})\geq\min_{{\bm{x}}\in\mathcal{D}}p({\bm{x}}).

2 Regression on Flight Delay Data Set

Next we evaluate the model on a large-scale regression task using the flight delay data set (Hensman et al., 2013). The goal is to predict how long flights are delayed based on eight attributes. Following Deisenroth & Ng (2015), we train using the first 55 million data points and use the following 100,000100,000 as test data. We picked this split not only to illustrate the scalability of our method, but also due to the fact that the test distribution is known to be slightly different from training, which poses challenges of non-stationarity. We evaluate the performance by measuring the root mean squared error (RMSE) and the negative log-likelihood (NLL).

One could model heteroscedasticity in GLMs using random effects (see Appendix C for a discussion), however as a simpler alternative, we follow the solution proposed by Lakshminarayanan et al. (2017) for heteroscedastic regression and set p(y∣z)p(y|{\bm{z}}) to be a two-headed model that predicts both the mean and variance. We use a RNVP transform as the invertible function where the RNVP blocks use 1-layer network with 100 hidden units, and train using Adam optimizer for 10 epochs with learning rate 10−310^{-3} and batch size 100100. To the best of our knowledge, the state-of-the-art (SOTA) performance on this data set is a test RMSE of 38.3838.38 and a test NLL of 6.916.91 (Lakshminarayanan et al., 2016). Our hybrid model achieves a slightly worse test RMSE of 40.46 but achieves a markedly better test NLL of 5.07. We believe that this superior NLL stems from the hybrid model’s ability to detect the non-stationarity of the data. Figure 3 shows a histogram of the log⁡p(x)\log p({\bm{x}}) evaluations for the training data (blue bars) and test data (red bars). The leftward shift in the red bars confirms that the test data points indeed have lower density under the flow than the training points.

3 MNIST Classification

Moving on to classification, we train a DIGLM on MNIST using 16 Glow blocks (1×11\times 1 convolution followed by a stack of ACLs) to define the invertible function. Inside of each ACL, we use a 3-layer Highway network (Srivastava et al., 2015) with 200200 hidden units to define the translation t(⋅;ϕs)t(\cdot;{\bm{\phi}}_{s}) and scaling s(⋅;ϕs)s(\cdot;{\bm{\phi}}_{s}) operations. We use batch normalization in the networks for simplicity in distributed coordination rather than actnorm as was used by Kingma & Dhariwal (2018). We use dropout (Srivastava et al., 2014) before passing z{\bm{z}} to the GLM, and tune dropout rate on the validation set. Optimization was done via Adam (Kingma & Ba, 2014) with a 10−410^{-4} initial learning rate for 100100k steps, then decayed by half at iterations 800800k and 900900k.

We compare the DIGLM to its discriminative component, which is obtained by setting the generative weight to zero (i.e. λ=0\lambda=0). We report test classification error, NLL, and entropy of the predictive distribution. Following Lakshminarayanan et al. (2017), we evaluate on both the MNIST test set and the NotMNIST test set, using the latter as an out-of-distribution (OOD) set. The OOD test is a proxy for testing if the model would be robust to anomalous inputs when deployed in a user-facing system. The results are shown in Table 1. Looking at the MNIST results, the discriminative model achieves slightly lower test error, but the hybrid model achieves better NLL and entropy. As expected, λ\lambda controls the generative-discriminative trade-off with lower values favoring discriminative performance and higher values favoring generative performance.

Next, we compare the generative density p(x)p({\bm{x}}) of the hybrid modelWe report results for λ=0.01/D\lambda=0.01/D; higher values are qualitatively similar. to that of the pure discriminative model (λ=0\lambda=0), quantifying the results in bits-per-dimension (BPD). Since the discriminative variant was not optimized to learn p(x)p({\bm{x}}), we expect it to have a high BPD for both in- and out-of distribution sets. This experiment is then a sanity check that a discriminative objective alone is insufficient for OOD detection and a hybrid objective is necessary. First examining the discriminative models’ BPD in Table 1, we see that it assigns similar values to MNIST and NotMNIST: 81.881.8 vs 87.7487.74 respectively. While at first glance this difference suggests OOD detection is possible, a closer inspection of the per instance log⁡p(x)\log p({\bm{x}}) histogram—which we provide in Subfigure 4(a)—shows that the distribution of train and test set densities are heavily overlapped. Subfigure 4(b) shows the same histograms for the DIGLM trained with a hybrid objective. We now see conspicuous separation between the NotMNIST (red) and MNIST (blue) sets, which suggests the threshold rejection rule would work well in this case.

Using the selective classification setup described earlier in equation 8, we use p(y∣x)p(y|{\bm{x}}) head when p(x)>τp({\bm{x}})>\tau where the threshold τ=min⁡x∈Xtrainp(x)\tau=\min_{{\bm{x}}\in X_{train}}p({\bm{x}}) and p(y)p(y) estimated using the label counts. The results are shown in Table 1. As expected, the hybrid model exhibits higher uncertainty and achieves better NLL and entropy on NotMNIST. To demonstrate that the hybrid model learns meaningful representations, we compute convex combinations of the latent variables z=αz1+(1−α)z2{\bm{z}}=\alpha{\bm{z}}_{1}+(1-\alpha){\bm{z}}_{2}. Figure 4(c) shows these interpolations in the MNIST latent space.

4 SVHN Classification

We move on to natural images, performing a similar evaluation on SVHN. For these experiments we use a larger network of 2424 Glow blocks and employ multi-scale factoring (Dinh et al., 2017) every 88 blocks. We use a larger Highway network containing 300 hidden units. In order to preserve the visual structure of the image, we apply only a 3 pixel random translation as data augmentation during training. The rest of the training details are the same as those used for MNIST. We use CIFAR-10 for the OOD set.

Table 2 summarizes the classification results, reporting the same metrics as for MNIST. The trends are qualitatively similar to what we observe for MNIST: the λ=0\lambda=0 model has the best classification performance, but the hybrid model is competitive. Figure 5(a) reports the log⁡p(x)\log p({\bm{x}}) evaluations for SVHN vs CIFAR-10. We see from the clear separation between the SVHN (blue) and CIFAR-10 (red) histograms that the hybrid model can detect the OOD CIFAR-10 samples. Figure 5(b) visualizes interpolations in latent space, again showing that the model learns coherent representations. Figure 5(c) shows confidence versus accuracy plots (Lakshminarayanan et al., 2017), using the selective classification rule described in Section 3.2, when tested on in-distribution and OOD, which shows that the hybrid model is able to successfully reject OOD inputs.

5 Semi-Supervised Learning

As discussed in Section 3.1, one advantage of the hybrid model is the ability to leverage unlabeled data. We first performed a sanity check on simulated data, using interleaved half moons. Figure 6 shows the decision boundaries when the model is trained without unlabeled data (left) and with unlabeled data (right). The rightmost figure shows a noticeably smoother boundary that better respects the half moon shape.

Next we present results on MNIST when training with only 10001000 labeled points (2%2\% of the data set) and using the rest as unlabeled data. For the unlabeled points, we maximize log⁡p(x)\log p({\bm{x}}) in the usual way and minimize the entropy for the p(y∣x)p(y|{\bm{x}}) head, corresponding to entropy minimization (Grandvalet & Bengio, 2005). We also use virtual adversarial training (VAT) (Miyato et al., 2018), which we found to boost performance. We chose weights on the generative model and on the VAT objective by performing grid sweeps on a validation set, see Appendix B for details. Table 3 shows the results. We see that incorporating the unlabeled data results in an improvement from 6.61%6.61\% error to 0.99%0.99\% error, which is competitive with other SOTA approaches such as ladder networks (Rasmus et al., 2015) (0.84%0.84\%) and GANs (Springenberg, 2015) (1.73%1.73\%).

Discussion

We have presented a neural hybrid model created by combining deep invertible features and GLMs. We have shown that this model is competitive with discriminative models in terms of predictive performance but more robust to out-of-distribution inputs and non-stationary problems. The availability of exact p(x,y)p({\bm{x}},y) allows us to simulate additional data, as well as compute many quantities readily, which could be useful for downstream applications of generative models, including but not limited to semi-supervised learning, active learning, and domain adaptation.

There are several interesting avenues for future work. Firstly, recent work has shown that deep generative models can assign higher likelihood to OOD inputs (Nalisnick et al., 2019; Choi & Jang, 2018), meaning that our rejection rule is not guaranteed to work in all settings. This is a challenge not just for our method but for all deep hybrid models. The DIGLM’s abilities may also be improved by considering flows constructed in other ways than stacking ACLs. Recently proposed continuous-time flows (Grathwohl et al., 2019) and invertible residual networks (Behrmann et al., 2019) may prove to be more powerful that the Glow transform that we use, thereby improving our results. Lastly, we have only considered KL-divergence-based training in this paper. Alternative training criteria such as Wasserstein distance could potentially further improve performance.

We thank Danilo Rezende for helpful feedback.

References

Appendix A Background on Affine Coupling Layers

One ACL performs the following operations (Dinh et al., 2017):

Splitting: x{\bm{x}} split it at dimension dd into two separate vectors x:d{\bm{x}}_{:d} and xd:{\bm{x}}_{d:} (using Python list syntax).

Identity and Affine Transformations: Given the split {x:d,xd:}\{{\bm{x}}_{:d},{\bm{x}}_{d:}\}, each undergoes a separate operation:

where t(⋅)t(\cdot) and s(⋅)s(\cdot) are translation and scaling operations with no restrictions on their functional form. We can compute them with neural networks that take as input x:d{\bm{x}}_{:d}, the other half of the original vector, and since x:d{\bm{x}}_{:d} has been copied forward by the first operation, no information is lost that would jeopardize invertibility.

Permutation: Lastly, the new representation h={h:d,hd:}{\bm{h}}=\{\mathbf{h}_{:d},\mathbf{h}_{d:}\} is ready to be either treated as output or fed into another ACL. If the latter, then the elements should be modified so that h:d\mathbf{h}_{:d} is not again copied but rather subject to the affine transformation. Dinh et al. (2017) simply exchange the components (i.e. {hd:,h:d})\{\mathbf{h}_{d:},\mathbf{h}_{:d}\})) whereas Kingma & Dhariwal (2018) apply a 1×11\times 1 convolution, which can be thought of as a continuous generalization of a permutation.

Several ACLs are composed to create the final form of f(x;ϕ)f({\bm{x}};{\bm{\phi}}), which is called a normalizing flow (Rezende & Mohamed, 2015). Crucially, the Jacobian of these operations is efficient to compute, simplifying to the sum of all the scale transformations:

where ll is an index over ACLs. The Jacobian of a 1×11\times 1 convolution does not have as simple of an expression, but Kingma & Dhariwal (2018) describe ways to reduce computation.

Appendix B Additional Semi-Supervised Results

The hyperparameters are described in Table S1.

B.2 Semi-supervised learning on SVHN

The results are shown in Table S2. Similar to the semi-supervised results on MNIST, we observe that our model can effectively leverage unlabeled data.

Appendix C Extensions

To model heteroscedastic noise, we can also add “random effects” to the model at the latent level. The model is then:

where an\mathbf{a}_{n} is a vector of random effects associated with the fixed effects xn\mathbf{x}_{n}, and u\mathbf{u} are the corresponding parameters in the GLM. Note that Depeweg et al. (2018) also use random effects model to handle heteroscedastic noise, but add them at the input level.