Deep AutoRegressive Networks

Karol Gregor, Ivo Danihelka, Andriy Mnih, Charles Blundell, Daan Wierstra

Introduction

Directed generative models provide a fully probabilistic account of observed random variables and their latent representations. Typically either the mapping from observation to representation or representation to observation is intractable and hard to approximate efficiently. In contrast, autoencoders provide an efficient two-way mapping where an encoder maps observations to representations and a decoder maps representations back to observations. Recently several authors (Ranzato et al., 2007; Vincent et al., 2008; Vincent, 2011; Rifai et al., 2012; Bengio et al., 2013b) have developed probabilistic versions of regularised autoencoders, along with means of generating samples from such models. These sampling procedures are often iterative, producing correlated approximate samples from previous approximate samples, and as such explore the full distribution slowly, if at all.

In this paper, we introduce Deep AutoRegressive Networks (DARNs), deep generative autoencoders that in contrast to the aforementioned models efficiently generate independent, exact samples via ancestral sampling. To produce a sample, we simply perform a top-down pass through the decoding part of our model, starting at the deepest hidden layer and sampling one unit at a time, layer-wise. Training a DARN proceeds by minimising the total information stored for reconstruction of the original input, and as such follows the minimum description length principle (MDL; Rissanen, 1978). This amounts to backpropagating an MDL cost through the entire joint encoder/decoder.

There is a long history of viewing autoencoders through the lens of MDL (Hinton & Van Camp, 1993; Hinton & Zemel, 1994), yet this has not previously been considered in the context of deep autoencoders. MDL provides a sound theoretical basis for DARN’s regularisation, whilst the justification of regularised autoencoders was not immediately obvious. Learning to encode and decode observations according to a compression metric yields representations that can be both concise and irredundant from an information theoretic point of view. Due to the equivalence of compression and prediction, compressed representations are good for making predictions and hence also good for generating samples. Minimising the description length of our model coincides exactly with minimising the Helmholtz variational free energy, where our encoder plays the role of the variational distribution. Unlike many other variational learning algorithms, our algorithm is not an expectation maximisation algorithm, but rather a stochastic gradient descent method, jointly optimising all parameters of the autoencoder simultaneously.

DARN and its learning algorithm easily stack, allowing ever deeper representations to be learnt, whilst at the same time compressing the training data — DARN allows for alternating layers of stochastic hidden units and deterministic non-linearities. Each stochastic layer within DARN is autoregressive: each unit receives input both from the preceding layer and the preceding units within the same layer. Autoregressive structure captures much of the dependence among units within the same layer, at very little computational cost during both learning and generation. This is in marked contrast to other mechanisms for lateral connections, such as introducing within-layer undirected edges, which often come at a prohibitively high computational cost at training and/or generation time.

Recently, several authors have exploited autoregression for distribution modelling (Larochelle & Murray, 2011; Gregor & LeCun, 2011; Uria et al., 2013). Unlike these models, DARN can have stochastic hidden units, and places autoregressive connections among these hidden units. Depending upon the architecture of the network, this can yield gains in both statistical and computational efficiency.

The remainder of the paper is structured as follows. In Section 2 we describe the architecture of our model, Section 3 reviews the minimum description length principle and its application to autoencoders. Section 4 describes the approximate parameter estimation algorithm. Section 5 has the results of our model on several data sets, and we conclude with a brief summary in Section 6.

Model Architecture

Our model is a deep, generative autoencoder; an example is shown in Figure 1 with two hidden layers. DARN has three components: the encoder q(HX)q(H|X) that picks a representation HH for a given observation XX, a decoder prior p(H)p(H) which provides a prior distribution on representations HH for generation, and a decoder conditional p(XH)p(X|H) which, given a representation HH, produces an observation XX. We shall use uppercase letters for random variables and lowercase for their values. We shall first describe our model with a single stochastic hidden layer and later show how this is easily generalised to multiple layers.

We begin by describing the decoder prior on the representation hh. The decoder prior on the representation hh is an autoregressive model. Let h1:jh_{1:j} denote the vector (h1,h2,,hj)(h_{1},h_{2},\dots,h_{j}) where each hi{0,1}h_{i}\in\{0,1\}, then

where h=(h1,h2,,hnh)h=(h_{1},h_{2},\dots,h_{n_{h}}) denotes the representation with nhn_{h} hidden stochastic units. p(hjh1:j1)p(h_{j}|h_{1:j-1}) is the probability mass function of hjh_{j} conditioned upon the activities of the previous units in the representation h1:j1h_{1:j-1}.

