Foundations to Frontier
Tests
H. Generative Models › H3 Variational Autoencoders

β-VAE

The β-VAE (Higgins and colleagues, ICLR 2017) multiplies the KL term of the VAE objective by β. With β > 1 the code is squeezed harder toward the prior, which the authors found yields disentangled latents: each latent tracks one factor of variation such as position, scale or rotation. Alemi and colleagues (2018) gave the cleaner reading: β picks a point on a rate–distortion curve, trading the information the code carries (rate, the KL) against reconstruction error (distortion). Later work showed the limits. Locatello and colleagues (2019) proved that without inductive biases disentanglement is not identifiable, and Rolinek and colleagues (2019) traced it to the diagonal posterior, which favours latent axes along principal directions. This page derives the rate–distortion view, solves the linear β-VAE exactly (it is reverse water-filling), and covers disentanglement metrics and variants (capacity annealing, FactorVAE, β-TCVAE). In the exercises you compute the linear optimum and active units. You then train linear β-VAEs on data with two hidden factors. β moved the model along the rate–distortion curve as theory predicts: 3.56 nats and error 0.19 at β = 1, 1.48 nats and 0.89 at β = 8, and one factor switched off at β = 30. When the factors had unequal variances the latents lined up with them (alignment 0.855 at β = 1, 0.862 at β = 8); with equal variances they did not (0.07), whatever β. A larger β only made the alignment arrive sooner.

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.

VAE lab
βσ² = 0.100: rate 5.04 nats, expected error 0.40, active latents 4 of 4. Raising β moves along the rate–distortion curve and switches off the weakest directions first.
Why engineers care

β-VAEs give compact, smooth latent spaces for robot state representations and control, and the rate–distortion view guides how latent diffusion autoencoders are regularised.

📝 Quick check (Level 0)
0/3 answered
  1. 1. β multiplies…
  2. 2. A larger β gives…
  3. 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.
📝 Quick check (Level 1)
0/3 answered
  1. 1. A linear β-VAE uses a direction of variance λ only if…
  2. 2. Rate of an active direction:
  3. 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()
🐍 Exercise 1: β-VAE loss, linear optimum and active units
Write the β-VAE loss, the exact linear β-VAE optimum along a direction, and an active-units counter.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Choose β by…
  2. 2. With a Gaussian decoder, what matters is…
  3. 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.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A full-covariance linear VAE's ELBO is invariant to…
  2. 2. With equal factor variances the learned axes are…
  3. 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.
🐍 Exercise 2 (research): does β control disentanglement, or does it only trade rate for distortion?
Train linear β-VAEs at several β on data with two hidden factors of unequal or equal variance, and measure rate, distortion and alignment with the factors.

β-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

  1. I. Higgins et al. (2017). “β-VAE: learning basic visual concepts with a constrained variational framework.” ICLR.
  2. C. P. Burgess et al. (2018). “Understanding disentangling in β-VAE.” arXiv.
  3. A. Alemi et al. (2018). “Fixing a broken ELBO.” ICML.
  4. H. Kim and A. Mnih (2018). “Disentangling by factorising.” ICML.
  5. R. T. Q. Chen, X. Li, R. Grosse and D. Duvenaud (2018). “Isolating sources of disentanglement in VAEs.” NeurIPS.
  6. F. Locatello et al. (2019). “Challenging common assumptions in the unsupervised learning of disentangled representations.” ICML.
  7. M. Rolinek, D. Zietlow and G. Martius (2019). “Variational autoencoders pursue PCA directions (by accident).” CVPR.