### Abstract

With the introduction of the variational autoencoder (VAE), probabilisticlatent variable models have received renewed attention as powerful generativemodels. However, their performance in terms of test likelihood and quality ofgenerated samples has been surpassed by autoregressive models withoutstochastic units. Furthermore, flow-based models have recently been shown to bean attractive alternative that scales well to high-dimensional data. In thispaper we close the performance gap by constructing VAE models that caneffectively utilize a deep hierarchy of stochastic variables and model complexcovariance structures. We introduce the Bidirectional-Inference VariationalAutoencoder (BIVA), characterized by a skip-connected generative model and aninference network formed by a bidirectional stochastic inference path. We showthat BIVA reaches state-of-the-art test likelihoods, generates sharp andcoherent natural images, and uses the hierarchy of latent variables to capturedifferent aspects of the data distribution. We observe that BIVA, in contrastto recent results, can be used for anomaly detection. We attribute this to thehierarchy of latent variables which is able to extract high-level semanticfeatures. Finally, we extend BIVA to semi-supervised classification tasks andshow that it performs comparably to state-of-the-art results by generativeadversarial networks.

### Quick Read (beta)

# BIVA: A Very Deep Hierarchy of Latent Variables for Generative Modeling

###### Abstract

With the introduction of the variational autoencoder (VAE), probabilistic latent variable models have received renewed attention as powerful generative models. However, their performance in terms of test likelihood and quality of generated samples has been surpassed by autoregressive models without stochastic units. Furthermore, flow-based models have recently been shown to be an attractive alternative that scales well to high-dimensional data. In this paper we close the performance gap by constructing VAE models that can effectively utilize a deep hierarchy of stochastic variables and model complex covariance structures. We introduce the Bidirectional-Inference Variational Autoencoder (BIVA), characterized by a skip-connected generative model and an inference network formed by a bidirectional stochastic inference path. We show that BIVA reaches state-of-the-art test likelihoods, generates sharp and coherent natural images, and uses the hierarchy of latent variables to capture different aspects of the data distribution. We observe that BIVA, in contrast to recent results, can be used for anomaly detection. We attribute this to the hierarchy of latent variables which is able to extract high-level semantic features. Finally, we extend BIVA to semi-supervised classification tasks and show that it performs comparably to state-of-the-art results by generative adversarial networks.

bayesnet \usetikzlibraryarrows \usetikzlibraryshapes.multipart \tikzset state/.style= rectangle split, rectangle split parts=2, rectangle split part fill=red!30,blue!20, rounded corners, draw=black, very thick, minimum height=2em, text width=3cm, inner sep=2pt, text centered,

BIVA: A Very Deep Hierarchy of Latent Variables for Generative Modeling

Lars Maaløe Corti Copenhagen Denmark [email protected] Marco Fraccaro Unumed Copenhagen Denmark [email protected] Valentin Liévin & Ole Winther Technical University of Denmark Copenhagen Denmark {valv,olwi}@dtu.dk

noticebox[b]33rd Conference on Neural Information Processing Systems (NeurIPS 2019), Vancouver, Canada.\[email protected]

## 1 Introduction

One of the key aspirations in recent machine learning research is to build models that understand the world (Kingma13; Rezende14; Goodfellow2014; Oord2015). Generative models are providing the means to learn from a plethora of unlabeled data in order to model a complex data distribution, e.g. natural images, text, and audio. These models are evaluated by their ability to generate data that is similar to the input data distribution from which they were trained on. The range of applications that come with generative models are vast, where audio synthesis (Oord16b) and semi-supervised classification (Rasmus15; Maaloe2016; Salimans2016) are examples hereof. Generative models can be broadly divided into explicit and implicit density models. The generative adversarial network (GAN) (Goodfellow2014) is an example of an implicit model, since it is not possible to procure a likelihood estimation from this model framework. The focus of this research is instead within explicit density models, for which a tractable or approximate likelihood estimation can be performed.

The three main classes of powerful explicit density models are autoregressive models (Larochelle11; Oord2015), flow-based models (Dinh14; Dinh16; Kingma18; Ho19), and probabilistic latent variable models (Kingma13; Rezende14; Mnih14). In recent years autoregressive models, such as the PixelRNN and the PixelCNN (Oord2015; Salimans17), have achieved superior likelihood performance and flow-based models have proven efficacy on large-scale natural image generation tasks (Kingma18). However, in the autoregressive models, the runtime performance of generation is scaling poorly with the complexity of the input distribution. The flow-based models do not possess this restriction and do indeed generate visually compelling natural images when sampling close to the mode of the distribution. However, generation from the actual learned distribution is still not outperforming autoregressive models (Kingma18; Ho19).

Probabilistic latent variable models such as the variational auto-encoder (VAE) (Kingma13; Rezende14) possess intriguing properties that are different from the other classes of explicit density models. They are characterized by a posterior distribution over the latent variables of the model, derived from Bayes’ theorem, which is typically intractable and needs to be approximated. This distribution most commonly lies on a low-dimensional manifold that can provide insights into the internal representation of the data (Bengio2013a). However, the latent variable models have largely been disregarded as powerful generative models due to blurry generations and poor likelihood performances on natural image tasks. (Larsen16; Dosovitskiy2016), amongst others, attribute this tendency to the usage of a similarity metric in pixel space. Contrarily, we attribute it to the lack of overall model expressiveness for accurately modeling complex input distributions, as discussed in (ZhaoSE17; rezende2018taming).

There has been much research into explicitly defining and learning more expressive latent variable models. Here, the complementary research into learning a covariance structure through a framework of normalizing flows (Rezende2015; Tomczak16; Kingma2016) and the stacking of a hierarchy of latent variables (Burda15; Ranganath2015; Maaloe2016; Sonderby2016) have shown promising results. However, despite significant improvements, the reported performance of these models has still been inferior to their autoregressive counterparts. This has spawned a new class of explicit density models that adds an autoregressive component to the generative process of a latent variable model (Gulrajani2016; Chen2017). In this combination of model paradigms, the latent variables can be viewed as merely a lossy representation of the input data and the model still suffers from the same issues as autoregressive models.

#### Contributions.

In this research we argue that latent variable models that are defined in a sufficiently expressive way can compete with autoregressive and flow-based models in terms of test log-likelihood and quality of the generated samples. We introduce the Bidirectional-Inference Variational Autoencoder (BIVA), a model formed by a deep hierarchy of stochastic variables that uses skip-connections to enhance the flow of information and avoid inactive units. To define a flexible posterior approximation, we construct a bidirectional inference network using stochastic variables in a bottom-up and a top-down inference path. The inference model is reminiscent to the stochastic top-down path introduced in the Ladder VAE Sonderby2016 and IAF VAE Sonderby2016 with the addition that the bottom-up pass is now also stochastic and there are no autoregressive components. We perform an in-depth analysis of BIVA and show (i) an ablation study that analyses the contributions of the individual novel components, (ii) that the model is able to improve on state-of-the-art results on benchmark image datasets, (iii) that a small extension of the model can be used for semi-supervised classification and performs comparably to current state-of-the-art models, and (iv) that the model, contrarily to other state-of-the-art explicit density models (Nalisnick18), can be utilized for anomaly detection on complex data distributions.

## 2 Variational Autoencoders

The VAE is a generative model parameterized by a neural network $\theta $ and is defined by an observed variable $x$ that depends on a hierarchy of stochastic latent variables $\mathbf{z}={z}_{1},\mathrm{\dots},{z}_{L}$ so that: ${p}_{\theta}(x,\mathbf{z})={p}_{\theta}(x|{z}_{1}){p}_{\theta}({z}_{L}){\prod}_{i=1}^{L-1}{p}_{\theta}({z}_{i}|{z}_{i+1})$. The posterior distribution over the latent variables of a VAE is commonly analytically intractable, and is approximated with a variational distribution which is factorized with a bottom-up structure, ${q}_{\varphi}(\mathbf{z}|x)={q}_{\varphi}({z}_{1}|x){\prod}_{i=1}^{L-1}{q}_{\varphi}({z}_{i+1}|{z}_{i})$, so that each latent variable is conditioned on the variable below in the hierarchy. The parameters $\theta $ and $\varphi $ can be optimized by maximizing the evidence lower bound (ELBO)

