Foundations to Frontier
Tests
H. Generative Models › H4 Generative Adversarial Networks

InfoGAN: interpretable latent codes

InfoGAN (Chen et al., NeurIPS 2016) splits the generator's input into unstructured noise z and a small latent code c, such as one 10-way categorical variable and two continuous ones. It adds a term that rewards high mutual information between c and the generated sample. Mutual information is intractable, so InfoGAN maximises a variational lower bound L_I = H(c) + E log Q(c | x), where Q is an extra head on the discriminator that tries to read the code back from the image. Without labels, the categorical code on MNIST learned the digit classes with about 5% error, and the continuous codes learned rotation and stroke width. The extra head costs almost nothing. This page derives the lower bound, explains the shared Q network and the choice of λ, and discusses what 'disentanglement' can and cannot mean (Locatello et al. 2019). In the exercises you compute L_I, Gaussian code likelihoods, purity and mutual information. You then train an InfoGAN (λ = 1) and the same network with λ = 0 on a ring of 8 Gaussians with an 8-way code. With the information term, every code value took over exactly one mode on all three seeds (NMI 1.0, L_I = 2.078 of log 8 = 2.079). It also covered all 8 modes with 89–97% of samples on a mode. Without it, NMI was 0.46–0.77 and only 6–7 modes were covered.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A dial with a meaning

A GAN’s noise input is a jumble: changing one number usually changes the output in some unpredictable mix of ways. InfoGAN reserves a few inputs as ‘dials’ and adds a referee that, looking only at the generated sample, must guess how the dials were set. If the referee can guess correctly, each dial must control something visible and consistent, such as which digit is drawn or how thick the strokes are. No labels are needed: the GAN finds the meanings itself. The demo shows how much information a dial with k settings can carry, and how much of it the referee captures at a given accuracy.

GAN lab
A 8-way code carries H(c) = log 8 = 2.079 nats. With Q giving 0.9 to the right code the lower bound L_I is 1.560 (75% of H(c)).
Why engineers care

Codes that control one factor at a time are useful for synthetic data: vary only sensor angle, only illumination or only target class while keeping everything else fixed. In practice the factors InfoGAN finds are not guaranteed to be the ones you want, so check them.

📝 Quick check (Level 0)
0/3 answered
  1. 1. InfoGAN adds to the generator input…
  2. 2. The extra network Q tries to…
  3. 3. InfoGAN needs labels?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Objective. min over G, Q of max over D of V(D, G) − λ L_I(G, Q), where V is the usual GAN value.
  • Lower bound (Barber and Agakov 2003). I(c; G(z, c)) = H(c) − H(c | x) ≥ H(c) + E over c, z of log Q(c | G(z, c)) = L_I, for any distribution Q(c | x); the gap is E over x of KL(P(c|x) ‖ Q(c|x)).
  • Codes. Categorical c ~ Cat(K = 10, p = 0.1): Q outputs a softmax and the term is a cross-entropy. Continuous c ~ U(−1, 1): Q outputs a factorised Gaussian (mean and log standard deviation) and the term is a Gaussian log-likelihood.
  • Architecture. Q shares all convolutional layers with D and adds one fully connected layer: negligible cost.
  • λ. λ = 1 for discrete codes; smaller for continuous codes, so that their log-likelihood term stays on the same scale as the GAN loss.
  • Results. MNIST: the categorical code captured digit type (about 5% error without labels), continuous codes captured rotation and width and extrapolated beyond [−1, 1]. Also pose and lighting on 3D faces and chairs, hairstyles and glasses on CelebA.
  • Limits. Locatello et al. (ICML 2019) proved that unsupervised disentanglement is impossible without inductive biases and found that results vary more with seeds and hyperparameters than with the method. InfoGAN’s factors depend on architecture and data.
📝 Quick check (Level 1)
0/3 answered
  1. 1. L_I is a lower bound on…
  2. 2. For a categorical code the L_I term is…
  3. 3. Q shares its layers with…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Bounds, codes and purity

Exercise 1.

  • The entropy of a uniform categorical code.
  • The variational lower bound L_I from Q’s predicted probabilities.
  • The negative log-likelihood of continuous codes under a factorised Gaussian Q.
  • Purity: how consistently each code value maps to a single cluster.

Practice.

  • Start small: one categorical code with as many values as the factor you hope to find, plus 1–3 continuous codes.
  • Monitor L_I: it should approach H(c) quickly for categorical codes; if it does not, Q is too weak or λ too small.
  • Inspect traversals: vary one code with z fixed and look at the samples; check several seeds, since meanings change between runs.
  • Label a few samples to name the learned factors, or use weak supervision when a specific factor is needed.
  • For controllable generation today conditional models (H4.3), StyleGAN’s latent directions (H4.11) or diffusion guidance are usually more reliable.
import torch, torch.nn.functional as F
c = torch.randint(0, 10, (B,)); u = torch.rand(B, 2) * 2 - 1
x = G(torch.cat([torch.randn(B, 62), F.one_hot(c, 10).float(), u], 1))
h = D_trunk(x); logit = D_head(h); q_cat, q_mu, q_logsd = Q_head(h)
info = F.cross_entropy(q_cat, c) + 0.1 * (q_logsd + 0.5 * ((u - q_mu) / q_logsd.exp()) ** 2).sum(1).mean()
g_loss = F.binary_cross_entropy_with_logits(logit, torch.ones_like(logit)) + 1.0 * info   # λ = 1
# D and Q also minimise `info` (Q head and shared trunk)
🐍 Exercise 1: the information bound
Compute the code entropy, the variational lower bound L_I, a Gaussian code likelihood and code purity.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A traversal varies…
  2. 2. If L_I stays far below H(c)…
  3. 3. To name the learned factors…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

