Generative Models: GANs and VAEs Explained
Generative Models: GANs and VAEs Explained
Generative Models
(Unsupervised learning)
-GAN
-VAE
-Diffusion Models
GAN original paper: Goodfellow, I. J., Pouget-Abadie, J., Mirza, M., Xu, B., Warde-Farley, D., Ozair, S., ... &
Bengio, Y. (2014). Generative adversarial nets. Advances in neural information processing systems, 27.
VAE original paper: Davidson, T. R., Falorsi, L., De Cao, N., Kipf, T., & Tomczak, J. M. (2018). Hyperspherical
variational auto-encoders. arXiv preprint arXiv:1804.00891.
Kingma, D. P., & Welling, M. (2013). Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114.
DDPM/Diffusion Models original paper: Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic
models. Advances in neural information processing systems, 33, 6840-6851.
1
16-08-2025
GAN
• GAN was introduced by Ian Goodfellow and his team in 2014 and they have transformed
how computers generate images, videos, music and more.
• Unlike traditional models that only recognize or classify data, they take a creative way by
generating entirely new content that closely resembles real-world data.
• A GAN is called adversarial because it trains two different networks which compete against
each other to generate more authentic new data from a given training dataset.
• One network generates new data by taking an input data sample and modifying it as much
as possible.
• The other network tries to predict whether the generated data output belongs in the
original dataset.
• In other words, the predicting network determines whether the generated data is fake or
real.
• The system generates newer, improved versions of fake data values until the predicting
network can no longer distinguish fake from original.
2
16-08-2025
Bayesian classifier
• A Bayesian classifier such as Naive Bayes is a type of generative model that
learns the joint probability distribution P(X,Y) over the input data X and
class labels Y
• From prob distribu on X → Y or features → class_label, make predictions
P(Y ∣ X).
• It estimates how likely it is to see each data point X given a
class Y (i.e., P(X∣Y)), and the overall chance of each class P(Y).
• Using Bayes' theorem, it computes the conditional probability P(Y∣X) for
classification tasks.
• Informally, this can be viewed as
posteriori = likelihood * prior/evidence
3
16-08-2025
• P(X|yes)·P(yes) =
P(rain|yes)·P(hot|yes)·P(high|yes)·P(weak|yes)·P(yes) =
3/9·2/9·3/9·6/9·9/14 = 0.010582
• P(X|no)·P(no) =
P(rain|no)·P(hot|no)·P(high|no)·P(weak|no)·P(no) =
2/5·2/5·4/5·2/5·5/14 = 0.018286
4
16-08-2025
Generative models
5
16-08-2025
6
16-08-2025
• This method is used for playing games in which there are 2 players taking
turns to play moves.
• MiniMax game tree are best suited for games in which both players can see
the entire game situation.
• The strategy behind MiniMax Algorithm is that it assumes that both player
will play to the best of their ability.
• Works for Zero-sum, perfect information games.
7
16-08-2025
GAN Architecture
8
16-08-2025
9
16-08-2025
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.
• 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.
where
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 about the fake sample is fake.
10
16-08-2025
11
16-08-2025
Log Loss=-log(0.2)
=1.609
12
16-08-2025
MinMax Loss
• Here the term ‘x’ represents the real data i.e. train set from the domain
• Term D(x) represents prediction of Discriminator; whether ‘x’ is real or
fake;
returns a value between 0 to 1, a value near zero indicating input is fake,
a value near 1 indicates input is real
• G(z) represents the generated output
• Term D(G(z)) represents Discriminator’s output on Generator’s fake sample
i.e. what class Discriminator assigned to G(z)
The goal of Generator model is to minimize this function.
The goal of Discriminator model is to maximize this function.
The first part of formula tells how good the Discriminator is
The second part of equation tells how good the Generator is
Visualizing Loss
13
16-08-2025
14
16-08-2025
An illustration of progress in GAN capabilities over the course of approximately three years following the introduction of
GANs. GANs have rapidly become more capable, due to changes in GAN algorithms, improvements to the underlying
deep learning algorithms, and improvements to underlying deep learning software and hardware infrastructure.
This rapid progress means that it is infeasible for any single document to summarize the state-of-the-art GAN
capabilities or any specific set of best practices; both continue to evolve rapidly enough that any comprehensive survey
quickly becomes out of date.
Source: Karras, T., Aila, T., Laine, S., Lehtinen, J. Progressive growing of GANs for improved quality, stability, and variation.
CoRR, abs/1710.10196 (2017).
Output of GAN
This image is a sample from a GAN depicting a person who does not exist but was “imagined” by a GAN
after training on photos of celebrities.
15
16-08-2025
Autoencoders
Autoencoder architecture
16
16-08-2025
Unsupervised Autoencoder
• An autoencoder is a type of artificial neural network architecture designed
for learning compact and meaningful representations of input data.
• Its structure consists of two primary components: the encoder and
the decoder.
• During training, the autoencoder minimizes the mean square difference
between the input and its reconstruction at output layer; to optimize the
weights and biases in the network.
Unsupervised Autoencoder
• This learned representation captures essential features and structures
present in the dataset, facilitating subsequent tasks like dimensionality
reduction, denoising, anomaly detection, or feature extraction.
• There’s no need of labelled data for training an autoencoder.
• The training patterns are arranged as Input-Output pair, with output
vector being same as input vector.
• This kind of setting makes it suitable for unsupervised learning though it
uses Backpropagation similar to supervised learning.
17
16-08-2025
Error-backpropagation Training
• In a typical autoencoder setup, the input and output pair shares identical
values since the primary goal of the autoencoder is to learn a condensed
yet representative encoding of the input itself.
• Thus, the output reconstructed by the decoder must closely match the
original input in terms of values.
Training Loss
• An autoencoder trains by minimizing the difference between its
input and the reconstructed output using backpropagation and
stochastic gradient descent or any equivalent optimization
strategy.
Initially, random weights are assigned to the network. Then, the input
passes through the encoder, producing a lower-dimensional latent
space representation, or code.
Subsequently, the decoder regenerates the original input from this
code.
18
16-08-2025
Training Loss
• Throughout the training phase, the network iteratively adjusts its weights
and biases to reduce the discrepancy between the actual input and the
decoded output.
Autoencoder uses
• A trained autoencoder captures essential features and structures
present in the dataset, facilitating subsequent tasks like dimensionality
reduction, denoising, anomaly detection, or feature extraction.
19
16-08-2025
20
16-08-2025
Autoencoder summary
• Autoencoders are a powerful tool for anomaly detection, particularly
when dealing with unlabeled data.
• By effectively training the autoencoder and setting appropriate
thresholds, one can gain valuable insights into anomalies within your
data.
• They are well-suited for detecting point anomalies (data points deviating
from the norm).
• For context-based anomalies (anomalies dependent on surrounding data
points or time series data), one needs to explore other techniques such
as Variational autoencoders (VAEs), Transformer, etc.
21
16-08-2025
Variational Autoencoder
Learns a hidden representation of input
Also Learns to generate new data
Minimize reconstruction loss + latent loss
Latent vectors are sampled from Gaussian Mixture
22
16-08-2025
VAE KL Divergence
• Minimizing the KL divergence between the learned
distribution of latent variables and a simple Gaussian
distribution whose values range from 0 to 1 forces the
learned encoding of latent variables to follow a normal
distribution.
• This allows for smooth interpolation of any point in latent
space, and thereby the generation of new images.
23
16-08-2025
Diffusion Models
Denoising diffusion probabilistic
models (DDPM)
Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic
models. Advances in neural information processing systems, 33, 6840-6851.
24
16-08-2025
Output of DDPM
Source: Original
Paper
2006.11239
It’s used by
commercial s/w
DALL-E for image
generation.
Diffusion models
• The intuition behind diffusion models is inspired by physics,
treating pixels like the molecules of a drop of ink spreading
out in a glass of water over time.
• Much like how the random movement of the ink molecules
will eventually lead to their even dispersal in the glass, the
random introduction of noise into an image will eventually
result in what looks like TV static.
• By modeling that diffusion process, then somehow learning
to reverse it, an artificial intelligence model can generate new
images by simply “denoising” samples of random noise.
25
16-08-2025
• They are particularly known for their ability to generate high-quality images
and other data types.
Diffusion models
• Forward Diffusion:
The model starts with real data (like an image) and progressively
adds random noise until it becomes pure noise.
This is like gradually blurring an image until it's just random pixels.
• Reverse Diffusion:
The model learns to reverse this process with a neural network,
starting from pure noise and gradually removing the noise to
reconstruct the original data or generate new data.
starting from a blurry image and gradually sharpening it.
26
16-08-2025
Averaging/Low-pass filters
• Smoothing filters are used for blurring and for noise reduction.
• Blurring/averaging is used in pre-processing tasks, such as removal of small details from
an image prior to large object extraction, and bridging of small gaps in lines or curves.
• Note that the sum of all elements of this matrix is 1.0. This is important. If the sum is
not exactly one, the resultant image will be brighter or darker.
27
16-08-2025
90 90 90 0 0 0 *
1/9 1/9 1/9 = ?
90 90 90 0 0 0
1/9 1/9 1/9
90 90 90 0 0 0
90 90 90 0 0 0
• Convolution operation with padding=‘same’ option results in an output image of size same
as input.
• In diffusion model, Gaussian noise is added in a controlled manner using Markov Chain
method.
28
16-08-2025
Result of smoothing
with square
averaging filter
masks of varying
sizes
29
16-08-2025
30
16-08-2025
Gaussian Filter
• The averaging filter that we introduced earlier replaces each pixel with
the average gray value of its neighbours.
• This means that nearby pixels all play an equal role in the average, and
more distant pixels play no role.
• It is more appealing to use the Gaussian to replace each pixel with a
weighted average of its neighbors.
• In this way, the nearest pixels influence the average more, and more
distant pixels play a smaller and smaller role.
• This is more elegant, because we have a smooth and continuous drop-
off in the influence of pixels on the result, instead of a sudden,
discontinuous change.
Gaussian Filter
• In order to build a discrete filter that looks like a Gaussian: is
done by evaluating the Gaussian function values at discrete
locations.
31
16-08-2025
Gaussian filter
• Example of a Gaussian filter and its effect on image
32
16-08-2025
• The shaded portions are a portion of an intermediate tensor as well as the input and
kernel tensor elements used for the computation.
• In Transposed Conv, decreasing padding will increase the output feature map size.
O=(I−1) × S + K−2P
33
16-08-2025
34
16-08-2025
Original authors:
To represent the reverse process, authors used a U-Net backbone similar
to an unmasked PixelCNN++ with group normalization throughout.
Parameters are shared across time, which is specified to the network
using the Transformer sinusoidal position embedding.
They used self-attention at the 16 X 16 feature map resolution.
35
16-08-2025
Commercial use of DM
• Diffusion models are among the neural network architectures
at the forefront of generative AI, most notably represented
by popular text-to-image models including Stability AI’s
Stable Diffusion, OpenAI’s DALL-E (beginning with DALL-E-2),
Midjourney and Google’s Imagen.
• They improve upon the performance and stability of
other machine learning architectures used for image
synthesis such as variational autoencoders (VAEs), generative
adversarial networks (GANs) and autoregressive models such
as PixelCNN.
36
16-08-2025
37