$\mathrm{log}{p}_{\theta}(x)\ge {\mathbb{E}}_{{q}_{\varphi}(\mathbf{z}|x)}\left[\mathrm{log}{\displaystyle \frac{{p}_{\theta}(x,\mathbf{z})}{{q}_{\varphi}(\mathbf{z}|x)}}\right]\equiv \mathcal{L}(\theta ,\varphi ).$ | (1) |

A detailed introduction on VAEs can be found in appendix A in the supplementary material. While a deep hierarchy of latent stochastic variables will result in a more expressive model, in practice the top stochastic latent variables of standard VAEs have a tendency to collapse into the prior. The Ladder VAE (LVAE) (Sonderby2016) is amongst the first attempts towards VAEs that can effectively leverage multiple layers of stochastic variables. This is achieved by parameterizing the variational approximation with a bottom-up deterministic path followed by a top-down inference path that shares parameters with the top-down structure of the generative model: ${q}_{\varphi ,\theta}(\mathbf{z}|x)={q}_{\varphi}({z}_{L}|x){\prod}_{i=1}^{L-1}{q}_{\varphi ,\theta}({z}_{i}|{z}_{i+1},x)$. See Appendix A for a graphical representation of the LVAE inference network. Thanks to the bottom-up path, all the latent variables in the hierarchy have a deterministic dependency on the observed variable $x$, which allows data-dependent information to skip all the stochastic variables lower in the hierarchy (Figure 4(d) in Appendix A). The stochastic latent variables that are higher in the hierarchy will therefore receive less noisy inputs, and will be empirically less likely to collapse. Despite the improvements obtained thanks to the more flexible inference network, in practice LVAEs with a very deep hierarchy of stochastic latent variables will still experience variable collapse. In the next section we will introduce the Bidirectional-Inference Variational Autoencoder, that manages to avoid these issues by extending the LVAE in 2 ways: (i) adding a deterministic top-down path in the generative model and (ii) defining a factorization of the latent variables ${z}_{i}$ at each level of the hierarchy that allows to construct a bottom-up stochastic inference path.

## 3 Bidirectional-Inference Variational Autoencoder

In this section, we will first describe the architecture of the Bidirectional-Inference Variational Autoencoder (Figure 1), and then provide the motivation behind the main ideas of the model as well as some intuitions on the role of each of its novel components. Finally, we will show how this model can be used for a novel approach to detecting anomalous data.

### 3.1 Model architecture

#### Generative model.

In BIVA, at each layer $1,\mathrm{\dots},L-1$ of the hierarchy we split the latent variable in two components, ${z}_{i}=({z}_{i}^{\text{scalebox}0.6BU},{z}_{i}^{\text{scalebox}0.6TD})$, which belong to a bottom-up (BU) and top-down (TD) inference path, respectively. More details on this will be given when introducing the inference network. The generative model of BIVA is illustrated in Figure 0(a). We introduce a deterministic top-down path ${d}_{L-1},\mathrm{\dots},{d}_{1}$ that is parameterized with neural networks and receives as input at each layer $i$ of the hierarchy the latent variable ${z}_{i+1}$. In the case of a convolutional model, this is done by concatenating $({z}_{i+1}^{\text{scalebox}0.6BU}$, ${z}_{i+1}^{\text{scalebox}0.6TD})$ and ${d}_{i+1}$ along the features’ dimension. ${d}_{i}$ can therefore be seen as a deterministic variable that summarizes all the relevant information coming from the stochastic variables higher in the hierarchy, ${z}_{>i}$. The latent variables ${z}_{i}^{\text{scalebox}.6BU}$ and ${z}_{i}^{\text{scalebox}.6TD}$ are conditioned on all the information in the higher layers, and are conditionally independent given ${z}_{>i}$. The joint distribution of the model is then given by:

${p}_{\theta}(x,\mathbf{z})={p}_{\theta}(x|\mathbf{z}){p}_{\theta}({z}_{L}){\displaystyle \prod _{i=1}^{L-1}}{p}_{\theta}({z}_{i}^{\text{scalebox}.6BU}|{z}_{>i}){p}_{\theta}({z}_{i}^{\text{scalebox}.6TD}|{z}_{>i}),$ |

where $\theta $ are the parameters of the generative model. The likelihood of the model ${p}_{\theta}(x|\mathbf{z})$ directly depends on ${z}_{1}$, and depends on ${z}_{>1}$ through the deterministic top-down path. Each stochastic latent variable $1,\mathrm{\dots},L$ is parameterized by a Gaussian distribution with diagonal covariance, with one neural network $\mu (\cdot )$ for the mean and another neural network $\sigma (\cdot )$ for the variance. Since the ${z}_{i+1}^{\text{scalebox}0.6BU}$ and ${z}_{i+1}^{\text{scalebox}0.6TD}$ variables are on the same level in the generative model and of the same dimensionality, we share all the deterministic parameters going to the layer below. See Appendix B for details.

#### Bidirectional inference network.

Due to the non-linearities in the neural networks that parameterize the generative model, the exact posterior distribution ${p}_{\theta}(\mathbf{z}|x)$ is intractable and needs to be approximated. As for VAEs, we therefore define a variational distribution, ${q}_{\varphi}(\mathbf{z}|x)$, that needs to be flexible enough to approximate the true posterior distribution, as closely as possible. We define a bottom-up (BU) and a top-down (TD) inference path, which are computed sequentially when constructing the posterior approximation for each data point $x$, see Figure 0(b). The variational distribution over the BU latent variables depends on the data $x$ and on all BU variables lower in the hierarchy, i.e. $$, where $\varphi $ denotes all the parameters of the BU path. ${z}_{i}^{\text{scalebox}.6BU}$ has a direct dependency only on the BU variable below, ${z}_{i-1}^{\text{scalebox}.6BU}$. The dependency on $$ is achieved, similarly to the generative model, through a deterministic bottom-up path ${\stackrel{~}{d}}_{1},\mathrm{\dots},{\stackrel{~}{d}}_{L-1}$.

The TD variables depend on the data and the BU variables lower in the hierarchy through the BU inference path, but also on all variables above in the hierarchy through the TD inference path, see Figure 0(b). The variational approximation over the TD variables is thereby $$. Importantly, all the parameters of the TD path are shared with the generative model, and are therefore denoted as $\theta $. The overall inference network can be factorized as follows:

$$ |

where the variational distributions over the BU and TD latent variables are Gaussians whose mean and diagonal covariance are parameterized with neural networks that take as input the concatenation over the feature dimension of the conditioning variables. Training of BIVA is performed, as for VAEs, by maximizing the ELBO in eq. (1) with stochastic backpropagation and the reparameterization trick.

### 3.2 Motivation

BIVA can be seen as an extension of the LVAE in which we (i) add a deterministic top-down path and (ii) apply a bidirectional inference network. We will now provide the motivation and some intuitions on the role of these two novel components, that will then be empirically validated with the ablation study of Section 4.1.

#### Deterministic top-down path.

Skip-connections represent one of the simplest yet most powerful advancements of deep learning in recent years. They allow constructing very deep neural networks, by better propagating the information throughout the model and reducing the issue of vanishing gradients. Skip connections form for example the backbone of deep neural networks such as ResNets (He2015), which have shown impressive performances on a wide range of classification tasks. Our goal in this paper is to build very deep latent variable models that are able to learn an expressive latent hierarchical representation of the data. In our experiments, we however found that the LVAE still had difficulties in activating the top latent variables for deeper hierarchies. To limit this issue, we add skip connections among the latent variables in the generative model by adding the deterministic top-down path, that makes each variable depend on all the variables above in the hierarchy (see Figure 0(a) for a graphical representation). This allows a better flow of information in the model and thereby avoids the collapse of latent variables. A related idea was recently proposed by (Dieng18), that add skip connections among the neural network layers parameterizing a shallow VAE with a single latent variable.

#### Bidirectional inference.

