Md. Asif Uddin

    Proposition 4I.13.P0447 of 100 in the corpus

    The KL term puts a price on the code, and a code priced too high is ignored.

    The ELBO trades a rate against a distortion. For a linear decoder the trade is exact: raising the weight on the rate shrinks the code until, past a threshold, the decoder stops using it. The rate pays for information and for every hole the prior does not cover.

    Rate against distortion for the linear β-VAEA curve of rate against squared distortion for the chapter's four points. At beta one quarter the rate is 1.386 and the distortion 1.25. At beta one, the ordinary ELBO, the rate is 0.693 and the distortion 2. At beta two they are 0.347 and 3. At beta four the rate reaches zero and the distortion 5, the total variance: the code is ignored. As beta goes to zero the curve rises without bound against a dashed line at distortion 1, the error of the principal-axis autoencoder of Chapter I.12.rate against distortion1234500.511.5distortion: mean squared errorrate: natsβ → 0: I.12's lossβ = 0.25β = 1β = 2β ≥ 4: collapseR = ½ log(4/β) and D = 1 + β, until β = 4.β = 1 is the ELBO. Past β = 4 the code carries nothing.
    Fig. 4 — Type G · Failure — Rate against distortion for the linear β-VAE on the chapter's four points, drawn from the exact solution. Raising β buys a cheaper code with a worse reconstruction; at β = 4 the code carries nothing and the decoder ignores it.

    Rate and distortion

    Average the ELBO over the data and give its two terms names. The average KL term is the rate RR: the cost, in nats, of the code relative to the prior. The average reconstruction term, negated, is the distortion. With a Gaussian decoder of fixed variance σ2\sigma^2 the distortion is the mean squared error DD, up to the factor 1/(2σ2)1/(2\sigma^2) and a constant, and the ELBO is minus their sum.

    Higgins and colleagues (2017) put a weight β\beta on the rate and found that β>1\beta>1 gave codes whose coordinates varied more independently. A weight changes which point on the trade-off training reaches. Alemi and colleagues (2018) drew that trade-off as a curve in the plane of rate and distortion, and showed that models with the same ELBO can sit at very different points of it. The ELBO alone does not say how much the code is used.

    The linear β-VAE, solved exactly

    Keep probabilistic PCA’s decoder with one latent dimension and σ2\sigma^2 fixed, and let the encoder be any Gaussian N(m,v)\mathcal N(m,v) for each input. Write a=wTxa=\vec w^{\mathsf T}\vec x and r=∥w∥2r=\|\vec w\|^2. The β\beta-weighted ELBO of one input is a quadratic in mm and a sum of vv and log⁡v\log v, so the best encoder can be found by setting two derivatives to zero:

    m=ar+βσ2,v=βσ2r+βσ2.\begin{aligned} m&=\frac{a}{r+\beta\sigma^2},\\ v&=\frac{\beta\sigma^2}{r+\beta\sigma^2}. \end{aligned}

    At β=1\beta=1 this is the exact posterior of (I.13.2). Substituting back and averaging over the data, using E[a2]=rλ1\E[a^2]=r\lambda_1 for w\vec w along u1\vec u_1, leaves a function of rr alone whose derivative is

    β2(r+βσ2)(λ1r+βσ2−1).\frac{\beta}{2(r+\beta\sigma^2)} \Big(\frac{\lambda_1}{r+\beta\sigma^2}-1\Big).

    It is positive until r+βσ2=λ1r+\beta\sigma^2=\lambda_1 and negative after. If βσ2≥λ1\beta\sigma^2\geq\lambda_1 it is never positive, and the best rr is zero. Evaluating the rate and the distortion at the optimum gives

    ∥w∥2=max⁡(λ1−βσ2,  0),R=12log⁡λ1βσ2,D=∑i>1λi+βσ2,\begin{aligned} \|\vec w\|^2&=\max(\lambda_1-\beta\sigma^2,\;0),\\ R&=\tfrac12\log\frac{\lambda_1}{\beta\sigma^2},\\ D&=\sum_{i>1}\lambda_i+\beta\sigma^2, \end{aligned}
    (I.13.8)

    A linear β-VAE trades rate for distortion and switches off past a threshold.

    the last two while βσ2<λ1\beta\sigma^2<\lambda_1. Past the threshold the rate is zero and the distortion is the total variance. This is I.13.T3, and I.13.B03 derives every line.

    On the four points, with λ1=4\lambda_1=4, λ2=1\lambda_2=1 and σ2=1\sigma^2=1, (I.13.8) gives a rate of 12log⁡(4/β)\tfrac12\log(4/\beta) and a distortion of 1+β1+\beta. The figure draws the curve:

    β\beta∥w∥2\|\vec w\|^2rate RRDD
    0.250.253.753.751.3862941.3862941.251.25
    11330.6931470.69314722
    22220.3465740.34657433
    44000055

    At β=1\beta=1 the solution is probabilistic PCA, and the rate log⁡2\log2 is the price of the code found in proposition 2. As β→0\beta\to0 the distortion falls to 11, which is the principal-axis autoencoder’s loss in I.12, and the rate grows without bound: the encoder’s variance βσ2/λ1\beta\sigma^2/\lambda_1 goes to zero and the code becomes a point. The deterministic autoencoder of I.12 is the corner of this curve where the code is free and infinitely expensive.

    Posterior collapse

    At β=4\beta=4 the optimum is w=0\vec w=\vec 0. The decoder ignores the code, the encoder returns the prior N(0,1)\mathcal N(0,1) for every input, the rate is zero and the distortion is 55, the whole variance of the data. That is posterior collapse, and here it is not a failure of optimisation. It is the maximum of the objective: the variance the code could explain, 44, is not worth its price, βσ2=4\beta\sigma^2=4.

    With β=1\beta=1 and σ2\sigma^2 learned, the same threshold appears per direction: probabilistic PCA gives zero weight to every direction whose eigenvalue does not exceed the noise variance. Lucas, Tucker, Grosse and Norouzi (2019) showed that linear VAEs collapse exactly where probabilistic PCA does, and that the ELBO adds no bad maxima of its own. The threshold is the one weight decay imposed in (I.12.6), with σ2\sigma^2 in place of γ\gamma.

    Nonlinear decoders add a second route. A decoder powerful enough to model x\vec x well without z\vec z, such as one that predicts each word of a sentence from the words before it, can reach a good reconstruction term at zero rate. The KL term is then pure cost, and training removes the code. Bowman and colleagues (2016) met this with sentence VAEs. They annealed the KL weight up from zero during training, and weakened the decoder by hiding some of its input words, so that the code had work to do.

    What the rate pays for

    The rate is an average over the training examples, indexed by nn. Write q(z)q(\vec z) for the aggregate posterior, the average of the encoder’s distributions. Then

    1N∑n=1NKL⁡(q(z∣xn) ∥ p(z))    =Iq(n;z)+KL⁡(q(z) ∥ p(z)).\begin{aligned} &\frac1N\sum_{n=1}^N\KL\big(q(\vec z\mid\vec x_n)\,\|\,p(\vec z)\big)\\ &\;\;=I_q(n;\vec z)+\KL\big(q(\vec z)\,\|\,p(\vec z)\big). \end{aligned}
    (I.13.9)

    The rate pays for information in the code and for mismatch with the prior.

    To see it, write each log⁡q(z∣xn)/p(z)\log q(\vec z\mid\vec x_n)/p(\vec z) as log⁡q(z∣xn)/q(z)\log q(\vec z\mid\vec x_n)/q(\vec z) plus log⁡q(z)/p(z)\log q(\vec z)/p(\vec z). The first averages to the mutual information between the code and the index of the example (Mutual information 0.IT.04), the second to the KL from the aggregate posterior to the prior. Hoffman and Johnson (2016) introduced this split. It is I.13.T4.

    Both parts mean something. Zero rate forces zero information: collapse is exactly a code that says nothing about which example it came from. And the second part is the hole problem of I.12, given a price. Where q(z)q(\vec z) is thin and the prior is not, codes drawn for generation land in places the decoder rarely saw in training.

    On the four points at β=1\beta=1, every encoder distribution has variance 0.250.25 and mean ±0.866025\pm0.866025, so q(z)q(z) is a mixture of two Gaussians. The rate 0.6931470.693147 splits into 0.5859390.585939 of information and 0.1072080.107208 of mismatch (I.13.X06). The mixture has variance exactly 11, like the prior, but not its shape: at z=0z=0 its density is 0.1780320.178032 where the prior’s is 0.3989420.398942. The prior draws codes near zero more than twice as often as the encoder produced them.

    What the variational autoencoder fixed, and what it did not

    Against I.12 it fixed three things. Codes have a distribution, so new ones can be drawn. The space between training codes is trained, because each input is decoded from a cloud of codes. And the objective is a lower bound on the likelihood, which an autoencoder never offered.

    Three things remain. The bound can be loose, and proposition 2 showed the gap cannot be measured on its own. The holes are priced, not removed. And a Gaussian decoder still returns a conditional mean, so ambiguous inputs are reconstructed as blurred averages, for the reason given in I.12.X08.

    The curve, in six lines

    from math import log
    lam1, lam2, var = 4.0, 1.0, 1.0
    for beta in (0.25, 0.5, 1, 2, 4, 8):
        r = max(lam1 - beta*var, 0.0)                  # ||w||^2 at the optimum
        rate = 0.5*log(lam1/(beta*var)) if r > 0 else 0.0
        distortion = lam2 + beta*var if r > 0 else lam1 + lam2
        print(f"beta {beta}: ||w||^2 {r:.2f}, rate {rate:.6f}, distortion {distortion:.2f}")

    It prints the table above with β=0.5\beta=0.5 and β=8\beta=8 added: rate 1.0397211.039721 with distortion 1.51.5, and a collapsed code with distortion 55. The check script compares these closed forms with a direct maximisation of the averaged objective.

    Sources