Skip to 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.

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

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:

Terminal window
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.

Tiny decoder run result map

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

Keep one generation review note:

Latent Shape
what compact code enters the generator/decoder
Output Shape
what sample-like object comes out
Quality Check
does it look plausible or reconstruct well?
Diversity Check
are outputs varied, or collapsing?
Trust Rule
generated output always needs review

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.

Check reasoning and explanation
  1. A passing answer connects tensors, model layers, loss, backward(), and optimizer updates into one training loop.
  2. The evidence should include a runnable mini experiment, tensor-shape checks, and a loss or validation curve you can explain.
  3. A good self-check names one failure mode such as shape mismatch, no loss decrease, overfitting, data leakage, or using Attention/Transformer words without explaining the data flow.