The inspiration for the bidirectional inference network of BIVA comes from the work on Auxiliary VAEs (AVAE) by (Ranganath2015; Maaloe2016). An AVAE can be viewed as a shallow VAE with a single latent variable $z$ and an auxiliary variable $a$ that increases the expressiveness of the variational approximation ${q}_{\varphi}(z|x)=\int {q}_{\varphi}(z|a,x){q}_{\varphi}(a|x)da$. By making the inference network ${q}_{\varphi}(z|a,x)$ depend on the stochastic variable $a$, the AVAE adds covariance structure to the posterior approximation over the stochastic unit $z$, since it no longer factorizes over its components ${z}^{(k)}$, i.e. ${q}_{\varphi}(z|x)\ne {\prod}_{k}{q}_{\varphi}({z}^{(k)}|x)$. As discussed in the following, by factorizing the latent variables at each level of the hierarchy of BIVA we are able to achieve similar results without introducing additional auxiliary variables in the model. To see this, we can focus for example on the highest latent variable ${z}_{L}$. In BIVA, the presence of the ${z}_{i}^{\text{scalebox}.6BU}$ variables makes the bottom-up inference path stochastic, as opposed to the deterministic BU path of the LVAE. While the conditional distribution $$ still factorizes over the components of ${z}_{L}$, due to the stochastic BU variables the marginal distribution over ${z}_{L}$ no longer factorizes, i.e. $$ Therefore, the BU inference path enables the learning of a complex covariance structure in the higher TD stochastic latent variables, which is fundamental in the model to extract good high-level semantic features from the data distribution. Notice that, in BIVA, only ${z}_{1}^{\text{scalebox}.6BU}$ will have a marginally factorizing inference network.

### 3.3 Anomaly detection with BIVA

Anomaly detection is considered to be one of the most important applications of explicit density models. However, recent empirical results suggest that these models are not able to distinguish between two clearly distinctive data distributions (Nalisnick18), as they can assign a higher likelihood to data points from a data distribution that is very different from the one the model was trained on. Based on a thorough study, (Nalisnick18) states that the main issue is the fact that explicit density models tend to capture low-level statistics, as opposed to the high-level semantics that are preferable when doing anomaly detection. We hypothesize that the latent representations in the higher layers of BIVA can capture the high-level semantics of the data and that these can be used for improved anomaly detection.

In the standard ELBO from eq. (1), the main contribution to the expected log-likelihood term is coming from averaging over the variational distribution of the lower level latent variables. This will thus emphasize low-level statistics. So in order to perform anomaly detection with BIVA we instead need to emphasize the contribution from the higher layers. We can achieve this with an alternative log-likelihood lower bound that partly replaces the inference network with the generative model. It will be a weaker bound than the ELBO, but it has the advantage that it explicitly uses the generative hierarchy of the stochastic variables. In the following we define the hierarchy of stochastic latent variables as $\mathbf{z}={z}_{1},{z}_{2},{z}_{3},\mathrm{\dots},{z}_{L}$ with ${z}_{i}=({z}_{i}^{\text{scalebox}0.6BU},{z}_{i}^{\text{scalebox}0.6TD})$. Instead of using the variational approximation ${q}_{\varphi}(\mathbf{z}|x)$ over all stochastic variables in the model, we use the prior distribution for the first $k$ layers and the variational approximation for the others, i.e. ${p}_{\theta}({z}_{\le k}|{z}_{>k}){q}_{\varphi}({z}_{>k}|x)$. The new ELBO becomes:

${\mathcal{L}}^{>k}={\mathbb{E}}_{{p}_{\theta}({z}_{\le k}|{z}_{>k}){q}_{\varphi}({z}_{>k}|x)}\left[\mathrm{log}{\displaystyle \frac{{p}_{\theta}(x|\mathbf{z}){p}_{\theta}({z}_{>k})}{{q}_{\varphi}({z}_{>k}|x)}}\right].$ | (2) |

${\mathcal{L}}^{>0}=\mathcal{L}$ is the ELBO in eq. (1). As for the ELBO, we approximate the computation of ${\mathcal{L}}^{>k}$ with Monte Carlo integration. Sampling from ${p}_{\theta}({z}_{\le k}|{z}_{>k}){q}_{\varphi}({z}_{>k}|x)$ can be easily performed by obtaining samples ${\widehat{z}}_{>k}$ from the inference network, that are then used to sample ${\widehat{z}}_{\le k}$ from the conditional prior ${p}_{\theta}({z}_{\le k}|{\widehat{z}}_{>k})$.

Due to the sampling from the prior, eq. (2) will generally return a worse likelihood approximation than the ELBO. Despite this, ${\mathcal{L}}^{>k}$ with higher values of $k$ represents a useful metric for anomaly detection. By only sampling the top $L-k$ variables from the variational approximation, in fact, we are forcing the model to only rely on the high-level semantics encoded in the highest variables of the hierarchy when evaluating this metric, and not on the low-level statistics encoded in the lower variables.

## 4 Experiments

BIVA is empirically evaluated by (i) an ablation study analyzing each novel component, (ii) likelihood and semi-supervised classification results on binary images, (iii) likelihood results on natural images, and (iv) an analysis of anomaly detection in complex data distributions.
We employ a free bits strategy with $\lambda =2$ (Kingma2016) for all experiments to avoid latent variable collapse during the initial training epochs.
Trained models are reported with 1 importance weighted sample, ${\mathcal{L}}_{1}$, and 1000 importance weighted samples, ${\mathcal{L}}_{1e3}$ (Burda15a). We evaluate the natural image experiments by bits per dimension (bits/dim), $\mathcal{L}/(hwc\mathrm{log}(2))$, where $h$, $w$, $c$ denote the height, width, and channels respectively.
For a detailed description of the experimental setup see Appendix C and the source code^{1}^{1}
1
Source code (Tensorflow): https://github.com/larsmaaloee/BIVA.^{2}^{2}
2
Source code (PyTorch): https://github.com/vlievin/biva-pytorch..
In Appendix D we test BIVA on complex 2d densities, while Appendix E presents initial results for the model on text.

### 4.1 Ablation Study

BIVA can be viewed as an extension of the LVAE from (Sonderby2016) where we add (i) extra dependencies in the generative model (${p}_{\theta}(x|{z}_{1})\to {p}_{\theta}(x|\mathbf{z})$ and ${p}_{\theta}({z}_{i}|{z}_{i+1})\to {p}_{\theta}({z}_{i}|{z}_{>i})$) through the skip connections obtained with the deterministic top-down path and (ii) a bottom-up (BU) path of stochastic latent variables to the inference model. In order to evaluate the effects of each added component we define an LVAE with the exact same architecture as BIVA, but without the BU variables and the deterministic top-down path. Next, we define the LVAE+, where we add to the LVAE’s generative model the deterministic top-down path. It is therefore the same model as in Figure 1 but without the BU variables. Finally, we investigate a LVAE+ model with $2L-1$ stochastic layers. This corresponds to the depth of the hierarchy of the BIVA inference model $x\to {z}_{1}^{\text{scalebox}0.4BU}\to \mathrm{\dots}\to {z}_{L-1}^{\text{scalebox}0.4BU}\to {z}_{L}\to {z}_{L-1}^{\text{scalebox}0.4TD}\to \mathrm{\dots}\to {z}_{1}^{\text{scalebox}0.4TD}$. If this model is competitive with BIVA then it is an indication that it is the depth that determines the performance. The ablation study is conducted on the CIFAR-10 dataset against the best reported BIVA with $L=15$ layers (Section 4.3), which means $2L-1=29$ stochastic latent layers in the deep LVAE+.

Param. | bits/dim | |
---|---|---|

LVAE L=15, ${\mathcal{L}}_{1}$ | 72.36M | $\le 3.60$ |

LVAE+ L=15, ${\mathcal{L}}_{1}$ | 73.35M | $\le 3.41$ |

LVAE+ L=29, ${\mathcal{L}}_{1}$ | 119.71M | $\le 3.45$ |

BIVA L=15, ${\mathcal{L}}_{1}$ | 102.95M | $\le 3.12$ |

