Skip to main content

6.6.1 Generative Models Roadmap: Sample, Decode, Review

Generative models create new samples instead of only predicting labels. The practical loop is: sample a latent code, decode it, review the output, and compare versions.

Look at the Generation Flow First

Generative models chapter relationship diagram

GAN adversarial balance map

ConceptFirst meaning
latent vectorcompact hidden input used for generation
decoder / generatorturns latent code into an output
discriminatorjudges real vs generated in GANs
VAElearns a smoother latent space
reviewgenerated output still needs human and metric checks

Run One Tiny Decoder

Create generative_first_loop.py and run it after installing torch.

import torch

torch.manual_seed(0)
latent = torch.randn(2, 4)
decoder = torch.nn.Sequential(torch.nn.Linear(4, 6), torch.nn.Tanh())
generated = decoder(latent)

print("latent_shape:", tuple(latent.shape))
print("generated_shape:", tuple(generated.shape))
print("value_range:", round(generated.min().item(), 3), round(generated.max().item(), 3))

Expected output:

latent_shape: (2, 4)
generated_shape: (2, 6)
value_range: -0.863 0.695

This is not a real generator yet. It shows the core shape idea: small latent vectors can be decoded into larger outputs.

Learn in This Order

OrderReadWhat to focus on
16.6.2 GANgenerator, discriminator, adversarial balance
26.6.3 VAEencoder, decoder, latent space

Pass Check

You pass this roadmap when you can explain the difference between predicting a label and generating a sample, and describe why generated outputs need review rather than blind trust.