In DARN, we parameterise the conditional probability mass of hjh_{j} in a variety of ways, depending upon the complexity of the problem. Logistic regression is the simplest:

The conditional distributions of the decoder p(XH)p(X|H) and of the encoder q(HX)q(H|X) have similar forms:

where, as with the decoder prior, the conditional probability mass functions can be parameterised as in Eq. 2 (we shall explore some more elaborate parameterisations later). Consequently,

The simple model presented so far is already a universal distribution approximator — it can approximate any (reasonable) distribution given sufficient capacity. As adding extra hidden layers to models such as deep belief networks strictly improves their representational power (Le Roux & Bengio, 2008), we could ask whether that is also the case for DARN. Although every distribution on HH may be written as Eq. 1, not every factorisation can be parameterised as Eq. 2. Thus we propose boosting DARN’s representational power in three ways: by adding stochastic hidden layers, by adding deterministic hidden layers, and by using alternate kinds of autoregressivity. We now consider each approach in turn.

We consider an autoencoder with hidden stochastic layers H(1),,H(nlayers)H^{(1)},\ldots,H^{({n_{\text{layers}}})} each with nh(1),,nh(nlayers)n_{h}^{(1)},\ldots,n_{h}^{({n_{\text{layers}}})} units, respectively. For convenience we denote the input layer by H(0)=XH^{(0)}=X and let H(nlayers+1)=H^{({n_{\text{layers}}}+1)}=\emptyset. The decoder and encoder probability distributions become

for l=0,,nlayersl=0,\ldots,{n_{\text{layers}}} and k=1,,nlayersk=1,\ldots,{n_{\text{layers}}}.

Additional deterministic hidden layers.

The second way of adding complexity is to insert more complicated deterministic functions between the stochastic layers. This applies both to the encoder and the decoder. If we wished to add just one deterministic hidden layer, we could use a simple multi-layer perceptron such as:

Alternate kinds of autoregressivity.

Finally, we can increase representational power by using more flexible autoregressive models, such as NADE (Larochelle & Murray, 2011) and EoNADE (Uria et al., 2013), instead of the simple linear autoregressivity we proposed in the previous section.

The amount of information that can be stored in the representation HH is upper bounded by the number of stochastic hidden units. Additional deterministic hidden units do not introduce any extra random variables and so cannot increase the capacity of the representation, whilst additional stochastic hidden units can.

2 Local connectivity

DARN can be made to scale to high-dimensional (image) data by restricting connectivity, both between adjacent layers, and autoregressively, within layers. This is particularly useful for modelling larger images. Local connectivity can be either fully convolutional (LeCun et al., 1998) or use less weight sharing. In this paper we use the periodic local connectivity of Gregor & LeCun (2010) which uses less weight sharing than full convolutional networks.

3 Sampling

Sampling in DARN is simple and efficient as it is just ancestral sampling. We start with the top-most layer, sample the first hidden unit h1p(H1(nlayers))h_{1}\sim p(H_{1}^{({n_{\text{layers}}})}) and then for each ii in turn, we sample hip(Hi(nlayers)h1:i1(nlayers))h_{i}\sim p(H_{i}^{({n_{\text{layers}}})}|h_{1:i-1}^{({n_{\text{layers}}})}). We repeat this procedure for each successive layer until we reach the observation. Sampling from the encoder works in exactly the same way but in the opposite direction, sampling each hidden unit from q(Hi(l)h1:i1(l),h(l1))q(H_{i}^{(l)}|h_{1:i-1}^{(l)},h^{(l-1)}) successively.

A DARN without a stochastic hidden layer but with an autoregressive visible layer is a fully visible sigmoid belief network (FVSBN; Frey, 1998). Thus FVSBN sampling scales as O(nx2)O(n_{x}^{2}). In NADE (Larochelle & Murray, 2011; Gregor & LeCun, 2011), autoregression is present in the visibles, but only deterministic hidden units are used. Sampling then scales as O(nxnd)O(n_{x}n_{d}) where nxn_{x} is the number of visibles and ndn_{d} is the number of deterministic hidden units. The complexity of sampling from a fully autoregressive single stochastic hidden layer DARN is O((nh+nx)2)O((n_{h}+n_{x})^{2}). If we omit the autoregressivity on the observations, we obtain a time complexity of O(nh(nx+nh))O(n_{h}(n_{x}+n_{h})). Furthermore, if the stochastic hidden layer is sparse, such that at nsn_{s} units are active on average, we obtain an expected time complexity of O(ns(nx+nh))O(n_{s}(n_{x}+n_{h})). We call this sparse, fast version fDARN. As more stochastic or deterministic hidden layers are added to DARN, the advantage of DARN becomes greater as each part of the decoder need only be computed once for DARN per datum, wheras deeper NADE-like models (Uria et al., 2013) require re-computation of large parts of the model for each unit.

