Navigation

Introduction to AI

Machine Learning

Deep Learning

Generative AI

Tools & Frameworks

General

Generative Models - Creating New Data with AI

Generative models don’t just classify or predict - they create entirely new data. From generating images to creating text, these models represent a frontier of AI capability. This post explores how they work.

What Are Generative Models?

Discriminative Models (most of ML):

  • Learn P(y|x): Given input, predict output
  • Examples: Classification, regression
  • Answer: “Is this a cat?”

Generative Models:

  • Learn P(x): Distribution of data itself
  • Can sample new data from learned distribution
  • Can answer: “What does a cat look like?”

Key Advantage

Once you know P(x), you can:

  • Generate new samples
  • Fill in missing data
  • Understand data structure
  • Transfer learning

Autoencoder: Learning Compressed Representations

Architecture

Input → Encoder → Latent Space → Decoder → Output
        (Compress)   (Small dim)  (Expand)

Process:

  1. Encoder: Compress input to lower-dimensional representation
  2. Latent space: Small vector capturing essence
  3. Decoder: Reconstruct from latent vector

Training: Minimize reconstruction error

Example: Image Autoencoder

Original Image (28×28=784 dims) 

Encoder (784 → 100 → 50 → 20)

Latent Vector (20 dims)

Decoder (20 → 50 → 100 → 784)

Reconstructed Image (784 dims)

Loss = ||Original - Reconstructed||²

Latent Space Properties

The latent space captures data structure:

Latent Space (2D visualization):
  Female ↑
    ↑ o-o-o
    | o   o
    | o   o
    └─────→ Blonde ← → Dark Hair
  • Position in latent space encodes features
  • Interpolating between points creates in-between images

Variational Autoencoder (VAE)

Key Innovation: Latent space has structure (normal distribution)

Latent Code: Not point, but distribution (mean + variance)

Loss Function:

Loss = Reconstruction Loss + KL Divergence
       └─ How well reconstructed   └─ Force latent distribution to Normal

Benefits:

  • Smooth latent space (can interpolate)
  • Can generate by sampling from normal distribution
  • Good theoretical foundation

Generative Adversarial Networks (GANs)

Pits two networks against each other: Generator vs Discriminator

Architecture

Generator          Discriminator
Random noise           ↑
    ↓          ┌────────┴────────┐
   [G] ----→ Fake data    Real data
    ↑         (50%)        (50%)
    │              │         │
    │              └────[D]──┘
    │                   ↓
    └─────Real/Fake?──┘

Training Process

Generator Goal: Create realistic-looking fakes

Discriminator Goal: Distinguish real from fake

Adversarial Loop:

  1. Generator creates fake samples
  2. Discriminator tries to spot fakes
  3. Discriminator feedback improves Generator
  4. Generator learns to fool Discriminator

Game Theory Intuition

Perfect Balance:
- Generator: Makes perfect fakes
- Discriminator: Can't tell difference
- Outcome: Indistinguishable fake from real

GAN Variants

Conditional GAN: Generate specific class

Generator: Noise + Class → Fake Image
Discriminator: Image + Class → Real/Fake?
Result: Generate cat images, dog images, etc.

StyleGAN: Control visual properties

Input: Style code → High-level attributes
       Noise code → Fine details
Result: Generate faces with specific features

GAN Challenges

Training Instability:

  • Difficult to balance Generator vs Discriminator
  • Mode collapse: Generator only creates subset of variations
  • Non-convergence

Mitigation:

  • Spectral normalization
  • Progressive training (start small)
  • Better loss functions
  • Careful hyperparameter tuning

Diffusion Models: Latest Frontier

Generate high-quality images through iterative refinement.

Forward Process: Adding Noise

Original Image
    ↓ Add noise
Noisy Image (slight)
    ↓ Add noise
Noisier Image
    ↓ Add noise
Very Noisy Image
    ↓ Add noise
Pure Noise

Process: Gradually corrupt image until pure noise

Reverse Process: Removing Noise

Pure Noise
    ↓ Model predicts denoised version
Very Noisy Image
    ↓ Model predicts denoised version
Noisy Image
    ↓ Model predicts denoised version
Slightly Noisy Image
    ↓ Model predicts denoised version
Clean Image

Training: Learn to denoise at each step

Why Diffusion Models Work

Advantage over GANs:

  • Stable training
  • No mode collapse
  • Generate high-quality outputs

Advantage over VAEs:

  • Better image quality
  • More flexible

Transformer-Based Generation

GPT-Style Models

Approach: Predict next token based on previous tokens

Process:

Seed: "Once upon a"

Model predicts: "time"

"Once upon a time" (new seed)

Model predicts: "there"

Continue until done

Result: Creative text generation

DALL-E, Imagen

Image Generation from Text:

Text: "A dog wearing sunglasses"

Diffusion Model

Generated Image

Training:

  • Image-text pairs
  • Learn to generate images from descriptions

Comparison of Generative Models

ModelSpeedQualityStabilityControl
GANFastVery HighLowModerate
VAEFastModerateHighModerate
DiffusionSlowVery HighHighHigh
GPTModerateHighHighModerate

Applications

Image Generation

  • Art creation
  • Data augmentation
  • Product visualization

Text Generation

  • Content writing
  • Code generation
  • Dialogue systems

Audio Generation

  • Music composition
  • Speech synthesis
  • Sound effects

Video Generation

  • Predictive video
  • Special effects
  • Animation

Drug Discovery

  • Generate molecular structures
  • Optimize for desired properties

Design

  • 3D model generation
  • Architecture design
  • Fashion design

Practical Considerations

Training Data

  • Need diverse, representative samples
  • More data = better generation
  • Quality over quantity important

Computational Cost

  • Massive resources required for large models
  • Training takes weeks/months
  • Fine-tuning more accessible

Ethical Concerns

  • Deepfakes: Realistic but false content
  • Copyright: Training data may be copyrighted
  • Bias: Model captures biases in training data
  • Misuse: Generating harmful content

Quality Evaluation

Perceptual Metrics:

  • Frechet Inception Distance (FID): Compare distributions
  • Inception Score (IS): Quality and diversity
  • Human evaluation: Most reliable

The Future

Trends:

  • Multimodal models (text+image+audio)
  • More efficient training
  • Better control mechanisms
  • Real-time generation
  • Integration with other AI systems

Challenges:

  • Still computationally expensive
  • Alignment with human values
  • Reliable quality at scale
  • Understanding emergent capabilities

Conclusion

Generative models learn the underlying distribution of data and create new samples. Autoencoders compress and reconstruct. GANs pit networks against each other. Diffusion models iteratively refine noise. Transformer models generate sequentially. Each approach has trade-offs in speed, quality, and control. Together, they enable remarkable capabilities: generating realistic images, writing coherent text, composing music. Understanding generative models is crucial for modern AI, from creative applications to scientific discovery. As these models advance, they’ll continue pushing boundaries of what AI can create.