Generative Vision: GANs & VAEs

latent variable

A latent variable is a hidden "control knob" the model uses to generate data, even though it is never directly observed in the dataset. The intuition: a face image is the visible end-product of many invisible factors — pose, lighting, identity, expression, hair. We never get those factors handed to us as labels, but we can posit a compact vector z that stands in for them and let the network learn to turn z into an image. The latent variable is that compact hidden cause.

Precisely, in a latent-variable generative model we factor the data distribution as p(x) equal to the integral over z of p(x|z) p(z), where z lives in a low-dimensional latent space with a chosen prior p(z) (commonly a standard Gaussian, so z is just a vector of independent unit-variance numbers). The decoder p(x|z) turns a code into an image; the prior says which codes are a priori likely. Sampling is two-step: draw z from p(z), then x from p(x|z). The latent space is the geometry of all possible codes, and proximity within it ideally corresponds to similarity among generated images.

A central question is what each latent dimension means. In an ideal disentangled latent space, separate coordinates control separate human-interpretable factors — one for pose, one for smile, one for hair length — so moving along a single axis changes one thing. In practice axes are usually entangled, but meaningful directions still exist and can be found after training: latent interpolation morphs smoothly, and latent arithmetic such as "smiling woman − neutral woman + neutral man ≈ smiling man" works in well-trained spaces (as popularized by word2vec analogies and DCGAN). StyleGAN's intermediate W space is famous for being more disentangled than the input Gaussian Z space.

"Latent" just means inferred or hidden, not magical — the dimensions are whatever the training objective and architecture happen to encode, and they need not align with human concepts unless you design for it (β-VAE, supervised factors, InfoGAN). Beware reading too much meaning into a single coordinate.

Also called
latent codehidden variablez潛在編碼