Minimum Description Length and Autoencoders

Autoencoders have previously been trained by an MDL principle derived from bits-back coding (Hinton & Van Camp, 1993). This yields generative autoencoders trained to minimise the Helmholtz variational free energy (Hinton & Zemel, 1994). Here we extend this work to deeper, autoregressive models trained by a stochastic approximation to backpropagation as opposed to expectation maximisation.

According to the MDL principle, we shall train this autoencoder by finding parameters that try to maximally compress the training data. Suppose a sender wishes to communicate a binary sequence of nxn_{x} elements, xx, to a receiver. We shall first sample a representation of nhn_{h} binary elements, hh, to communicate and then send the residual of xx relative to this representation. The idea is that the representation has a more concise code than the original datum xx and so can be compressed effectively: for example, by arithmetic coding (MacKay, 2003).

The description length of a random variable taking a particular value indicates how many bits must be used to communicate that particular value. Shannon’s source coding theorem shows that the description length is equal to the negative logarithm of the probability of the random variable taking that particular value (MacKay, 2003). Hence, when communicating a datum xx, having already communicated its representation hh, the description length would be

We wish for the parameters of the autoencoder to compress the data well on average, and so we shall minimise the expected description length,

where L(h)L(h) denotes the description length of the representation hh, and q(hx)q(h|x) is the encoder probability of the representation hh. As we are using bits-back coding, the description length of the representation hh is

Substituting Eq. 11 and Eq. 13 into Eq. 12 we recover the Helmholtz variational free energy:

Picking the parameters of q(HX)q(H|X) and p(X,H)p(X,H) to minimise the description length in Eq. 14 yields a coding scheme that requires the fewest expected number of bits to communicate a datum xx and its representation hh.

As Eq. 14 is the variational free energy, the encoder q(HX)q(H|X) that minimises Eq. 14 is the posterior p(HX)p(H|X). Variational learning methods sometimes refer to the negative expected description length L(x)-L(x) as the expected lower bound as it serves as a lower bound upon log2p(x)\log_{2}p(x). Note here that we shall be interested in optimising the parameters of q(HX)q(H|X) and p(X,H)p(X,H) simultaneously, whereas variational learning often only optimises the parameters of q(HX)q(H|X) and p(X,H)p(X,H) by co-ordinate descent.

Learning

Learning in DARN amounts to jointly training weights and biases θ\theta of both the encoder and the decoder, simultaneously, to minimise Eq. 12. The procedure is based on gradient descent by backpropagation and is based upon a number of approximations to the gradient of Eq. 12.

We write the expected description length in Eq. 12 as:

Calculating Eq. 4 exactly is intractable. Hence we shall use a Monte carlo approximation.

Given an observation xx, sample a representation hq(Hx)h\sim q(H|x) (see Section 2.3).

Calculate q(hx)q(h|x) (Eq. 4), p(xh)p(x|h) (Eq. 3) and p(h)p(h) (Eq. 1) for the sampled representation hh and given observation xx.

Update the parameters of the autoencoder by following the gradient θL(x)\nabla_{\theta}L(x).

We now turn to calculating the gradient of Eq. 4 which requires backpropagation of the MDL cost through the joint encoder/decoder. Unfortunately, this pass through the model includes stochastic units. Backpropagating gradients through stochastic binary units naïvely yields gradients that are highly biased, yet often work well in practice (Hinton, 2012). Whilst it is possible to derive estimators that are unbiased (Bengio et al., 2013a), their empirical performance is often unsatisfactory. In this work, we backpropagate gradients through stochastic binary units, and then re-weight these gradients to reduce bias and variance. Details are given in Appendix A.

Finally note that when the encoder is not autoregressive, the entire system can be trained using standard matrix operations and point-wise nonlinearities. Hence it is easily implementable on graphical processing units. The decoder’s autoregressive computation is expressed as a full matrix multiplication with a triangular matrix.

Results

We trained our models on binary UCI data sets, MNIST digits and frames from five Atari 2600 games (Bellemare et al., 2013).

The quantitative results reported here are in terms of the probability the decoder assigns to a test datum: p(x)p(x). For small DARN models, we can evaluate the likelihood p(x)p(x) exactly by iterating over every possible representation: p(x)=hp(x,h)p(x)=\sum_{h}p(x,h). As the computational cost of this sum grows exponentially in the size of the representation, for DARN models with more than 16 stochastic hidden units, we use an importance sampling estimate using the encoder distribution:

