module 03
module 03
Definition:
An autoencoder is a type of neural network used for unsupervised learning, primarily for
dimensionality reduction, feature extraction, and data reconstruction. It learns to encode
input data into a compressed representation (encoding) and then reconstruct the original data
(decoding).
Autoencoders are a special type of unsupervised feedforward neural network (no labels
needed!). The main application of Autoencoders is to accurately capture the key aspects of
the provided data to provide a compressed version of the input data, generate realistic
synthetic data, or flag anomalies.
Autoencoders are composed of 2 key fully connected feedforward neural networks (Figure
1):
• Encoder: compresses the input data to remove any form of noise and generates a
latent space/bottleneck. Therefore, the output neural network dimensions are smaller
than the input and can be adjusted as a hyperparameter in order to decide how much
lossy our compression should be.
• Decoder: making use of only the compressed data representation from the latent space,
tries to reconstruct with as much fidelity as possible the original input data (the
architecture of this neural network is, therefore, generally a mirror image of the
encoder). The “goodness” of the prediction can then be measured by calculating the
reconstruction error between the input and output data using a loss function.
Repeating iteratively this process of passing data through the encoder and decoder and
measuring the error to tune the parameters through backpropagation, the Autoencoder can,
with time, correctly work with extremely difficult forms of data. Following shows the
Autoencoder Architecture
Some of the most common hyperparameters that can be tuned when optimizing your
Autoencoder are:
• The number of layers for the Encoder and Decoder neural networks
• The number of nodes for each of these layers
• The loss function to use for the optimization process (e.g., binary cross-entropy or
mean squared error)
• The size of the latent space (the smaller, the higher the compression, acting, therefore
as a regularization mechanism)
Finally, Autoencoders can be designed to work with different types of data, such as tabular,
time-series, or image data, and can, therefore, be designed to use a variety of layers, such
as convolutional layers, for image analysis.
• Main Properties:
o Linear autoencoders perform similar to Principal Component Analysis (PCA),
Latent Space Smaller than the input Larger than the input data
Dimensions data dimension dimension (higher capacity)
4. Variants of Autoencoders
1. Denoising Autoencoders (DAEs)
Overview: Denoising Autoencoders are a variant of autoencoders designed to reconstruct
data that has been corrupted or noised. The objective is to learn robust features by training the
model to recover the original data from noisy or incomplete inputs.
How Denoising Autoencoders Work:
• Corruption Process: During training, the input data is corrupted by adding noise (e.g.,
Gaussian noise, random pixel dropout for images). This corruption can be in the form
of missing values or pixel distortions.
• Objective: The autoencoder is trained to reconstruct the original, clean data from the
corrupted version.
Applications:
• Image Denoising: Removing noise from corrupted images.
• Data Preprocessing: Helps to learn invariant features that generalize well across
different types of noise.
2. Sparse Autoencoders
Overview: Sparse Autoencoders are autoencoders that enforce sparsity in the hidden layer’s
activations. Sparsity means that only a small number of neurons in the hidden layer are active
at any given time, encouraging the network to learn more efficient and meaningful features.
Applications:
• Feature Learning: Encourages the model to learn efficient features by forcing it to
focus on a small set of active neurons.
• Anomaly Detection: By limiting the number of active features, sparse autoencoders
can detect outliers or anomalies in the data.
• Compression: The sparse representation reduces the dimensionality of the data
effectively.
3. Contractive Autoencoders (CAE)
Overview: Contractive Autoencoders are designed to learn more robust features by enforcing
a local contractivity constraint. This means the encoder learns to create representations that
are less sensitive to small changes in the input data, making the learned features more stable.
Applications:
• Robust Feature Learning: Helps in learning features that are insensitive to small
perturbations in data.
• Data Augmentation: Can be used for tasks where the model needs to generalize well
even when input data is noisy or slightly altered.
• Improved Generalization: Helps with generalizing to new, unseen data by
discouraging overfitting.
4. Deep Autoencoders
Overview: Deep Autoencoders are multi-layered neural networks, which consist of deep
encoder and decoder networks. The primary difference between shallow autoencoders (with
one hidden layer) and deep autoencoders is the depth of the network, which allows deep
autoencoders to learn more complex features and hierarchies in the data. How Deep
Autoencoders Work:
• Multi-Layer Architecture: The encoder and decoder consist of multiple hidden layers.
This deep architecture allows the model to learn hierarchical representations of data. For
example:
• Encoder: The encoder learns successive compressed representations of the input by
passing it through several layers of nonlinear activations.
• Decoder: Similarly, the decoder reconstructs the data by progressively expanding the
latent representation back to the original data space.
Applications:
• Feature Hierarchies: Deep autoencoders can learn complex hierarchical features,
which is useful for image and speech recognition.
• Data Preprocessing: Deep autoencoders can be used for tasks like data compression,
feature extraction, or denoising at a deeper level of abstraction.
Challenges:
• Training Deep Networks: Training deep autoencoders is more difficult than shallow
ones due to issues like vanishing gradients. Techniques like pretraining or using
modern optimizers (Adam, RMSprop) can help alleviate these problems.
plt.show()
The reconstructed images maintain the basic shape and outline of the original
handwritten digits.
The numbers are still clearly recognizable, meaning the encoder effectively compressed
important information.
2️⃣Slight Blurring & Loss of Fine Details
The reconstructed digits are slightly blurred, especially at the edges. Some small strokes
or tiny details are missing, as the encoder only retains key patterns in 32 dimensions.
✔ Some digits (e.g., 0, 1, 7) are reconstructed more clearly because they have
simpler shapes.
Digits with complex strokes (e.g., 8, 5, 3) lose finer details, making them harder to
recognize.
4️⃣Compression Effect
https://colab.research.google.com/drive/1gCJqMX6bcoYy7r0Oa_c6kOjIOBmzMofi?usp=sha
ring