Representation
Learning
Autoencoders
Our lectures so far were mostly adapted from
Also, Dr. Wei at TCU
Dr. Andrew Ng is a globally recognized leader in AI (Artificial Intelligence). He is
Founder of DeepLearning.AI, Executive Chairman of LandingAI, General Partner
at AI Fund, Chairman and Co-Founder of Coursera and an Adjunct Professor at
Stanford University’s Computer Science Department.
Introduction
• Autoencoders are an unsupervised learning techniques in which
we leverage neural networks for the task of representation learning.
• impose a bottleneck in the network which forces a compressed knowledge
representation of the original input.
• If the input features were each independent of one another, this
compression and subsequent reconstruction would be a very difficult task.
• Some correlations between input features is desired.
Autoencoders
We can take an unlabeled dataset;
frame it as a supervised learning problem;
that outputs, a reconstruction of the original
input .
How would you train this network? What would you
minimize?
This network can be trained by minimizing the reconstruction
error β π₯, π₯$ .
• β π₯, π₯$ measures the differences between our original
input and the consequent reconstruction
L1 Loss (J) = (1/n) * Σ|y_true - y_pred|
MSE Loss(J) = (1/n) * Σ(y_true - y_pred)^2
https://www.jeremyjordan.me/
Autoencoders
The bottleneck is a key attribute of our network design. Why?
without the presence of an information bottleneck our network could
easily learn to simply memorize the input values by passing these
values along through the network.
A bottleneck constrains the amount of information that can traverse the
full network, forcing a learned compression of the input data.
In fact, if we were to construct a linear network (ie. without the use of
nonlinear activation functions at each layer) we would observe a similar
dimensionality reduction as observed in PCA.
Principal Component Analysis (PCA)
AX=λX
Autoencoders
The ideal autoencoder model balances the following:
• Sensitive to the inputs enough to accurately build a reconstruction.
• Insensitive enough to the inputs that the model doesn't simply
memorize or overfit the training data.
maintain only the variations in the data required to reconstruct the input
without holding on to redundancies within the input.
β π₯, π₯$ + ππππ’πππππ§ππ
Undercomplete Autoencoders
The simplest architecture for constructing an autoencoder
is to constrain the number of nodes, present in the hidden
layer(s) of the network, limiting the amount of information
that can flow through the network.
Ideally, this encoding will learn and describe latent
attributes of the input data.
autoencoders are capable of learning non-linear manifolds
Undercomplete Autoencoders
An undercomplete autoencoder has
no explicit regularization term.
Prevent model memorization à
ensure we have sufficiently restricted
the number of nodes in the hidden
layer(s).
Enough nodes to represent the latent
space in bottleneck layer.
Sparse Autoencoders
Sparse autoencoders offer us an alternative method for
introducing an information bottleneck without requiring a
reduction in the number of nodes at our hidden layers.
transforms the input vector into an intermediate vector,
which can be of higher, equal, or lower dimension
compared to the input
Rather, we'll construct our loss function such that we
penalize activations within a layer.
For any given observation, we'll encourage our network to
learn an encoding and decoding which only relies on
activating a small number of neurons.
It's worth noting that this is a different approach
towards regularization, as we normally regularize
the weights of a network, not the activations.
Sparse Autoencoders
L1 Regularization: We can add a term to our loss
function that penalizes the absolute value of the vector
of activations a in layer h for observation i, scaled by a
tuning parameter π .
β π₯, π₯$ + π 0 π!
"
!
KL Divergence: KL-divergence is a measure of the
difference between two probability distributions. Sparsity
parameter = p. j indicates specific neuron in a layer h.
β π₯, π₯$ + 0 πΎπΏ π 3| 6π#
#
Bernoulli’s Dist
1
π$# = 0 π! " π₯
π
!
&!
π
1−π
KL(p, 6π) =: π log + 1 − π log
π$#
1 − π$#
#$%
Denoising Autoencoders
model isn't able to simply develop a mapping which memorizes the training data because our input and target
output are no longer the same.
the model learns a vector field for mapping the input data towards a lower-dimensional manifold.
Autoencoders
extract meaningful information,
reduce data dimensionality, and
reveal intricate structures within
your datasets.
Whether it’s for anomaly
detection, feature learning, or
data denoising, autoencoders can
be a versatile asset in your
machine learning toolkit.
• An autoencoder is a neural network architecture capable of discovering structure within data in order to
develop a compressed representation of the input.
• the biggest challenge when working with autoencoders is getting your model to actually learn a meaningful
and generalizable latent space representation.
Convolutional Autoencoders
Source: https://doi.org/10.1002/hbm.26098
Representation
Learning &
Generative Model
Variational
Autoencoders
Variational Autoencoders
• A variational autoencoder (VAE) provides a probabilistic manner for
describing an observation in latent space.
• Rather than building an encoder which outputs a single value to describe
each latent state attribute.
• formulate our encoder to describe a probability distribution for each
latent attribute.
Variational Autoencoders
autoencoder model on a large dataset of faces with an encoding dimension of 6.
Variational Autoencoders
What single value would you assign for the smile attribute if you feed in a photo of the Mona Lisa?
VAE describes latent attributes in probabilistic terms.
Variational Autoencoders
For variational autoencoders, the encoder model is sometimes referred to as the recognition model whereas
the decoder model is sometimes referred to as the generative model.
Variational Autoencoders
By constructing our encoder model to output a range of possible values (a statistical distribution) from which we'll
randomly sample to feed into our decoder model, we're essentially enforcing a continuous, smooth latent space
representation.
Maths behind VAE
Details: https://arxiv.org/pdf/1907.08956
Suppose that there exists some hidden variable z which generates an observation x .
We can only see x, but we would like to infer the characteristics of z. In other words, we’d like to compute π π§|π₯ .
π π₯ |π§ π π§
π π§ |π₯ =
π π₯
But we cannot compute p(x), intractable distribution
π π₯ = @π π₯ |π§ π π§ ππ§
Let's approximate π π§|π₯ by another distribution π π§|π₯ which we'll define such that it has a tractable distribution. If
we can define the parameters of π π§|π₯ such that it is very similar to π π§|π₯ , we can use it to perform approximate
inference of the intractable distribution.
Maths behind VAE
Details: https://arxiv.org/pdf/1907.08956
KL divergence is a measure of difference between two probability distributions. Thus, if we wanted to ensure that
π π§|π₯ was similar to π π§|π₯ , we could minimize the KL divergence between the two distributions.
minπΎπΏ π π§|π₯ 3| π π§|π₯
πΈ' )|* log π π₯ |π§ − πΎπΏ π π§|π₯ |3π π§
The first term represents the reconstruction likelihood. It measures how well the latent variable π§, sampled
from the encoder distribution π π§ β£ π₯ , can reconstruct the original input π₯through the decoder π π₯ β£ π§ .
the second term ensures that our learned distribution is similar to the true prior distribution .
Maths behind VAE
Details: https://arxiv.org/pdf/1907.08956
minπΎπΏ π π§|π₯ 3| π π§|π₯
By simplifying the above minimization
problem is equivalent to the following
maximization problem :
πΈ' )|* log π π₯ |π§ − πΎπΏ π π§|π₯ |3π π§
We can further construct this model into a neural network architecture where the encoder model learns a mapping
from x to z and the decoder model learns a mapping from z back to x.
β π₯, π₯$ + 0 πΎπΏ π# π§|π₯ H | π π§
#
Closed Form for two gaussians:
Assume π π§|π₯ follows a unit
Gaussian distribution, for each
dimension j of the latent space.
Practical Implementation
Backpropagation is not possible for random sampling.
Reparameterization Trick
https://dilithjay.com/blog/the-reparameterization-trick-clearly-explained
We randomly sample π from a unit Gaussian, and then shift the randomly sampled π by the latent distribution's
mean π and scale it by the latent distribution's variance π.
In order to deal with the fact that the network may learn negative values for π , we'll typically have the network
learn log π and exponentiate this value to get the latent distribution's variance.
VAE Latent Space
In order to deal with the fact that the network may learn negative values for π , we'll typically have the network
learn log π and exponentiate this value to get the latent distribution's variance.
Takeaways VAE
1. Encoder (Understanding the Input)
The encoder takes input data like images or text and learns its key features. Instead of outputting one fixed value, it
produces two vectors for each feature:
Mean (μ): A central value representing the data.
Standard Deviation (σ): It is a measure of how much the values can vary.
These two values define a range of possibilities instead of a single number.
2. Latent Space (Adding Some Randomness)
Instead of encoding the input as one fixed point it pick a random point within the range given by the mean and
standard deviation. This randomness lets the model create slightly different versions of data which is useful for
generating new, realistic samples.
3. Decoder (Reconstructing or Creating New Data)
The decoder takes the random sample from the latent space and tries to reconstruct the original input. Since the
encoder gives a range, the decoder can produce new data that is similar but not identical to what it has seen.
Tryout now: https://colab.research.google.com/drive/1YXZGHJBKnVzq0xFLcSWhRW0rjP_-g2NE?usp=sharing
Questions?