where ss indexes one of SS samples. As this estimate can have high variance, we repeat the estimation ten times and report the 95 per cent confidence interval. In our experiments, the variance of the estimator was low. Where available, we used a validation set to choose the learning rate and certain aspects of the model architecture, such as the number of hidden units. We used the Monte Carlo approximation to expected description length in Eq. 4 of the validation set to select these.

We evaluated the test-set performance of DARN on eight binary data sets from the UCI repository (Bache & Lichman, 2013). In Table 1, we compare DARN to baseline models from Uria et al. (2013).

We used a DARN with two hidden layers. The first layer was deterministic, with tanh activations. The second layer was a stochastic layer with an autoregressive prior p(H)p(H). The decoder conditional p(XH)p(X|H) included autoregressive connections.

The architecture and learning rate was selected by cross-validation on a validation set for each data set. The number of deterministic hidden units was selected from 100 to 500, in steps of 100, whilst the number of stochastic hidden units was selected from {8,12,16,32,64,128,256}\{8,12,16,32,64,128,256\}. We used RMSprop (Graves, 2013) with momentum 0.9 and learning rates 0.00025, 0.0000675 or 10510^{-5}. The network was trained with minibatches of size 100. The best results are shown in bold in Table 1. DARN achieved better test log-likelihood on four of eight data sets than the baseline models reported in Uria et al. (2013). We found that regularisation by adaptive weight noise on these small data sets (Graves, 2011) did not yield good results, but early stopping based on the performance on the validation set worked well.

2 Binarised MNIST data set

We evaluated the sampling and test-set performance of DARN on the binarised MNIST data set (Salakhutdinov & Murray, 2008), which consists of 50,00050,000 training, 10,00010,000 validation, and 10,00010,000 testing images of hand-written digits (Larochelle & Murray, 2011). Each image is 28×2828\times 28 pixels.

We used two hidden layers, one deterministic, one stochastic. The results are in Table 2 with nhn_{h} denoting the number of stochastic hidden units. The deterministic layer had 100 units for architectures with 16 or fewer stochastic units per layer, and 500 units for more than 16 stochastic units. The deterministic activation function was taken to be the tanh function. We used no autoregressivity for the observation layer — the decoder conditional is a product of independent Bernoulli distributions, conditioned upon the representation. Training was done with RMSprop (Graves, 2013), momentum 0.9 and minibatches of size 100. We used a learning rate of 3×105\times 10^{-5}. Adaptive weight noise (Graves, 2011), denoted by “adaNoise” in Table 2, was used to avoid the need for early stopping.

After training, we were able to measure the exact log-likelihood for networks with 16 or fewer stochastic hidden units. For the network with 500 hidden units, we estimated the log-likelihood by importance sampling given by the above procedure. For each test example, we sampled 100,000100,000 latent representations from the encoder distribution. The estimate was repeated ten times; we report the estimated 95 per cent confidence intervals. The obtained log-likelihoods and confidence intervals are given in Table 2 along with those of other models. DARN performs favourably compared to the other models. For example, a DARN with just 9 stochastic hidden units obtains almost the same log-likelihood as a mixture of Bernoullis (MoBernoullis) with 500 components: log25009\log_{2}500\approx 9. DARN with 500 stochastic hidden units compares favourably to state-of-the-art generative performance of deep Boltzmann machines (DBM; Salakhutdinov & Hinton, 2009) and deep belief networks (DBN; Salakhutdinov & Murray, 2008; Murray & Salakhutdinov, 2009). Notably, DARN’s upper bound, the expected description length given in the far right column, is lower than the likelihood of NADE whilst DARN’s estimated log likelihood is lower than the log-likelihood of the best reported EoNADE (Uria et al., 2013) results.

We performed several additional experiments. First, we trained fDARN with 400 hidden units and 5%5\% sparsity, resulting in an upper bound negative log-likelihood of 96.1 (Table 2). The estimated speed of generation was 2.4×1042.4\times 10^{4} multiplications per sample, which compares favourably to NADE’s of 2.2×1062.2\times 10^{6}, a nearly 100 fold speedup. While the likelihood is worse, the samples appear reasonable by ocular inspection.

Next, we trained a very deep, 1212 stochastic layer DARN with 8080 stochastic units in each layer, and 400400 tanh units in each deterministic layer. Here we also used skip connections where each tanh layer received input from all previous stochastic layers. Due to computational constraints we only evaluated the upper bound of this architecture as reported in Table 2 — where it records the best upper bound among all DARN models, showing the value of depth in DARN.