Table 1 presents a comparison of the different model architectures. The positive effect of adding the skip connections in the generative models can be evaluated from the difference between the LVAE $L=15$ and LVAE+ $L=15$ results, for which there is close to a 0.2 bits/dim difference in the ELBO. Thanks to the more expressive posterior approximation obtained using its bidirectional inference network, BIVA improves the ELBO significantly w.r.t the LVAE+, by more than 0.3 bits/dim. Notice that a deeper hierarchy of stochastic latent variables in the LVAE+ will not necessarily provide a better likelihood performance, since the LVAE+ $L=29$ performs worse than the LVAE+ $L=15$ despite having significantly more parameters. In Figure 2 we plot for LVAE, LVAE+ and BIVA the KL divergence between the variational approximation over each latent variable and its prior distribution, $KL(q||p)$. This KL divergence is 0 when the two distributions match, in which case we say that the variable has collapsed, since its posterior approximation is not using any data-dependent information. We can see that while the LVAE is only able to utilize its lowest 7 stochastic variables, all variables in both LVAE+ and BIVA are active. We attribute this tendency to the deterministic top-down path that is present in both models, which creates skip-connections between all latent variables that allow to better propagate the information throughout the model.

### 4.2 Binary Images

$-\mathrm{log}p(x)$ | |

With autoregressive components | |

PixelCNN Oord2015 | $=81.30$ |

DRAW Gregor15 | $$ |

IAFVAE Kingma2016 | $\le 79.88$ |

PixelVAE Gulrajani2016 | $\le 79.66$ |

PixelRNN Oord2015 | $=79.20$ |

VLAE Chen2017 | $\le 79.03$ |

Without autoregressive components | |

Discrete VAE Rolfe2017 | $\le 81.01$ |

BIVA, ${\mathcal{L}}_{1}$ | $\le 81.20$ |

BIVA, ${\mathcal{L}}_{1e3}$ | $\le 78.67$ |

BIVA finetuned, ${\mathcal{L}}_{1}$ | $\le 80.47$ |

BIVA finetuned, ${\mathcal{L}}_{1e3}$ | $\le 78.59$ |

Error % | |
---|---|

M1+M2 (Kingma14) | $3.33$% ($\pm 0.14$) |

VAT (Miyato15) | $2.12$% |

CatGAN (Springenberg2015) | $1.91$% ($\pm 0.10$) |

SDGM (Maaloe2016) | $1.32$% ($\pm 0.07$) |

LadderNet (Rasmus15) | $1.06$% ($\pm 0.37$) |

ADGM (Maaloe2016) | $0.96$% ($\pm 0.02$) |

ImpGAN (Salimans2016) | $0.93$% ($\pm 0.07$) |

TripleGAN (Li17) | $0.91$% ($\pm 0.58$) |

SSLGAN (Dai17) | $0.80$% ($\pm 0.10$) |

BIVA | $0.83$% ($\pm 0.02$) |

bits/dim | |

With autoregressive components | |

ConvDRAW Gregor16 | $$ |

IAFVAE ${\mathcal{L}}_{1}$ Kingma2016 | $\le 3.15$ |

IAFVAE ${\mathcal{L}}_{1e3}$ Kingma2016 | $\le 3.12$ |

GatedPixelCNN Oord16 | $=3.03$ |

PixelRNN Oord2015 | $=3.00$ |

VLAE Chen2017 | $\le 2.95$ |

PixelCNN++ Salimans17 | $=2.92$ |

Without autoregressive components | |

NICE Dinh14 | $=4.48$ |

DeepGMMs Oord14 | $=4.00$ |

RealNVP Dinh16 | $=3.49$ |

DiscreteVAE++ Vahdat18 | $\le 3.38$ |

GLOW Kingma18 | $=3.35$ |

Flow++ Ho19 | $=3.08$ |

BIVA L=10, ${\mathcal{L}}_{1}$ | $\le 3.17$ |

BIVA L=15, ${\mathcal{L}}_{1}$ | $\le 3.12$ |

BIVA L=15, ${\mathcal{L}}_{1e3}$ | $\le 3.08$ |

We evaluate BIVA $L=6$ in terms of test log-likelihood on statically binarized MNIST (Salakhutdinov08), dynamically binarized MNIST (LeCun98) and dynamically binarized OMNIGLOT (Lake2013). The model parameterization and optimization parameters have been kept identical for all binary image experiments (see Appendix C). For each experiment on binary image datasets, we finetune each model by setting the free bits to $\lambda =0$ until convergence in order to test the tightness of the ${\mathcal{L}}_{1}$ ELBO.

To the best of our knowledge, BIVA achieves state-of-the-art results on statically binarized MNIST, outperforming other latent variable models, autoregressive models, and flow-based models (see Table 4). Finetuning the model with $\lambda =0$ improves the ${\mathcal{L}}_{1}$ ELBO significantly and achieves slightly better performance for the 1000 importance weighted samples. For dynamically binarized MNIST and OMNIGLOT, BIVA achieves similar improvements with ${\mathcal{L}}_{\text{1e3}}=78.41$ (state-of-the-art) and ${\mathcal{L}}_{\text{1e3}}=91.34$ respectively, see Tables 10 and 11 in Appendix G.

#### Semi-supervised learning.

BIVA can be easily extended for semi-supervised classification by adding a categorical variable $y$ to represent the class, as done in (Kingma14). We add a classification model $$ to the inference network, and a class-conditional distribution ${p}_{\theta}(x|\mathbf{z},y)$ to the generative model (see Appendix F for a detailed description). We train 5 different semi-supervised models on MNIST, each using a different set of just 100 randomly chosen and evenly distributed MNIST labels. Table 4 presents the classification results on the test set (mean and standard deviation over the 5 runs), that shows that BIVA achieves comparable performance to recent state-of-the-art results by generative adversarial networks.

### 4.3 Natural Images

We trained and evaluated BIVA $L=15$ on 32x32 CIFAR-10, 32x32 ImageNet (Oord2015), and another BIVA $L=20$ on 64x64 CelebA (Larsen16). For the output decoding, we employ the discretized logistic mixture likelihood from (Salimans17) (see Appendix C for more details). In Table 4 we see that for the CIFAR-10 dataset BIVA outperforms other state-of-the-art non-autoregressive models and performs slightly worse than state-of-the-art autoregressive models. For the 32x32 ImageNet dataset BIVA achieves better performance than flow-based models, but the performance gap to the autoregressive models remains large (Table 13 in Appendix G). This may be due to the added complexity (more categories) of the 32x32 ImageNet dataset, requiring an even more flexible model. More research should be invested in defining an improved architecture for BIVA that holds more parameters and thereby achieves better performances.

Figure 3 shows generated samples from the $\mathcal{N}(0,I)$ prior of a BIVA $L=20$ trained on the CelebA dataset. From a visual inspection, the samples are far superior to previous natural image generations by latent variable models. We believe that previous claims stating that this type of model can only generate blurry images should be disregarded (Larsen16). Rather the limited expressiveness/flexibility of previous models should be blamed. Additional samples from BIVA can be found in Appendix G.

### 4.4 Does BIVA know what it doesn’t know?

We test the anomaly detection capabilities of BIVA replicating the most challenging experiments of (Nalisnick18). We train BIVA $L=15$ on the CIFAR-10 dataset, and evaluate eq. (2) for various values of $k$ on the CIFAR-10 test set, the SVHN dataset (Netzer2011) and the CelebA dataset. The results can be found in Table 5 and Figure 4, and are reported in terms of bits per dimension (lower is better). We see that for $k=0$, corresponding to the standard ELBO, BIVA wrongly assigns lower values to data points from SVHN. This is in line with the results obtained with other explicit density models in (Nalisnick18), and shows that by using the standard ELBO the low-level image statistics prevail and the model is not able to correctly detect out-of-distribution samples. However, for higher values of $k$, the situation is reversed. We take this as an indication that BIVA uses the high-level semantics inferred from the data to better differentiate between the CIFAR-10 and the SVHN/CelebA distributions. We repeat the experiment training BIVA $L=6$ on the FashionMNIST dataset (Table 5), and testing on the FashionMNIST test set and the MNIST dataset. Unlike the flow-based models used in (Nalisnick18), BIVA is able to learn a data distribution that can be used to detect anomalies with the standard ELBO (but also $k>0$).

## 5 Conclusion

In this paper, we have introduced BIVA, that significantly improves performances over previously introduced probabilistic latent variable models and flow-based models. BIVA is able to generate natural images that are both sharp and coherent, to improve on semi-supervised classification benchmarks and, contrarily to other models, allows for anomaly detection using the extracted high-level semantics of the data.

## References

