Autoencoder
An autoencoder is a type of artificial neural network used to learn efficient data codings in an unsupervised manner. The aim of an autoencoder is to learn a representation for a set of data, typically for dimensionality reduction, by training the network to ignore signal “noise”. Along with the reduction side, a reconstructing side is learnt, where the autoencoder tries to generate from the reduced encoding a representation as close as possible to its original input, hence its name. Several variants exist to the basic model, with the aim of forcing the learned representations of the input to assume useful properties. Examples are the regularized autoencoders, proven effective in learning representations for subsequent classification tasks, and Variational autoencoders, with their recent applications as generative models. Autoencoders are effectively used for solving many applied problems, from face recognition to acquiring the semantic meaning of words.
Introduction
An autoencoder is a neural network that learns to copy its input to its output. It has an internal layer that describes a code used to represent the input, and it is constituted by two main parts: an encoder that maps the input into the code, and a decoder that maps the code to a reconstruction of the original input.Performing the copying task perfectly would simply duplicate the signal, and this is why autoencoders usually are restricted in ways that force them to reconstruct the input approximately, preserving only the most relevant aspects of the data in the copy.
The idea of autoencoders has been popular in the field of neural networks for decades, and the first applications date back to the '80s. Their most traditional application was dimensionality reduction or feature learning, but more recently the autoencoder concept has become more widely used for learning generative models of data. Some of the most powerful AIs in the 2010s involved sparse autoencoders stacked inside of deep neural networks.
Basic Architecture
The simplest form of an autoencoder is a feedforward, non-recurrent neural network similar to single layer perceptrons that participate in multilayer perceptrons – having an input layer, an output layer and one or more hidden layers connecting them – where the output layer has the same number of nodes as the input layer, and with the purpose of reconstructing its inputs instead of predicting the target value given inputs. Therefore, autoencoders are unsupervised learning models.An autoencoder consists of two parts, the encoder and the decoder, which can be defined as transitions and such that:
In the simplest case, given one hidden layer, the encoder stage of an autoencoder takes the input and maps it to :
This image is usually referred to as code, latent variables, or latent representation. Here, is an element-wise activation function such as a sigmoid function or a rectified linear unit. is a weight matrix and is a bias vector. Weights and biases are usually initialized randomly, and then updated iteratively during training through Backpropagation. After that, the decoder stage of the autoencoder maps to the reconstruction of the same shape as :
where for the decoder may be unrelated to the corresponding for the encoder.
Autoencoders are trained to minimise reconstruction errors, often referred to as the "loss":
where is usually averaged over some input training set.
As mentioned before, the training of an autoencoder is performed through Backpropagation of the error, just like a regular feedforward neural network.
Should the feature space have lower dimensionality than the input space, the feature vector can be regarded as a compressed representation of the input. This is the case of undercomplete autoencoders. If the hidden layers are larger than , or equal to, the input layer, or the hidden units are given enough capacity, an autoencoder can potentially learn the identity function and become useless. However, experimental results have shown that autoencoders might still learn useful features in these cases. In the ideal setting, one should be able to tailor the code dimension and the model capacity on the basis of the complexity of the data distribution to be modeled. One way to do so, is to exploit the model variants known as Regularized Autoencoders''.
Variations
Regularized Autoencoders
Various techniques exist to prevent autoencoders from learning the identity function and to improve their ability to capture important information and learn richer representations.Sparse autoencoder (SAE)
Recently, it has been observed that when representations are learnt in a way that encourages sparsity, improved performance is obtained on classification tasks. Sparse autoencoder may include more hidden units than inputs, but only a small number of the hidden units are allowed to be active at once. This sparsity constraint forces the model to respond to the unique statistical features of the input data used for training.Specifically, a sparse autoencoder is an autoencoder whose training criterion involves a sparsity penalty on the code layer.
Recalling that, the penalty encourages the model to activate some specific areas of the network on the basis of the input data, while forcing all other neurons to be inactive.
This sparsity of activation can be achieved by formulating the penalty terms in different ways.
- One way to do it, is by exploiting the Kullback-Leibler divergence. Let
where is summing over the hidden nodes in the hidden layer, and is the KL-divergence between a Bernoulli random variable with mean and a Bernoulli random variable with mean.
- Another way to achieve sparsity in the activation of the hidden unit, is by applying L1 or L2 regularization terms on the activation, scaled by a certain parameter. For instance, in the case of L1 the loss function would become
- A further proposed strategy to force sparsity in the model is that of manually zeroing all but the strongest hidden unit activations. The k-sparse autoencoder is based on a linear autoencoder and tied weights. The identification of the strongest activations can be achieved by sorting the activities and keeping only the first k values, or by using ReLU hidden units with thresholds that are adaptively adjusted until the k largest activities are identified. This selection acts like the previously mentioned regularization terms in that it prevents the model from reconstructing the input using too many neurons.
Denoising autoencoder (DAE)
Indeed, DAEs take a partially corrupted input and are trained to recover the original undistorted input. In practice, the objective of denoising autoencoders is that of cleaning the corrupted input, or denoising. Two underlying assumptions are inherent to this approach:
- Higher level representations are relatively stable and robust to the corruption of the input;
- To perform denoising well, the model needs to extract features that capture useful structure in the distribution of the input.
The training process of a DAE works as follows:
- The initial input is corrupted into through stochastic mapping.
- The corrupted input is then mapped to a hidden representation with the same process of the standard autoencoder,.
- From the hidden representation the model reconstructs.
The above-mentioned training process could be developed with any kind of corruption process. Some examples might be additive isotropic Gaussian noise, Masking noise or Salt-and-pepper noise.
Finally, notice that the corruption of the input is performed only during the training phase of the DAE. Once the model has learnt the optimal parameters, in order to extract the representations from the original data no corruption is added.
Contractive autoencoder (CAE)
Contractive autoencoder adds an explicit regularizer in their objective function that forces the model to learn a function that is robust to slight variations of input values. This regularizer corresponds to the Frobenius norm of the Jacobian matrix of the encoder activations with respect to the input. Since the penalty is applied to training examples only, this term forces the model to learn useful information about the training distribution. The final objective function has the following form:The name contractive comes from the fact that the CAE is encouraged to map a neighborhood of input points to a smaller neighborhood of output points.
There is a connection between the denoising autoencoder and the contractive autoencoder : in the limit of small Gaussian input noise, DAE make the reconstruction function resist small but finite-sized perturbations of the input, while CAE make the extracted features resist infinitesimal perturbations of the input.
Variational autoencoder (VAE)
Unlike classical autoencoders, Variational autoencoders are generative models, like Generative Adversarial Networks. Their association with this group of models derives mainly from the architectural affinity with the basic autoencoder, but their mathematical formulation differs significantly. VAEs are directed probabilistic graphical models whose posterior is approximated by a neural network, forming an autoencoder-like architecture. Differently from discriminative modeling that aims to learn a predictor given the observation, generative modeling tries to simulate how the data is generated, in order to understand the underlying causal relations. Causal relations have indeed the great potential of being generalizable.Variational autoencoder models make strong assumptions concerning the distribution of latent variables. They use a variational approach for latent representation learning, which results in an additional loss component and a specific estimator for the training algorithm called the Stochastic Gradient Variational Bayes estimator. It assumes that the data is generated by a directed graphical model and that the encoder is learning an approximation to the posterior distribution where and denote the parameters of the encoder and decoder respectively. The probability distribution of the latent vector of a VAE typically matches that of the training data much closer than a standard autoencoder. The objective of VAE has the following form:
Here, stands for the Kullback–Leibler divergence. The prior over the latent variables is usually set to be the centred isotropic multivariate Gaussian ; however, alternative configurations have been considered.
Commonly, the shape of the variational and the likelihood distributions are chosen such that they are factorized Gaussians:
where and are the encoder outputs, while and are the decoder outputs.
This choice is justified by the simplifications that it produces when evaluating both the KL divergence and the likelihood term in variational objective defined above.
VAE have been criticized because they generate blurry images. However, researchers employing this model were showing only the mean of the distributions,, rather than a sample of the learned Gaussian distribution
These samples were shown to be overly noisy due to the choice of a factorized Gaussian distribution. Employing a Gaussian distribution with a full covariance matrix,
could solve this issue, but is computationally intractable and numerically unstable, as it requires estimating a covariance matrix from a single data sample. However, later research showed that a restricted approach where the inverse matrix is sparse, could be tractably employed to generate images with high-frequency details.
Large-scale VAE models have been developed in different domains to represent data in a compact probabilistic latent space. For example, VQ-VAE for image generation and Optimus for language modeling.
Advantages of Depth
Autoencoders are often trained with only a single layer encoder and a single layer decoder, but using deep encoders and decoders offers many advantages.- Depth can exponentially reduce the computational cost of representing some functions.
- Depth can exponentially decrease the amount of training data needed to learn some functions.
- Experimentally, deep autoencoders yield better compression compared to shallow or linear autoencoders.
Training Deep Architectures
Recently, researchers have debated whether joint training would be better for deep auto-encoders. A study published in 2015 empirically showed that the joint training method not only learns better data models, but also learned more representative features for classification as compared to the layerwise method. However, their experiments highlighted how the success of joint training for deep autoencoder architectures depends heavily on the regularization strategies adopted in the modern variants of the model.
Applications
The two main applications of autoencoders since the 80s have been dimensionality reduction and information retrieval, but modern variations of the basic model were proven successful when applied to different domains and tasks.Dimensionality Reduction
was one of the first applications of deep learning, and one of the early motivations to study autoencoders. In a nutshell, the objective is to find a proper projection method, that maps data from high feature space to low feature space.One milestone paper on the subject was that of Geoffrey Hinton with his publication in Science Magazine in 2006: in that study, he pretrained a multi-layer autoencoder with a stack of RBMs and then used their weights to initialize a deep autoencoder with gradually smaller hidden layers until a bottleneck of 30 neurons. The resulting 30 dimensions of the code yielded a smaller reconstruction error compared to the first 30 principal components of a PCA, and learned a representation that was qualitatively easier to interpret, clearly separating clusters in the original data.
Representing data in a lower-dimensional space can improve performance on different tasks, such as classification. Indeed, many forms of dimensionality reduction place semantically related examples near each other, aiding generalization.
Relationship with principal component analysis (PCA)
If linear activations are used, or only a single sigmoid hidden layer, then the optimal solution to an autoencoder is strongly related to principal component analysis. The weights of an autoencoder with a single hidden layer of size span the same vector subspace as the one spanned by the first principal components, and the output of the autoencoder is an orthogonal projection onto this subspace. The autoencoder weights are not equal to the principal components, and are generally not orthogonal, yet the principal components may be recovered from them using the singular value decomposition.However, the potential of Autoencoders resides in their non-linearity, allowing the model to learn more powerful generalizations compared to PCA, and to reconstruct back the input with a significantly lower loss of information.
Information Retrieval
benefits particularly from dimensionality reduction in that search can become extremely efficient in certain kinds of low dimensional spaces. Autoencoders were indeed applied to semantic hashing, proposed by Salakhutdinov and Hinton in 2007. In a nutshell, training the algorithm to produce a low-dimensional binary code, then all database entries could be stored in a hash table mapping binary code vectors to entries. This table would then allow to perform information retrieval by returning all entries with the same binary code as the query, or slightly less similar entries by flipping some bits from the encoding of the query.Anomaly Detection
Another field of application for autoencoders is anomaly detection. By learning to replicate the most salient features in the training data under some of the constraints described previously, the model is encouraged to learn how to precisely reproduce the most frequent characteristics of the observations. When facing anomalies, the model should worsen its reconstruction performance. In most cases, only data with normal instances are used to train the autoencoder; in others, the frequency of anomalies is so small compared to the whole population of observations, that its contribution to the representation learnt by the model could be ignored. After training, the autoencoder will reconstruct normal data very well, while failing to do so with anomaly data which the autoencoder has not encountered. Reconstruction error of a data point, which is the error between the original data point and its low dimensional reconstruction, is used as an anomaly score to detect anomalies.Image Processing
The peculiar characteristics of autoencoders have rendered these model extremely useful in the processing of images for various tasks.One example can be found in lossy image compression task, where autoencoders demonstrated their potential by outperforming other approaches and being proven competitive against JPEG 2000.
Another useful application of autoencoders in the field of image preprocessing is image denoising. The need for efficient image restoration methods has grown with the massive production of digital images and movies of all kinds, often taken in poor conditions.
Autoencoders are increasingly proving their ability even in more delicate contexts such as medical imaging. In this context, they have also been used for image denoising as well as super-resolution. In the field of image-assisted diagnosis, there exist some experiments using autoencoders for the detection of breast cancer or even modelling the relation between the cognitive decline of Alzheimer's Disease and the latent features of an autoencoder trained with MRI
Lastly, other successful experiments have been carried out exploiting variations of the basic autoencoder for image super-resolution tasks.