Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Turning the compression knob
A VAE balances two things: describe each input well, and keep its code close to a plain standard bell curve. β is a knob on that balance. Turn it up and the model must say less about each input: reconstructions get blurrier, unimportant details are dropped first, and in good cases each remaining code dimension ends up tracking one meaningful factor, such as an object’s position or size. Turn it down and the code carries more detail. The demo shows how much information each latent carries as you turn the knob.
β-VAEs give compact, smooth latent spaces for robot state representations and control, and the rate–distortion view guides how latent diffusion autoencoders are regularised.
- 1. β multiplies…
- 2. A larger β gives…
- 3. Disentangled means each latent tracks…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Objective: E_q[log p(x | z)] − β · KL(q(z | x) ‖ p(z)). β = 1 is the ELBO; other β values are not likelihood bounds.
- Rate and distortion (Alemi et al., 2018): rate R = E_x KL(q(z | x) ‖ p(z)) ≥ I(x; z); distortion D = −E log p(x | z). The β-VAE minimises D + βR.
- Linear β-VAE, exactly solvable: for a data direction of variance λ and decoder variance σ², dividing the loss by β gives a plain VAE with noise βσ². So:
- the direction is used only if λ > βσ²;
- its rate is ½ ln(λ / βσ²) and its expected squared error βσ²; an unused direction costs its full variance λ.
- Example: λ = 3, σ² = 0.05: rate ½ ln 60 = 2.047 nats at β = 1, ½ ln 7.5 = 1.007 at β = 8, zero once β ≥ 60.
- This is reverse water-filling: the optimal Gaussian code gives every used component the same error θ = βσ², exactly Shannon’s rate–distortion solution.
- Active units (Burda et al., 2016): count latents whose posterior mean varies over the data, Var_x(E_q[z_j]) > 0.01.
- Disentanglement metrics: the β-VAE metric, FactorVAE metric, MIG (mutual information gap: for each factor, the gap between the two latents most informative about it), DCI and SAP.
- 1. A linear β-VAE uses a direction of variance λ only if…
- 2. Rate of an active direction:
- 3. MIG measures…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Training β-VAEs
Exercise 1.
- The β-VAE loss.
- The exact optimum of a linear β-VAE along one data direction (decoder weight, rate, error).
- Counting active units.
Practice.
- Sweep β on a log grid and plot rate against distortion; pick β from the curve, not from samples alone.
- With a Gaussian decoder, β and σ_x² are interchangeable (only βσ_x² matters), so a learned σ_x undoes a fixed β.
- Burgess et al.’s capacity annealing (loss rec + γ ǀKL − Cǀ with C raised from 0 to about 25 nats) gives better reconstructions than a large fixed β.
- FactorVAE (Kim and Mnih, 2018) and β-TCVAE (Chen et al., 2018) penalise only the total correlation of the aggregate posterior, keeping more information.
- Report disentanglement over many seeds: Locatello et al. found seed variation larger than differences between methods.
def beta_vae_loss(x, x_logits, mu, logvar, beta=4.0):
rec = F.binary_cross_entropy_with_logits(x_logits, x, reduction="none").flatten(1).sum(-1)
kl = 0.5 * (mu ** 2 + logvar.exp() - 1 - logvar).sum(-1)
return (rec + beta * kl).mean(), kl.mean() # log the KL: it is the rate
def capacity_loss(rec, kl, step, gamma=1000.0, c_max=25.0, ramp=100_000):
C = c_max * min(step / ramp, 1.0) # Burgess et al. (2018)
return (rec + gamma * (kl - C).abs()).mean()- 1. Choose β by…
- 2. With a Gaussian decoder, what matters is…
- 3. FactorVAE and β-TCVAE penalise…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Derivation of the linear solution. For one data direction of variance λ, encoder mean a·x, posterior variance s² and decoder weight w, the expected loss per point is [λ(1 − wa)² + w²s²]/(2σ²) + (β/2)(a²λ + s² − 1 − ln s²). Dividing by β turns it into the ordinary VAE loss with noise βσ². Its optimum is the probabilistic PCA solution: w² = λ − βσ², s² = βσ²/λ, a = w/λ when λ > βσ², and w = 0 otherwise. Substituting gives the KL ½ ln(λ/βσ²) and the squared error λ(βσ²/λ)² + w²βσ²/λ = βσ².
Why the diagonal posterior picks axes. The ELBO of a linear VAE with a full-covariance posterior is invariant to rotating the latent space. With a diagonal posterior it is not: the optimum needs WᵀW diagonal, i.e. decoder columns along the principal directions of the data. If the true factors are the principal directions (unequal variances), the latents align with them; if two factors have equal variance, every rotation of their plane is equally good and the alignment is arbitrary (Rolinek, Zietlow and Martius, 2019). β changes how strongly the diagonal posterior is enforced, not which axes are preferred.
The impossibility result. Locatello et al. (2019) proved that for any factorised prior there are infinitely many generative models with entangled latents that give exactly the same data distribution; unsupervised disentanglement therefore needs inductive biases (architecture, the posterior family, weak supervision). Their 12000-model study found that random seeds and hyperparameters mattered more than the choice of method.
β and likelihood. For β ≠ 1 the objective is no longer a bound on log p(x); a β-VAE trades likelihood for a more compressed code. Two-stage approaches (train a VAE, then fit the latent prior) and latent diffusion keep β small and handle sample quality elsewhere.
- 1. A full-covariance linear VAE's ELBO is invariant to…
- 2. With equal factor variances the learned axes are…
- 3. Locatello et al. showed unsupervised disentanglement needs…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does β control disentanglement, or does it only trade rate for distortion?
History.
- I. Higgins et al., “β-VAE: learning basic visual concepts with a constrained variational framework” (ICLR 2017).
- C. P. Burgess et al., “Understanding disentangling in β-VAE” (2018); A. Alemi et al., “Fixing a broken ELBO” (ICML 2018).
- F. Locatello et al., “Challenging common assumptions in the unsupervised learning of disentangled representations” (ICML 2019); M. Rolinek, D. Zietlow and G. Martius, “Variational autoencoders pursue PCA directions (by accident)” (CVPR 2019).
Exercise 2.
- Data: 300 points from two independent uniform factors, rotated by 30° and embedded in 4 dimensions with noise variance 0.05. Factor variances are 3 and 1 (unequal) or 1 and 1 (equal).
- Model: linear β-VAE, 2 latents, diagonal Gaussian posterior, decoder variance 0.05, trained with Adam (1500 steps, rate 0.05, decayed linearly to 0 over the last 500 so the result is converged) on the exact expected loss.
- Measures: rate (total KL), distortion (expected squared error), active latents (KL above 0.05 nats), and an alignment score: for each factor, the largest minus the second-largest ǀcorrelationǀ with any latent mean, averaged (1 = one latent per factor, 0 = fully mixed).
| factors | β | rate (nats) | distortion | active | alignment at step 500 | final alignment |
|---|---|---|---|---|---|---|
| unequal | 1 | 3.563 | 0.191 | 2 | 0.059 | 0.855 |
| unequal | 8 | 1.484 | 0.891 | 2 | 0.862 | 0.862 |
| unequal | 30 | 0.348 | 2.625 | 1 | 0.574 | 0.574 |
| equal | 1 | 3.032 | 0.191 | 2 | 0.076 | 0.068 |
| equal | 8 | 0.953 | 0.891 | 2 | 0.068 | 0.068 |
- β traded rate for distortion exactly as derived: the β = 1 rate matched ½ ln(3.05/0.05) + ½ ln(1.05/0.05) = 3.58, and each active direction’s error was βσ² (0.05 at β = 1, 0.4 at β = 8). At β = 30 (βσ² = 1.5) the weaker factor was switched off.
- Alignment came from unequal variances, not from β: β = 1 and β = 8 ended at almost the same alignment (0.855 and 0.862) when the variances differed, and at 0.068 when they were equal. β = 8 got there much sooner (0.862 already at step 500 against 0.059).
- Seeds 1 and 2: unequal-variance alignment 0.977 and 0.967 at β = 1, 0.979 and 0.957 at β = 8; equal-variance alignment varied from 0.089 to 0.914 across seeds and β, the signature of an arbitrary rotation.
- Caveat: a linear model with uniform factors, which a Gaussian model cannot tell from rotated ones; deep β-VAEs add other inductive biases that can help or hurt.
β-VAEs in AI, robotics and aerospace
- State representations for control: β-VAE encoders (e.g. DARLA, 2017) compress camera images into compact latents for reinforcement learning that transfers across visual changes.
- Latent diffusion autoencoders use a very small KL weight (around 10⁻⁶ in Stable Diffusion’s autoencoder): a rate–distortion choice toward detail.
- Anomaly detection on telemetry and imagery uses the rate (KL) and distortion of a β-VAE as two separate anomaly signals.
References
- I. Higgins et al. (2017). “β-VAE: learning basic visual concepts with a constrained variational framework.” ICLR.
- C. P. Burgess et al. (2018). “Understanding disentangling in β-VAE.” arXiv.
- A. Alemi et al. (2018). “Fixing a broken ELBO.” ICML.
- H. Kim and A. Mnih (2018). “Disentangling by factorising.” ICML.
- R. T. Q. Chen, X. Li, R. Grosse and D. Duvenaud (2018). “Isolating sources of disentanglement in VAEs.” NeurIPS.
- F. Locatello et al. (2019). “Challenging common assumptions in the unsupervised learning of disentangled representations.” ICML.
- M. Rolinek, D. Zietlow and G. Martius (2019). “Variational autoencoders pursue PCA directions (by accident).” CVPR.