## Appendix A Deep Learning and Variational Inference

The introduction of stochastic backpropagation [Paisley2012, Hoffman2013] and the variational auto-encoder (VAE) [Kingma13, Rezende14] has made approximate Bayesian inference and probabilistic latent variable models applicable to machine learning problems considering complex data distributions, e.g. natural images, audio, and text. The VAE is a generative model parameterized by a neural network $\theta $ and is defined by an observed variable $x$ that depends on a hierarchy of stochastic latent variables $\mathbf{z}={z}_{1},\mathrm{\dots},{z}_{L}$ so that: ${p}_{\theta}(x,\mathbf{z})={p}_{\theta}(x|{z}_{1}){p}_{\theta}({z}_{L}){\prod}_{i=1}^{L-1}{p}_{\theta}({z}_{i}|{z}_{i+1})$. This is illustrated in Figure 4(a).

The distributions ${p}_{\theta}({z}_{i}|{z}_{i+1})$ over the latent variables of the VAE are normally defined as Gaussians with diagonal covariance, whose parameters depend on the previous latent variable in the hierarchy (with the top latent variable ${p}_{\theta}({z}_{L})=\mathcal{N}({z}_{L};0,I)$). The likelihood ${p}_{\theta}(x|{z}_{1})$ is typically a Gaussian distribution for continuous data, or a Bernoulli distribution for binary data.

In order to learn the parameters $\theta $ we seek to maximize the log marginal likelihood over a training set: ${\sum}_{i}\mathrm{log}{p}_{\theta}({x}_{i})={\sum}_{i}\mathrm{log}\int {p}_{\theta}({x}_{i},{\mathbf{z}}_{i})\mathit{d}{\mathbf{z}}_{i}$. However, complex data distributions require an expressive model, which makes the above integral intractable. In order to circumvent this, we use Variational Inference [Jordan99] and introduce a posterior approximation ${q}_{\varphi}(\mathbf{z}|x)$, known as inference network or encoder, that is parameterized by a neural network $\varphi $. Using Jensen’s inequality we can derive the evidence lower bound (ELBO), a lower bound to the integral in the marginal likelihood which is a function of the variational approximation ${q}_{\varphi}(\mathbf{z}|x)$ and the generative model ${p}_{\theta}(x,\mathbf{z})$:

$\mathrm{log}{p}_{\theta}(x)\ge {\mathbb{E}}_{{q}_{\varphi}(\mathbf{z}|x)}\left[\mathrm{log}{\displaystyle \frac{{p}_{\theta}(x,\mathbf{z})}{{q}_{\varphi}(\mathbf{z}|x)}}\right]\equiv \mathcal{L}(\theta ,\varphi ).$ | (3) |

The parameters $\theta $ and $\varphi $ can be optimized by maximizing the ELBO with stochastic backpropagation and the reparameterization trick, which allows using gradient ascent algorithms with low variance gradient estimators [Kingma13, Rezende14]. As illustrated in Figure 4(b), in a VAE the variational approximation is factorized with a bottom-up structure, ${q}_{\varphi}(\mathbf{z}|x)={q}_{\varphi}({z}_{1}|x){\prod}_{i=1}^{L-1}{q}_{\varphi}({z}_{i+1}|{z}_{i})$, so that each latent variable is conditioned on the variable below in the hierarchy. For ease of computation, all the factors in the variational approximation are typically assumed to be Gaussians whose mean and diagonal covariance are parameterized by neural networks.

#### Latent variable collapse in VAEs.

A deep hierarchy of latent stochastic variables will result in a more expressive model. However, the additional variables come at a price. As shown in [Chen2017, Maaloe17], we can rewrite the ELBO (eq. (1)):

$$ |

From the above, it becomes obvious that, during the optimization of the VAE, the top stochastic latent variables may have a tendency to collapse into the prior, i.e. $$, if the model $$ is powerful enough. This is supported by empirical results in [Sonderby2016, Bowman2015] amongst others. The tendency has limited the applicability of deep VAEs in problems with complex data distributions, and has pushed VAE research towards the extension of shallow VAEs with autoregressive models, that allow capturing a lossy representation in the latent space while achieving strong generative performances [Gulrajani2016, Chen2017]. Another research direction has focused on learning more complex prior distributions through normalizing flows [Rezende2015, Tomczak16, Kingma2016]. Our research considers instead the original goal of building expressive models that can exploit a deeper hierarchy of stochastic latent variables while avoiding variable collapse.

## Appendix B Detailed Model Description

#### Generative model.

The generative model (see Figure 5(a)) has a top-down path going from ${z}_{L}$ through the intermediary stochastic latent variables to $x$. Between each stochastic layer there is a ResNet block with $M$ layers set up similarly to [Salimans17]. Weight normalization [Salimans2016a] is applied in all neural network layers. In the generative model, the BU and TD units are not distinguished so we write ${z}_{i}=({z}_{i}^{\text{scalebox}0.6BU},{z}_{i}^{\text{scalebox}0.6TD})$. We use ${f}_{i,j}$ to denote the neural network function (a function of generative model parameters $\theta $) of ResNet layer $j$ associated with stochastic layer $i$. The feature maps are written as ${d}_{i,j}$. The generative process can then be iterated as ${z}_{L}\sim \mathcal{N}(0,I)$ and $i=L-1,L-2,\mathrm{\dots},1$:

${d}_{i,0}$ | $={z}_{i+1}$ | (4) | ||

${d}_{i,j}$ | $$ | (5) | ||

${z}_{i}$ | $={\mu}_{\theta ,i}({d}_{i,M})+{\sigma}_{\theta ,i}({d}_{i,M})\otimes {\u03f5}_{i},$ | (6) |

where ${d}_{L,j}=0$, $$ denotes concatenation of feature maps in the convolutional network and hidden units in the fully connected network, $\u03f5\sim \mathcal{N}(0,I)$ and $\mu (\cdot )$ and $\sigma (\cdot )$ are parameterized by neural networks. To complete the generative model $p(x|\mathbf{z})$ is written in terms of ${z}_{1}$ and ${d}_{1}$ through a ResNet block ${f}_{0}$.

#### Inference model.

The inference model (see Figure 5(b) and 5(c)) consists of a bottom-up (BU) and top-down (TD) paths such that bottom-up stochastic units only receive bottom-up information whereas the top-down units receive both bottom-up and top-down information. The top-down path shares parameters with the generative model. For each stochastic latent variable ${z}_{i}$ in $i=1,\mathrm{\dots},L$ we use a ResNet block with $M$ layers and there are associated neural network functions ${g}_{i,j}$, $j=1,\mathrm{\dots},M$ with parameters collectively denoted by $\varphi $. The deterministic feature map of layer $i,j$ is denoted by ${\stackrel{~}{d}}_{i,j}$:

${\stackrel{~}{d}}_{i,0}$ | $$ | (7) | ||

${\stackrel{~}{d}}_{i,j}$ | $$ | (8) | ||

${z}_{i}^{\text{scalebox}0.6BU}$ | $={\mu}_{i}^{\text{scalebox}0.6BU}({\stackrel{~}{d}}_{i,M})+{\sigma}_{i}^{\text{scalebox}0.6BU}({\stackrel{~}{d}}_{i,M})\otimes {\u03f5}_{i}^{\text{scalebox}0.4BU}$ | (9) |

where $\u03f5\sim \mathcal{N}(0,I)$. Finally, to infer the top-down latent we use the bottom-up latent ${z}_{i}^{\text{scalebox}0.6TD}$ inferred in eq. (9) and pass them through the generative path eq. (5) for $i=L-1,L-2,\mathrm{\dots},2$ to determine ${d}_{i,M}$ and

${z}_{i}^{\text{scalebox}0.6TD}$ | $$ | (10) |

## Appendix C Experimental Setup

Throughout all experiments, we follow the BIVA model description that is described in detail in Appendix B and F.

#### Optimization.

All models are optimized using Adamax [Kingma14a] with a hyperparameter setting similar to the one used in [Kingma2016]. They are trained with a batch-size of 48 where the binary image experiments are trained on a single GPU and the natural image experiments are trained on two GPUs (by splitting the batch in 2 and then taking the mean over the gradients). For evaluation, we use exponential moving averages of the parameters space, similar to [Kingma2016, Salimans17].

