Module 5
Module 5
Architecture of Autoencoder
It compress the input data into a smaller, more manageable form by reducing its
dimensionality while preserving important information. It has three layers which
are:
Input Layer: This is where the original data enters the network. It can be
images, text features or any other structured data.
Hidden Layers: These layers perform a series of transformations on the input
data. Each hidden layer applies weights and activation functions to capture
important patterns, progressively reducing the data's size and complexity.
Output(Latent Space): The encoder outputs a compressed vector known as
the latent representation or encoding. This vector captures the important
features of the input data in a condensed form helps in filtering out noise and
redundancies.
It is the smallest layer of the network which represents the most compressed
version of the input data. It serves as the information bottleneck which force the
network to prioritize the most significant features. This compact representation
helps the model learn the underlying structure and key patterns of the input helps
in enabling better generalization and efficient data encoding.
3. Decoder
It is responsible for taking the compressed representation from the latent space
and reconstructing it back into the original data form.
Hidden Layers: These layers progressively expand the latent vector back into a
higher-dimensional space. Through successive transformations decoder
attempts to restore the original data shape and details
Output Layer: The final layer produces the reconstructed output which aims to
closely resemble the original input. The quality of reconstruction depends on
how well the encoder-decoder pair can minimize the difference between the
input and output during training.
Mean Squared Error (MSE): This is commonly used for continuous data. It
measures the average squared differences between the input and the
reconstructed data.
During training the network updates its weights using backpropagation to minimize
this reconstruction loss. By doing this it learns to extract and retain the most
important features of the input data which are encoded in the latent space.
Applications of Autoencoders
Compression of data
Even though autoencoders are meant to compress data, they are rarely employed for this
reason in practice. The following are the reasons –
Lossy compression − The Autoencoder's output is not identical to the input, but it is a near but degraded
representation. They are not the best option for lossless compression.
Data-specific − Autoencoders can only compress data identical to the data on which they were trained.
They differ from traditional data compression algorithms like jpeg or gzip in that they learn features
relevant to the provided training data. As a result, we can't anticipate a landscape photo to be compressed
by an autoencoder trained on handwritten digits.
Autoencoders are rarely used for compression because we now have more efficient and
straightforward algorithms as jpeg, LZMA, and LZSS (used in WinRAR in conjunction with
Huffman coding). Autoencoders have been used for picture denoising and dimensionality
reduction in recent years. Image denoising is used to gain accurate information about the
image's content.
Reduction of Dimensionality
The autoencoders reduce the input to a reduced representation stored in the middle layer
called code. By separating this layer from the model, the information from the input has
been compressed, and each node can now be handled as a variable. As a result, we may
determine that by deleting the decoder, an autoencoder with the coding layer as the output
can be used for dimensionality reduction.
Extraction of Features
Autoencoders' encoding segment aids in the learning of critical hidden features present in
the input data, reducing the reconstruction error. A new set of unique feature combinations
is formed during the encoding process.
Image Production
The VAE (Variational Autoencoder) is a generative model used to produce images that the
model has not yet seen. The concept is that the system will generate similar images based
on input photographs such as faces or scenery. The purpose is to:
Types of Autoencoders
Following are the different types of Autoencoders which are designed for specific
tasks with unique features:
1. Denoising Autoencoder
Denoising Autoencoder is trained to handle corrupted or noisy inputs, it learns to
remove noise and helps in reconstructing clean data. It prevent the network from
simply memorizing the input and encourages learning the core features.
2. Sparse Autoencoder
Sparse Autoencoder contains more hidden units than input features but only allows
a few neurons to be active simultaneously. This sparsity is controlled by zeroing
some hidden units, adjusting activation functions or adding a sparsity penalty to the
loss function.
3. Variational Autoencoder
Variational autoencoder (VAE) makes assumptions about the probability
distribution of the data and tries to learn a better approximation of it. It
uses stochastic gradient descent to optimize and learn the distribution of latent
variables. They used for generating new data such as creating realistic images or
text.
It assumes that the data is generated by a Directed Graphical Model and tries to
learn an approximation to qϕ(z∣x) to the conditional property
qθ(z∣x) where ϕ and θ are the parameters of the encoder and the decoder
respectively.
4. Convolutional Autoencoder
Convolutional autoencoder uses convolutional neural networks (CNNs) which
are designed for processing images. The encoder extracts features using
convolutional layers and the decoder reconstructs the image
through deconvolution also called as upsampling.
Stochastic Encoder
The word stochastic means random. So, a stochastic encoder introduces controlled
randomness in creating the compressed representation of input data. A Stochastic Encoder is a
type of encoder used in deep learning that does not produce a single fixed output for an input.
Instead, it produces a probability distribution and then samples the latent representation from
that distribution.
Function of Stochastic Encoder
When an input (image / text / audio) is given:
Formula
This step ensures the output is not fixed, but still meaningful.
3. Purpose of Stochastic Encoder
Variational AutoEncoders
Variational Autoencoders (VAEs) are type of generative model in machine learning
that create new data similar to the input they are trained on. They not only compress
and reconstruct data like traditional autoencoders but also learn a continuous
probabilistic representation of the underlying features. This unique approach helps
VAEs to generate new, realistic data samples that closely resemble the original
input. In this article, we will see more about VAEs and its core concepts.
VAE is a special kind of autoencoder that can generate new data instead of just
compressing and reconstructing it. It has three main parts:
Variational Autoencoder
Where,
Applications of VAEs
Generative modeling. The core advantage of VAEs is their ability to generate new
data samples that are similar to the training data but not identical to any specific
instance. For example, in image synthesis, VAEs can create new images that
resemble the training set but with variations, making them useful for tasks like
creating new artwork, generating realistic faces, or producing new designs in fashion
and architecture.
Anomaly detection. By learning the distribution of normal data, VAEs can identify
deviations from this distribution as anomalies. This is particularly useful in
applications like fraud detection, network security, and predictive maintenance.
Data imputation and denoising. One of VAEs' strong points is reconstructing data
with missing or noisy parts. By sampling from the learned latent distribution, they are
able to predict and fill in missing values or remove noise from corrupted data. This
makes them valuable in applications such as medical imaging, where accurate data
reconstruction is essential, or in restoring corrupted audio and visual data.
Denoising AutoEncoders(DAE)
Autoencoders are neural networks for unsupervised learning that compress input
data into a low-dimensional space (using an encoder) and then reconstruct it (using
a decoder), training the network to minimize the reconstruction error between the
original input and its reconstructed output. If the hidden layer is too large,
autoencoders may simply learn to replicate the input perfectly, functioning as an
identity mapping and failing to extract meaningful features.
Denoising autoencoders address this by providing a deliberately noisy or
corrupted version of the input to the encoder, but still using the original, clean
input for calculating loss.
This trains the model to learn useful, robust features and reduces the chance of
simply replicating the input.
Architecture of DAE
Generative Models
A generative model is a type of machine learning model that aims to learn
underlying patterns or distributions of data to generate new, similar data. This is
used in unsupervised machine learning to describe phenomena in data, enabling
computers to understand the real world. In this article, we will discuss some
applications and examples of generative models.
Generative modeling is the use of probability in artificial intelligence (AI), statistics,
and applications to create a representation or abstraction of observed phenomena
or target variables that can be computed from observations. These models are
capable of generating new data instances that are similar to your training data
Generative models aim to understand the underlying data distribution of the
training set and generate new samples from this distribution. They can learn the
joint probability distribution and can generate both input data X and target labels Y.
Generative models learn the data distribution of an input training set, to
generate new data points similar to the initial training set. It means that these
models can understand and replicate the nuances of your data. From image
generation to natural language understanding and synthesis, this Generative
Model has a wide range of applications and is the basis of the latest generation of
AI systems powered by large language models (LLMs).
Artificial intelligence (AI) is rapidly transforming our world, and its importance is
undeniable. Generative models are a cornerstone of modern artificial intelligence
(AI), providing essential capabilities that drive innovation and expand the
boundaries of what AI systems can achieve. Their importance in AI stems from
their ability to model complex data distributions, generate new data, and enable a
wide range of applications that would otherwise be challenging or impossible.
Generative models are a class of models in machine learning that aim to model the
underlying distribution of data in order to generate new samples from that
distribution. Here are some common types of generative models:
1. Probabilistic Models:
Probabilistic models use probability distributions to represent the data. They aim to
estimate the joint probability of the observed data and the latent variables. Two
notable examples of probabilistic models are Bayesian Networks and Hidden
Markov Models.
Bayesian Network: Bayesian Network is a graphical representation of the
various possible relationships between a given set of random variables. is a
classifier that has no dependence on features i.e. it is condition-independent
They are used to model uncertainty in complex domains by encoding
probabilistic relationships among variables. These networks are particularly
effective in scenarios where we need to understand causal relationships and
make decisions under uncertainty.
Hidden Markov Models (HMM): Hidden Markov Models are statistical models
that represent systems that transition between states in a Markov process,
where the system's state is partially observable through a set of observations. It
is predicated on the idea that there is an underlying process with hidden states,
each of which has a known outcome. The probabilities of switching between
hidden states and emitting observable symbols are defined by the model.
Apart from the mainstream generative models, there are also some other types of
models available that provide unique approaches to data generation.
Flow-Based Models: Flow-based models utilize invertible neural networks to
learn the exact likelihood of data. These models, such as RealNVP and Glow,
allow for both efficient sampling and exact log-likelihood computation.
Energy-Based Models: Energy-based models define a scalar energy function
that assigns low energy to data points that resemble the training data and high
energy to unlikely data points. These models, including Boltzmann Machines
and their variants, focus on learning the energy landscape of the data
distribution.
Generative models have a wide range of applications across various fields. Here's
a breakdown of some of the key areas :
1. Image Generation
Generative Adversarial Networks (GANs), have revolutionized image
generation. GANs can produce highly realistic images that are often
indistinguishable from real photographs. Basically, it takes a Prompt from the
User to analyze the meaning of the query and pass it forward to creating an
image. These models are used in various applications, including creating
synthetic faces, landscapes, and objects for media, entertainment, and virtual
reality environments.
Image-to-image translation involves converting images from one domain to
another, such as transforming sketches into photorealistic images or converting
daytime photos into nighttime scenes.
Examples models: Stable Diffusion, Midjourney,OpenAI DALL-E
2. Text Generation
Generative models play a crucial role in natural language processing (NLP),
enabling machines to understand and generate human-like text. There are
some hugging face models such as Mistral 7b and LLama 2 7b that are used in
Natural Language Processing.
Text Completion and Summarization: Text generation models are adept at
completing sentences or paragraphs based on a given prompt. They are also
used for text summarization, where they condense long documents into concise
summaries while preserving the original meaning.
Examples models: Google PaLM, Meta LLaMA,OpenAI GPT-4, Mistral, Zephyr
4. Data Augmentation
Enhancing Training Dataset: Generative models are used to augment training
datasets, especially in scenarios where obtaining large amounts of labeled data
is challenging. By generating synthetic data that resembles real-world samples,
these models improve the performance of machine learning algorithm.
Creating synthetic data: Model can create entirely synthetic datasets that
simulate real-world distributions. This capability is critical for tasks that require
privacy-preserving data, such as in healthcare and finance, where synthetic
data can be used to train models without revealing sensitive information.
Examples models: StyleGAN
5. Healthcare Applications
Generative models are transforming medical image analysis by enhancing and
generating medical images. It can be used to analyze medical images like X-
rays or MRIs, potentially aiding in early disease detection or treatment planning.
These applications assist in disease diagnosis, treatment planning, and medical
research.
In drug discovery, models are used to design new molecules with desired
properties. Models like Variational Autoencoders (VAEs) and GANs help in
exploring the vast chemical space, predicting molecular properties, and
generating novel compounds.
While generative models offer a wide range of capabilities, they also face several
challenges:
Computational complexity of training: Generative models, especially sophisticated
models such as GANs, require significant computational resources and time. Training
them requires powerful hardware and can be resource-intensive.
Quality of output generated: Output generated from generative models may not
always be accurate or error-free. This can be due to a number of factors, including
insufficient data, insufficient training, or overly complex models
Security: Generative AI systems can be used to fake information or propaganda by
creating realistic and believable fake videos, images and text
Trustworthy Concern The ability of generative models to generate realistic
content raises ethical issues, especially in the creation of deep imitation or fake
content. Ensuring responsible use is paramount to prevent abuse or fraud.
Data dependencies: The quality of the output generated depends heavily on the
quality of the training data. If the training data is biased or unrepresentative, the
model output will reflect those biases.
Boltzmann machine
These machines are not deterministic deep learning models, they are stochastic
or generative deep learning models. They are representations of a system.
Visible nodes: These are nodes that can be measured and are measured.
Hidden nodes: These are nodes that cannot be measured or are not measured.
a Boltzmann machine can be called a stochastic Hopfield network which has hidden
units. It has a network of units with an ‘energy’ defined for the overall network.
The Boltzmann machine is named after Ludwig Boltzmann, an Austrian scientist who
came up with the Boltzmann distribution. However, this type of network was first
developed by Geoff Hinton, a Stanford Scientist.
Boltzmann machine
Boltzmann distribution
It was formulated by Ludwig Boltzmann in 1868 and is also known as the Gibbs
distribution.
Uses of Boltzmann Machines
The main aim of a Boltzmann machine is to optimize the solution of a problem. To do
this, it optimizes the weights and quantities related to the specific problem that is
assigned to it. This technique is employed when the main aim is to create mapping and
to learn from the attributes and target variables in the data. If you seek to identify an
underlying structure or the pattern within the data, unsupervised learning methods for
this model are regarded to be more useful. Some of the most widely used unsupervised
learning methods are clustering, dimensionality reduction, anomaly detection and
creating generative models.
All of these techniques have a different objective of detecting patterns like identifying
latent grouping, finding irregularities in the data, or even generating new samples from
the data that is available. You can even stack these networks in layers to build deep
neural networks that capture highly complicated statistics. Restricted Boltzmann
machines are widely used in the domain of imaging and image processing as well
because they have the ability to model continuous data that are common to natural
images. They are even used to solve complicated quantum mechanical many-particle
problems or classical statistical physics problems like the Ising and Potts classes of
models.
A major difference is that unlike other traditional networks (A/C/R) which don’t have any
connections between the input nodes, Boltzmann Machines have connections among
the input nodes. Every node is connected to all other nodes irrespective of whether they
are input or hidden nodes. This enables them to share information among themselves
and self-generate subsequent data. You’d only measure what’s on the visible nodes
and not what’s on the hidden nodes. After the input is provided, the Boltzmann
machines are able to capture all the parameters, patterns and correlations among the
data. It is because of this that they are known as deep generative models and they fall
into the class of Unsupervised Deep Learning.
While in a full Boltzmann machine all the nodes are connected to each other and the
connections grow exponentially, an RBM has certain restrictions with respect to node
connections.
In a Restricted Boltzmann Machine, hidden nodes cannot be connected to each other
while visible nodes are connected to each other.
In a Deep Belief Network, you could say that multiple Restricted Boltzmann Machines
are stacked, such that the outputs of the first RBM are the inputs of the subsequent
RBM. The connections within individual layers are undirected, while the connections
between layers are directed. However, there is an exception here. The connection
between the top two layers is undirected.
A deep belief network can either be trained using a Greedy Layer-wise Training
Algorithm or a Wake-Sleep Algorithm.
Deep Boltzmann Machines are very similar to Deep Belief Networks. The difference
between these two types of Boltzmann machines is that while connections between
layers in DBNs are directed, in DBMs, the connections within layers, as well as the
connections between the layers, are all undirected.
DBNs, with their deep architecture and efficient learning capabilities, have been pivotal
in advancing the field of deep learning, particularly in handling complex tasks like image
and speech recognition.
GAN consist of two main models that work together to create realistic synthetic data
which are as follows:
1. Generator Model
The generator is a deep neural network that takes random noise as input to
generate realistic data samples like images or text. It learns the underlying data
patterns by adjusting its internal parameters during training
through backpropagation. Its objective is to produce samples that the discriminator
classifies as real.
where
JG measure how well the generator is fooling the discriminator.
G(zi) is the generated sample from random noise zi
D(G(zi)) is the discriminator’s estimated probability that the generated sample is
real.
The generator aims to maximize D(G(zi)) meaning it wants the discriminator to
classify its fake data as real (probability close to 1).
2. Discriminator Model
The discriminator acts as a binary classifier helps in distinguishing between real and
generated data. It learns to improve its classification ability through training, refining
its parameters to detect fake samples more accurately. When dealing with image
data, the discriminator uses convolutional layers or other relevant architectures
which help to extract features and enhance the model’s ability.
Discriminator Loss Function: The discriminator tries to minimize this loss:
JD measures how well the discriminator classifies real and fake samples.
xi is a real data sample.
G(zi) is a fake sample from the generator.
D(xi) is the discriminator’s probability that xi is real.
D(G(zi)) is the discriminator’s probability that the fake sample is real.
The discriminator wants to correctly classify real data as real (maximize
logD(xi) and fake data as fake (maximize log(1−D(G(zi)))
MinMax Loss
GANs are trained using a MinMax Loss between the generator and discriminator:
where,
The generator tries to minimize this loss (to fool the discriminator) and the
discriminator tries to maximize it (to detect fakes accurately).
GAN
Working of GAN
GAN train by having two networks the Generator (G) and the Discriminator (D)
compete and improve together. Here's the step-by-step process
The generator starts with a random noise vector like random numbers. It uses this
noise as a starting point to create a fake data sample such as a generated image.
The generator’s internal layers transform this noise into something that looks like
real data.
2. Discriminator's Turn
3. Adversarial Learning
If the discriminator correctly classifies real and fake data it gets better at its job.
If the generator fools the discriminator by creating realistic fake data, it receives a
positive update and the discriminator is penalized for making a wrong decision.
4. Generator's Improvement
Each time the discriminator mistakes fake data for real, the generator learns from
this success.
Through many iterations, the generator improves and creates more convincing
fake samples.
5. Discriminator's Adaptation
The discriminator also learns continuously by updating itself to better spot fake
data.
This constant back-and-forth makes both networks stronger over time.
6. Training Progression
As training continues, the generator becomes highly proficient at producing
realistic data.
Eventually the discriminator struggles to distinguish real from fake shows that the
GAN has reached a well-trained state.
At this point, the generator can produce high-quality synthetic data that can be
used for different applications.
Types of GAN
There are several types of GANs each designed for different purposes. Here are
some important types:
1. Vanilla GAN
Deep Convolutional GAN (DCGAN) are among the most popular types of GANs
used for image generation.
They are important because they:
Uses Convolutional Neural Networks (CNNs) instead of simple multi-layer
perceptrons (MLPs).
Max pooling layers are replaced with convolutional stride helps in making the
model more efficient.
Fully connected layers are removed, which allows for better spatial understanding
of images.
DCGANs are successful because they generate high-quality, realistic images.