The bound. I(c; X) = H(c) − H(c | X) with X = G(z, c). For any conditional Q, E over (c, X) of log P(c | X) = E log Q(c | X) + E over X of KL(P(·|X) ‖ Q(·|X)) ≥ E log Q(c | X). So I(c; X) ≥ H(c) + E log Q(c | X) = L_I, with equality when Q is the true posterior. The expectation only needs samples (c, z) and X = G(z, c), so the bound can be estimated and differentiated with respect to both G and Q without knowing P(c | X).

What maximising it does. For a categorical code with K values, L_I ≤ H(c) = log K, and L_I = log K exactly when Q identifies c from X with certainty: different code values must produce separable outputs. Combined with the GAN term, which forces outputs to look real, the cheapest way to do this is to let each code value own a different region of the data, such as a cluster, a digit class or a pose range.

Why it also helps coverage. If the K code values are spread over the data and each must stay distinguishable, the generator cannot put all samples into one region: that would make c unrecoverable. The information term therefore acts against mode collapse, at least for as many modes as the code has values.

What it does not guarantee. Any invertible relabelling of the factors gives the same mutual information, so which factor a code captures, and whether it is ‘semantic’, depends on the network’s inductive biases and the data (Locatello et al. 2019).

📝 Quick check (Level 3)
0/3 answered
  1. 1. The gap in the bound is…
  2. 2. For a K-way code, L_I is at most…
  3. 3. Mutual information cannot tell apart…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Does the information term make a code take over the modes of a toy distribution?

History.

  • X. Chen, Y. Duan, R. Houthooft, J. Schulman, I. Sutskever and P. Abbeel, “InfoGAN: interpretable representation learning by information maximizing generative adversarial nets” (NeurIPS 2016).
  • D. Barber and F. Agakov, “The IM algorithm: a variational approach to information maximization” (NeurIPS 2003).
  • F. Locatello et al., “Challenging common assumptions in the unsupervised learning of disentangled representations” (ICML 2019).

Exercise 2. A ring of 8 Gaussians (radius 2, std 0.1) and an 8-way categorical code.

  • Models (trained side by side): G takes 2-D noise plus the one-hot code: 10 → 32 → 32 → 2. D has 9 outputs (a real/fake logit and 8 Q-logits) on a shared 2 → 32 → 32 trunk. InfoGAN uses λ = 1; the control is identical with λ = 0 (the code is still an input, but nothing rewards using it).
  • Training: non-saturating loss, Adam (lr 0.002, β1 = 0.5), batch 64, 1000 steps.
  • Measures on 2000 samples (250 per code value): normalised mutual information (NMI) between code and nearest mode; purity, the mean share of each code value’s samples in its most common mode; L_I from Q; modes covered and the share of samples on a mode.
model seed NMI purity modes on a mode L_I (log 8 = 2.079)
InfoGAN (λ = 1) 0 / 1 / 2 1.0 / 1.0 / 1.0 1.0 / 1.0 / 1.0 8 / 8 / 8 0.942 / 0.894 / 0.966 2.078 / 2.078 / 2.077
control (λ = 0) 0 / 1 / 2 0.461 / 0.767 / 0.565 0.482 / 0.803 / 0.602 6 / 6 / 7 0.293 / 0.426 / 0.576 –
  • The code took over the modes: with the information term each of the 8 code values produced samples in exactly one mode, and Q recovered the code almost perfectly (L_I within 0.002 of log 8).
  • Without it the code was used only partly: the generator still saw c, and on seed 1 it was fairly informative (NMI 0.77), but nothing forced it.
  • Coverage bonus: the information term also prevented mode dropping here (8 of 8 modes versus 6–7). This is the easiest case: the number of code values equals the number of modes. With a mismatched K, or factors that are not clusters, results are less clean.
🐍 Exercise 2 (research): does the information term make a code take over the modes of a toy distribution?
Train an InfoGAN with an 8-way code and the same network without the information term on a ring of 8 Gaussians, and measure how the code maps to modes.

InfoGAN in AI, robotics and aerospace

  • Controllable synthetic data: codes that vary pose, lighting or class let engineers sweep one factor of synthetic imagery, after checking what each code actually does.
  • Unsupervised discovery: InfoGAN-style codes have been used to find discrete regimes in sensor or simulation data, such as flight phases or operating modes, as a clustering method with a generator attached.
  • Information-maximising objectives reappear in skill discovery for robots (DIAYN, Eysenbach et al. 2019), where a policy is rewarded when a discriminator can recover which skill produced a trajectory.

References

  1. X. Chen, Y. Duan, R. Houthooft, J. Schulman, I. Sutskever and P. Abbeel (2016). “InfoGAN: interpretable representation learning by information maximizing generative adversarial nets.” NeurIPS.
  2. D. Barber and F. Agakov (2003). “The IM algorithm: a variational approach to information maximization.” NeurIPS.
  3. F. Locatello, S. Bauer, M. Lucic, G. Rätsch, S. Gelly, B. Schölkopf and O. Bachem (2019). “Challenging common assumptions in the unsupervised learning of disentangled representations.” ICML.
  4. B. Eysenbach, A. Gupta, J. Ibarz and S. Levine (2019). “Diversity is all you need: learning skills without a reward function.” ICLR.