#### Binary image architecture.

BIVA has $L=6$ layers. The ${g}_{{\varphi}_{1}}$ neural networks are defined by $M=3$, 64x5x5 (number of kernels x kernel width x kernel height) convolutional layers and an overall stride of 2. Neural networks $i=2,\mathrm{\dots},6$ are defined by four $M=3$, 64x3x3 convolutional layers. The final neural network, $i=6$, applies a stride of 2. All stochastic latent variables are densely connected layers of dimension $48,40,32,24,16,8$ for $1,\mathrm{\dots},L$ respectively. We apply a dropout rate of $0.5$ for both the deterministic layers in the generative as well as the inference model.

#### Natural image architecture (32x32).

BIVA has $L=15$ layers. The ${g}_{{\varphi}_{1}}$ neural networks are defined by $M=3$, 96x5x5 convolutional layers and an overall stride of 2. Neural networks $i=2,\mathrm{\dots},15$ are defined by $M=3$, 96x3x3 convolutional layers. Neural networks $11$ and $15$ are defined with a stride of 2. All stochastic latent variables are parameterized by convolutional layers with $38,36,34,\mathrm{\dots},10$ feature maps for $1,2,3,\mathrm{\dots},L$ respectively. The kernel width and height of the stochastic latent variables are defined similarly to the dimension of the subsequent output after striding. We apply a dropout rate of $0.2$ in the deterministic layers of the inference model.

#### Natural image architecture (64x64).

BIVA has $L=20$ layers. The ${g}_{{\varphi}_{1}}$ and ${g}_{{\varphi}_{2}}$ neural networks are defined by $M=3$, 64x7x7 and 64x5x5 convolutional layers respectively with a stride of 2 in each. Neural networks $i=3,\mathrm{\dots},11$ are defined by $M=3$ 64x3x3 convolutional layers. Neural network $11$ is defined with a stride of 2. Neural networks $i=12,\mathrm{\dots},20$ are defined by $M=3$, 128x3x3 convolutional layers and network $20$ has a stride of 2. All stochastic latent variables are parameterized by convolutional layers with $20,19,18,\mathrm{\dots},1$ feature maps for $1,2,3,\mathrm{\dots},L$ respectively. The kernel width and height of the stochastic latent variables are defined similarly to the dimension of the subsequent output after striding. We apply a dropout rate of $0.2$ in the deterministic layers of the inference model.

## Appendix D Modeling Complex 2D Densities

Potential $U(\mathbf{Z})$ | |
---|---|

1: | $\frac{1}{2}{\left(\frac{\parallel \mathbf{z}\parallel -2}{0.4}\right)}^{2}-\mathrm{ln}({e}^{-\frac{1}{2}{\left[\frac{{\mathbf{Z}}_{1}-2}{0.6}\right]}^{2}}+{e}^{-\frac{1}{2}{\left[\frac{{\mathbf{Z}}_{1}+2}{0.6}\right]}^{2}}))$ |

2: | $\frac{1}{2}{\left[\frac{{\mathbf{Z}}_{2}-{w}_{1}(\mathbf{Z})}{0.4}\right]}^{2}$ |

3: | $-\mathrm{ln}\left({e}^{-\frac{1}{2}}{\left[\frac{{\mathbf{Z}}_{2}-{\bm{w}}_{1}(\mathbf{Z})}{0.35}\right]}^{2}+{e}^{-\frac{1}{2}{\left[\frac{{\mathbf{Z}}_{2}-{\bm{w}}_{1}(\mathbf{Z})+{w}_{2}(\mathbf{Z})}{0.35}\right]}^{2})}\right)$ |

4: | $-\mathrm{ln}\left({e}^{-\frac{1}{2}{\left[\frac{{\mathbf{Z}}_{2}-{w}_{1}(\mathbf{Z})}{0.4}\right]}^{2}}+{e}^{-\frac{1}{2}{\left[\frac{{\mathbf{Z}}_{2}-{w}_{1}(\mathbf{Z})+{w}_{3}(\mathbf{Z})}{0.35}\right]}^{2})}\right)$ |

with ${w}_{1}(\mathbf{z})=\mathrm{sin}\left(\frac{2\pi {\mathbf{z}}_{1}}{4}\right)$, ${w}_{2}(\mathbf{z})=3{e}^{-\frac{1}{2}{\left[\frac{\left({\mathbf{Z}}_{1}-1\right)}{0.6}\right]}^{2}}$, | |

${w}_{3}(\mathbf{z})=3\sigma \left(\frac{{\mathbf{Z}}_{1}-1}{0.3}\right)$ and $\sigma (x)=1/\left(1+{e}^{-x}\right)$ . |

#### Problem.

[Maaloe2016] showed that Variational Auto-Encoders can fit complex posterior distributions for the latent space using the inference model ${q}_{\varphi}(z|x)$, parameterized as a fully factorized Gaussian and $p(x)$ being a simple diagonal Gaussian. In table 6, we define complex non-Gaussian densities using a potential model $U(\mathbf{Z})$, as described in [Rezende2015]. While modeling such distributions remains within the reach of an adequately complex Variational Autoencoder, optimizing such a model remains challenging.

#### Objective.

Similarly to [Maaloe2016], we choose $p(x)$ to be an isotropic Gaussian and we model the target density using the top stochastic variable: $p({z}_{L})=\frac{{e}^{-U(z)}}{Z}$. This results in the following bound:

$\mathrm{log}p(x)\ge {\mathbb{E}}_{{q}_{\varphi}(x,\mathbf{z})}\left[\mathrm{log}{\displaystyle \frac{{p}_{\theta}(x|{z}_{1})p({z}_{L})}{{q}_{\varphi}(x)}}+{\displaystyle \sum _{i=1}^{L-1}}\mathrm{log}{\displaystyle \frac{{p}_{\theta}({z}_{i}|{z}_{i+1})}{{q}_{\varphi}({z}_{i,TD}|{z}_{i+1},x){q}_{\varphi}({z}_{i+1}|{z}_{i,BU},x)}}\right].$ | (11) |

#### Experimental Setup.

We test BIVA against the VAE and LVAE models using the same number of stochastic variables, hence the models use the same number of intermediate layers. All models are implemented using 5 stochastic layers, MLPs with one hidden layer of size $128$ and with residual connections. The chosen architecture is voluntary kept minimal, therefore the task remains challenging for all models.

We train all models for $1{e}^{4}$ iterations using the Adamax optimizer. We use batch sizes of size $512$. The potential is linearly annealed from $0.1$ to $1$ during $5{e}^{3}$ steps. In order to avoid posterior collapse, $0.5$ freebits are applied to each stochastic layer. The learning rate is linearly increased from $1{e}^{-5}$ to $3{e}^{-3}$ and exponentially annealed back to $1{e}^{-5}$.

In order to measure the quality of the posterior density, we estimate $KL(q({z}_{L})||p({z}_{L}))$ using $1{e}^{6}$ posterior samples evaluated using a grid of size ${(-2,2)}^{2}$ with a resolution of $100\times 100$. Each model is trained $100$ times for each density.

#### Results.

According to the approximate $KL(q({z}_{L})||p({z}_{L}))$, we found that BIVA tends to learn a posterior that lies closer to the target density. Figure 7 shows that BIVA often learns more complex features than the baseline models, which posteriors remain closer to the modes. Figure 7 reveals that LVAE is able to find solutions that are competitive with the best BIVA samples according to $KL(q({z}_{L})||p({z}_{L}))$. However, this happens very rarely whereas BIVA has a more robust optimization behaviour.

## Appendix E Initial Results on Text Generation Tasks

parameters | $-\mathrm{log}p(x)$ | kl | ppl | |

Results with autoregressive components, no dropout | ||||

LSTM | $15.0M$ | $=41.49$ | $-$ | $36.28$ |

RNN-VAE [Bowman2015], ${\mathcal{L}}_{1}$, warmup | $23.7M$ | $\le 42.09$ | $1.61$ | $38.21$ |

RNN-VAE [Bowman2015], ${\mathcal{L}}_{1}$, finetuned | $23.7M$ | $\le 42.41$ | $5.13$ | $39.26$ |