Finally, we trained a network with one stochastic layer, 400 units, and one tanh layer (1000 units) in both encoder and decoder on the pixel intensities directly, rather than binarising the data set. We show the sample probabilities of observables in Figure 2(right).

3 Atari 2600 game frames

We recorded 100,000100,000 frames from five different Atari 2600 games (Bellemare et al., 2013) from random play, recording each frame with 1%1\% probability. We applied an edge detector to the images yielding frames of 159×209159\times 209 pixelsThe script to generate the dataset is available at https://github.com/fidlej/aledataset. Frames of these games generated by DARN are shown in Figure 5.

To scale DARN to these larger images, we used three hidden layers. The stack of layers contains a locally connected layer with weight-sharing (see Section 2.2), a rectified linear activation function, another locally connected layer followed by a rectified linear function and a fully connected layer followed by 300 stochastic binary units. The autoregressive prior on the representation was also fully connected. The locally connected layers had 32 filters with a period of 8. The first locally connected layer used stride 4 and kernel size 8. The second locally connected layer used stride 2 and kernel size 4. The autoregressive connections for the visible layer used a period of 14 and kernel size 15.

The games in Figure 5 are ordered from left to right, in decreasing order of log probability. While DARN captures much of the structure in these games, such as the scores, various objects, and correlations between objects, when the game becomes less regular, as with River Raid (second to right) and Sea Quest (far right), DARN is not able to generate reasonable frames.

Figure 5 shows the representation that DARN learns for a typical frame of the game Freeway. To show the effect of deeper layers in DARN, Figure 3 shows the frames DARN generates using the representation from different depths. In the game of Freeway, several cars (the white blobs) travel along lanes, delimited by dashed white lines. Here we used a DARN with three stochastic hidden layers. When DARN was trained using a sparsity penalty on the activations, as we described in Section 2.3, it learnt a representation where the second hidden layer captures the rough outline of each car, whereas the first hidden layer filled in the details of each car. A global bias learns the background image. A third hidden layer decides where to place the cars. All layers except the very top layer are locally connected. The top layer has 100 units. The second hidden layer was locally connected with a kernel of size 21×2121\times 21, whilst the first hidden layer was locally connected with a kernel of size 7×77\times 7.

Conclusion

In this paper we introduced deep autoregressive networks (DARN), a new deep generative architecture with autoregressive stochastic hidden units capable of capturing high-level structure in data to generate high-quality samples. The method, like the ubiquitous autoencoder framework, is comprised of not just a decoder (the generative element) but a stochastic encoder as well to allow for efficient and tractable inference. Training proceeds by backpropagating an MDL cost through the joint model, which approximately equates to minimising the Helmholtz variational free energy. This procedure necessitates backpropagation through stochastic units, as such yielding an approximate Monte Carlo method. The model samples efficiently, trains efficiently and is scalable to locally connected and/or convolutional architectures. Results include state-of-the-art performance on multiple data sets.

Appendix A Derivation of Gradients

We derive the gradient of the objective function with respect to the inputs to a stochastic binary hidden unit. Let q(hi)q(h_{i}) be the probability distribution of the iith hidden unit, f(hi)f(h_{i}) be the part of the network which takes hih_{i} as an input. The expected value of f(hi)f(h_{i}) and its gradient are:

where θF^\widehat{\nabla_{\theta}F} denotes our estimator. A good baseline should be correlated with f(hi)f(h_{i}), have low variance, and also be such that the expected value of θlogq(hi)b\nabla_{\theta}\log q(h_{i})b is zero to get an unbiased estimate of the gradient. We chose a non-constant baseline. The baseline will be a first-order Taylor approximation of ff. We can get the first-order derivatives from backpropagation. The baseline is a Taylor approximation of ff about hih_{i}, evaluated at a point hih_{i}^{\prime}:

To satisfy the unbiasedness requirement, we need to solve the following equation for hih_{i}^{\prime}:

The solution depends on the shape of ff. If ff is a linear function, any hih_{i}^{\prime} can be used. If ff is a quadratic function, the solution is hi=12h_{i}^{\prime}=\frac{1}{2}. If fif_{i} is a cubic or higher-order function, the solution depends on the coefficients of the polynomial. We will use hi=12h_{i}^{\prime}=\frac{1}{2} and our estimator will be biased for non-quadratic functions.

By substituting the baseline into Eq. 20 we obtain the final form of our estimator of the gradient:

An implementation can estimate the gradient with respect to q(Hi=1)q(H_{i}=1) by backpropagating with respect to hih_{i} and scaling the gradient by 12q(hi)\frac{1}{2q(h_{i})}, where hih_{i} is the sampled binary value.

References