Hybrid VAE [semeniuta2017hybrid], ${\mathcal{L}}_{1}$, finetuned | $23.7M$ | $\le 42.24$ | $4.67$ | $38.70$ |

BIVA L=7, ${\mathcal{L}}_{1}$, finetuned | $23.0M$ | $\le 42.34$ | $10.15$ | $39.04$ |

Results without autoregressive components, no dropout | ||||

Hybrid VAE [semeniuta2017hybrid], ${\mathcal{L}}_{1}$, finetuned | $15.0M$ | $\le 54.53$ | $14.10$ | $112.1$ |

BIVA L=7 Finetuned, ${\mathcal{L}}_{1}$ | $14.0M$ | $\le 54.13$ | $15.33$ | $108.3$ |

Optimizing generative models coupled with autoregressive models is a difficult task. Such coupling causes the posterior to collapse, and the latent variables are ignored. Nonetheless, autoregressive components remain a cornerstone of the generative models for text [Bowman2015, semeniuta2017hybrid, shah2018generating]. In order to enforce the model to use the latent variable, previous efforts aimed at weakening the decoder using powerful regularizing tricks, such as word dropout [Bowman2015]. We investigate the use of BIVA in the context of sentence modeling without weakening the decoder. We show that it allows optimizing the latent variables more effectively, resulting in a higher measured KL when compared to the RNN-VAE [Bowman2015] and the Hybrid VAE [semeniuta2017hybrid].

#### Dataset.

We use the Bookcorpus dataset [bookcorpus] of sentences of maximum 40 words, no preprocessing is performed and sentences are tokenized using the white spaces. We defined a vocabulary of $20000$ words and filtered out the sentences that contain non-indexed tokens. We randomly sampled $10000$ sentences for testing and used the remaining $56$M sentences for training.

#### Models.

We couple BIVA with an LSTM decoder, using the output of the convolutional model as an input sequence for the auto-regressive model. We compare our model against a LSTM language model [hochreiter1997long], the RNN-VAE [Bowman2015], and the Hybrid VAE [semeniuta2017hybrid], which couples a convolutional architecture with an LSTM decoder. We also perform experiments without using autoregressive components.

All LSTM models are parameterized by $1024$ units and we use embeddings of dimension $512$. This results in an RNN-VAE model with 23.7M parameters and we limit the other models to use the same total number of parameters. This results in using a limited number of stochastic layers for the BIVA and small a small number of kernels of $128$.

#### Training.

We trained the models for $5$ epochs with an initial learning rate of $2{e}^{-3}$ using the Adamax optimizer. We used batches of size $512$ and used only one stochastic sample. We train all latent variable models using the freebits method from [Kingma2016] with an initial KL budget of $30$ nats distributed equally over the stochastic variables and we incrementally decrease the freebits value on plateau. We also train the RNN-VAE baseline using the deterministic warmup method [Bowman2015, Sonderby2016] for comparison.

#### Likelihood and latent variables usage.

We report the test set results in table 7 and test samples in 8 and reconstructions in table 9. While BIVA without the autoregressive decoder is not competitive with an LSTM language model, we observe that replacing the LSTM inference model by a BIVA model allows exploiting the latent space more actively, which results in a higher measured KL than the RNN-VAE and Hybrid VAE baselines.

!

BIVA+LSTM | RNN-VAE |
---|---|

he said . | “ two . |

i tried to think of something to say to him , but he was already on his way back to the house . | “ you do n’t have to do this . ” |

it sounded as if he was going to say something . | the light from the lamp was dim , but the light was dim and the room was dark . |

“ and that ’s why you ’re coming . ” | or a nuclear bomb , or something . |

“ what ? ” | “ the baby ? ” |

she swallowed . | “ you ’re not going to kill me . ” |

“ i want you . ” | she was n’t going to . |

glancing up , i saw the way he was staring at me with a look of pure hatred . | “ i guess we could have been more careful , ” he said . |

i need a favor . ” | there are some things that are not good . |

he did n’t . | “ you ’re a good man . |

you ’re not dead . | i had n’t been able to get it out . |

i stood , and he followed . | “ you ’re going to have to be careful , ” he said . |

“ can i sit on the couch and talk ? ” | it ’s not a bad idea . |

“ it was n’t until i was fifteen , i was n’t in the mood to be around . | he asked . |

i looked down at my lap . | “ this is a bad idea , ” he said , his voice a little hoarse . |

the smile disappeared . | “ i ’m sure he ’s in love with you . |

it was hard to tell which one was more of a rock . | as he stepped out of the car , he saw the man standing in the doorway , his eyes wide and his face pale . |

i ’m not sure it ’s a good idea . | . |

the first two . | “ no . |

he was there . | “ in the meantime , i need to get some sleep , ” i said . |

“ all of you , ” joe said . | i was n’t . |

he did n’t care if he was n’t a vampire . | did i want to talk to you ? |

her mouth curved up , then she nodded . | “ i want to hear you say it . ” |

just tell me what you want in the end . | the train was already in the driveway . |

and again . | “ good . |

the other man ’s voice was hoarse and ragged . | i just needed to get out of here , and i needed to get out of here . |

i had n’t known that was a bad idea , but i had n’t been able to get it out of my head . | “ this is a good idea . |

your brother is the most important thing to me . | “ hey . ” |

you dont need to go to the police , right ? | she took a deep breath and let it out . |

there was a long silence . | then he kissed her . |

i looked up . | i felt a warm hand on my shoulder and a warm smile spread across my face . |

he nodded , and he looked at me , and i could tell he was thinking about it . | “ he ’s dead . ” |

“ hang on , baby . | at the time , i was going to have to get out of the house . |

we had to be close to the city , and we could n’t afford to be here . | he was so close to the edge of the bed . |

you know , it would be better if you were n’t so stupid . ” | “ i do n’t know . |

excuse me ? | “ i do n’t have a choice . ” |

you know how much i love you , too . | i know i ’m not going to let him touch me , but i do . |

a woman ’s voice , a voice that was familiar . | i could n’t see the face of the man who ’d just been in the doorway . |

i have a very important business to attend to , and i ’m going to have to make a decision . | in the end , we all know that we are not going to be able to get out of this . |

they sat on the small wooden table in the center of the room . | “ yes . |

“ it ’s fine . ” | “ what are you doing here ? ” |

she felt a rush of relief . | so the only thing that mattered was that he was here . |

maria , he says . | neither of them spoke . |

what ? | from now on , you will be able to get out of here . |

“ it does n’t seem like a lot to me , ” he said . | the thought of having to kill him made him want to kill her . |

he ’d told her everything . | the other two were staring at me , their eyes wide . |

“ she ’s in shock . | i did n’t want to be a part of it , but i was n’t going to let it go . |

“ after all , ” he murmured , “ i ’m going to go get the rest of the stuff . ” | “ i do n’t want to talk about it . |

and then , finally , she ’d done it . | she looked at him , her eyes wide . |

her words were a whisper , but it was n’t enough . | “ that ’s what you ’re going to do . |

!

input | BIVA+LSTM | RNN-VAE |
---|---|---|

“ a sad song , being sung alone in the basement . ” | “ it sounds like you ’ve been through a lot . ” | “ you ’re going to be a great father . ” |

more often , though , wherever she sank , beck was there . | more than anything , she wanted to be with him . | in the end , we all knew what was going on . |

he looked just about as pale as i had ever seen him . | he ’s still a lot more than a friend . | he was n’t going to let her go . |

caleb turned and shoved him back as he took his true form . | he lifted me up , his arms still wrapped around my waist . | he was standing in the doorway , his hands folded in front of him . |

i gasped , tried to pull away , squeezed my legs together . | i gasped , and he was n’t able to stop himself . | i felt my body tense , and i could n’t help but smile . |

i agreed as i adjusted myself and sat heavily in my chair . | i tried to ignore it , but my eyes were still closed . | i did n’t want to be the one to tell him . |

you bind me , UNK in darkness , though , in light . | he ’d decided to take her home , to make her feel safe . | he was more than willing to let her go . |

they promise me things , ask me questions , whisper and plead . | they might be able to do something about it , but they do n’t . | “ we need to talk , ” he said , his voice low . |

i glowed as i held the bear , almost bigger than me . | i started to close my eyes , but he was too strong . | i could n’t help but smile at the sight of her . |

i wonder how much he pays them to be his guard dogs . | i had to admit that it was n’t a good idea . | i do n’t want to be a part of this . |

“ hmmm , ” richard muttered , and headed up the path . | “ jesus , ” he said , his voice barely audible . | “ but you ’re going to be a father . |

he was happy that he had found it in the UNK hall . | he was n’t going to be the one to go . | he was n’t sure if he was going to make it . |

at the shack , at the condo , at the hangar . ” | at the moment , the only thing that mattered was that he was n’t alone . | he was staring at the floor , his eyes wide . |

“ i ’d pop to go to the dance with you . ” | “ i ’d prefer to go to the hospital . | “ i ’m going to go to the bathroom . |

someday , i ’ll share them with the rest of the world . | and now i have a lot of my own . | “ we ’re going to have to do something about it . |

“ maybe i ’m not the right person for this one ” . | “ maybe we can get a little more of a ride . ” | “ i do n’t think you ’re going to be able to do that . ” |

“ gin is my sister , and she ’s coming with me . | “ there ’s a chance i can get a little more sleep . ” | “ if you want to , i ’ll be there . ” |

thick desire stormed her … along with a bittersweet curl of emotion . | the tension was gone , and he was n’t looking at me . | the air smelled of stale cigarette smoke . |

they caused him to stagger back and drove him to the ground . | they had to be at the top of the hill . | he ’d found a way to get her to safety . |

you ’re not much of a friar , friar , he says . | you ’re not supposed to be around here , are you ? ” | you ’re not going to be able to do that , are you ? ” |

## Appendix F Semi-Supervised Learning

When defining BIVA for semi-supervised classification tasks we follow the approach described for the M2 model in [Kingma14]. In addition to BIVA, described in detail in Appendix B, we introduce a classification model $$ in the inference model, where $y$ is the class variable, and a Categorical latent variable dependency in the generative model.

#### Inference model.

For the classification model we introduce another deterministic hierarchy with an equivalent parameterization as ${\stackrel{~}{d}}_{i,1},\mathrm{\dots},{\stackrel{~}{d}}_{i,M}$. We denote the hierarchy ${\stackrel{~}{d}}_{i,1}^{\text{scalebox}0.4C},\mathrm{\dots},{\stackrel{~}{d}}_{i,M}^{\text{scalebox}0.4C}$. The forward-pass is performed by:

${\stackrel{~}{d}}_{i,0}^{\text{scalebox}0.6C}$ | $=\{\begin{array}{cc}\hfill x\hfill & \hfill i=1\hfill \\ \hfill {\stackrel{~}{d}}_{i-1,M}^{\text{scalebox}0.4C}\hfill & \hfill \mathrm{otherwise}\hfill \end{array}$ | (12) | ||

${\stackrel{~}{d}}_{i,j}^{\text{scalebox}0.6C}$ | $$ | (13) | ||

$y$ | $={g}_{{\varphi}_{i,M+1}}^{\text{scalebox}0.4C}({\stackrel{~}{d}}_{i,M}^{\text{scalebox}0.4C}),$ | (14) |

where ${g}_{{\varphi}_{i,M+1}}^{\text{scalebox}0.4C}$ is a final densely connected neural network layer, of the same dimension as the number of categories, and a Softmax activation function. The inference model is thereby factorized by:

$$ | (15) |

#### Generative model.

For each stochastic latent variable, $\mathbf{z}$, and the observed variable $x$ in the generative model, as well as the TD path of the inference model, we add a conditional dependency on a categorical variable $y$:

${p}_{\theta}(x,y,\mathbf{z})={p}_{\theta}(x|\mathbf{z},y){p}_{\theta}({z}_{L}){p}_{\theta}(y){\displaystyle \prod _{i=1}^{L-1}}{p}_{\theta}({z}_{i}|{z}_{>i},y).$ | (16) |

#### Evidence lower bound.

In a semi-supervised learning problem, we have labeled data and unlabeled data which results in two formulations of the ELBO. The ELBO for labeled data points is given by:

$\mathrm{log}{p}_{\theta}(x,y)\ge {\mathbb{E}}_{{q}_{\varphi}(\mathbf{z}|x,y))}\left[\mathrm{log}{\displaystyle \frac{{p}_{\theta}(x,y,\mathbf{z})}{{q}_{\varphi ,\theta}(\mathbf{z}|x,y)}}\right]\equiv -\mathcal{F}(\theta ,\varphi ).$ | (17) |

Since the classification model is not included in the above definition of the ELBO we add a classification loss term (a categorical cross-entropy), equivalent to the approach in [Kingma14]:

$$ | (18) |

where $\alpha $ is a hyperparameter that we define as in [Maaloe2016]. For the unlabeled data points, we marginalize over the labels:

$\mathrm{log}{p}_{\theta}(x)\ge {\mathbb{E}}_{{q}_{\varphi}(\mathbf{z},y|x)}\left[\mathrm{log}{\displaystyle \frac{{p}_{\theta}(x,y,\mathbf{z})}{{q}_{\varphi ,\theta}(\mathbf{z},y|x)}}\right]\equiv -\mathcal{U}(\theta ,\varphi ).$ | (19) |

The combined objective function over the labeled, $({x}_{l},{y}_{l})$, and unlabeled data points, $({x}_{u})$, are thereby given by:

$\mathcal{J}(\theta ,\varphi )={\displaystyle \sum _{{x}_{l},{y}_{l}}}\overline{\mathcal{F}}(\theta ,\varphi ;{x}_{l},{y}_{l})+{\displaystyle \sum _{{x}_{u}}}\mathcal{U}(\theta ,\varphi ;{x}_{u}).$ | (20) |

## Appendix G Additional Results

$-\mathrm{log}p(x)$ | |

Results with autoregressive components | |

DRAW+VGP [Tran2016] | $$ |

IAFVAE [Kingma2016] | $\le 79.10$ |

VLAE [Chen2017] | $\le 78.53$ |

Results without autoregressive components | |

IWAE [Burda15] | $\le 82.90$ |

ConvVAE+HVI [Salimans15] | $\le 81.94$ |

LVAE [Sonderby2016] | $\le 81.74$ |

Discrete VAE [Rolfe2017] | $\le 80.04$ |

BIVA, ${\mathcal{L}}_{1}$ | $\le 80.60$ |

BIVA, ${\mathcal{L}}_{1}e3$ | $\le 78.49$ |

BIVA finetuned, ${\mathcal{L}}_{1}$ | $\le 80.06$ |

BIVA finetuned, ${\mathcal{L}}_{1e3}$ | $\le 78.41$ |

$-\mathrm{log}p(x)$ | |

Results with autoregressive components | |

DRAW [Gregor15] | $$ |

ConvDRAW [Gregor16] | $$ |

VLAE [Chen2017] | $\le 89.83$ |

Results without autoregressive components | |

IWAE [Burda15] | $\le 103.38$ |

LVAE [Sonderby2016] | $\le 102.11$ |

DVAE [Rolfe2017] | $\le 97.43$ |

BIVA, ${\mathcal{L}}_{1}$ | $\le 95.90$ |

BIVA finetuned, ${\mathcal{L}}_{1}$ | $\le 93.54$ |

BIVA finetuned, ${\mathcal{L}}_{1e3}$ | $\le 91.34$ |

$-\mathrm{log}p(x)$ | |
---|---|

BIVA, ${\mathcal{L}}_{1}$ | $\le 94.05$ |

BIVA finetuned, ${\mathcal{L}}_{1}$ | $\le 93.54$ |

BIVA finetuned, ${\mathcal{L}}_{1e3}$ | $\le 87.98$ |

bits/dim | |

With autoregressive components | |

ConvDRAW [Gregor16] | $$ |

PixelRNN [Oord2015] | $=3.63$ |

GatedPixelCNN [Oord16] | $=3.57$ |

Without autoregressive components | |

RealNVP [Dinh16] | $=4.28$ |

GLOW [Kingma18] | $=4.09$ |

Flow++ [Ho19] | $=3.86$ |

BIVA, ${\mathcal{L}}_{1}$ | $\le 3.98$ |

BIVA, ${\mathcal{L}}_{1e3}$ | $\le 3.96$ |