AI Glossary / Probabilistic machine learning / Intermediate
KL annealing
Definition
KL annealing is a training strategy that changes the weight of a Kullback - Leibler divergence term over time. In variational autoencoders, it commonly starts that weight near zero and gradually raises it, allowing the model to learn useful latent representations before applying the full regularization pressure.
What it means
A variational autoencoder balances two goals: reconstructing or explaining observed data, and keeping its approximate latent posterior appropriately related to a prior distribution. The KL term contributes to the second goal.
If a powerful decoder can model the data while ignoring the latent variable, training may settle into posterior collapse. In that situation, the approximate posterior can become close to the prior regardless of the input, leaving the latent code with little useful input-specific information.
KL annealing changes the training path in an attempt to avoid that outcome. It is a schedule for an objective coefficient, not a guarantee of meaningful representations. The architecture, data, optimizer and other training choices still affect the result.
How it works
In a common loss-minimization notation, the objective is reconstruction cost plus beta(t) times KL(q(z given x) || p(z)). A warm-up schedule increases beta from zero or a small value toward one over a chosen number of training steps.
The schedule can be linear or curved. Cyclical variants repeatedly lower and raise the weight rather than using one permanent warm-up. Their purpose is to provide additional opportunities to develop useful latent codes.
At beta = 1, the usual reconstruction-plus-KL objective corresponds to the negative evidence lower bound, subject to the model's definitions. At smaller weights it is generally a modified objective, not the same likelihood bound. The weighted KL contribution and the unweighted KL value should both be logged.
Three practical examples
- A text variational autoencoder uses a KL warm-up when its decoder otherwise learns to ignore the global latent code.
- An image-model experiment compares schedules while monitoring reconstruction, latent usage and samples drawn from the prior.
- A research team tests cyclical annealing against a fixed-weight baseline under the same evaluation procedure and training budget.
Think of it this way
Think of learning to organize notes before being asked to compress them into a strict filing system. Early flexibility may help useful organization emerge, while later constraints encourage compatibility with the intended system.
The analogy does not mean that every relaxed start leads to better learning. Nor is the KL term simply a penalty for having too many notes: it measures a distributional discrepancy, whose effect depends on the model and its parameterization.
Worked example
Separating a changing weight from a changing model
Consider two hypothetical model states evaluated with the same loss definitions. State A has reconstruction cost 20 and unweighted KL 6. State B has reconstruction cost 23 and unweighted KL 1. These are invented values for illustrating the objective, not measured training results.
At beta = 0.1, A's weighted loss is 20 + 0.1 times 6 = 20.6. B's loss is 23 + 0.1 times 1 = 23.1, so A is preferred by this temporary objective.
At beta = 1, A scores 26 and B scores 24, so B is preferred. The scores tie when 20 + 6 beta = 23 + beta, giving beta = 0.6.
A linear schedule reaching one after 10,000 updates has beta = 0.2 at update 2,000 and beta = 0.8 at update 8,000, under that stated indexing convention. The optimization target changes across those points. This explains why comparing raw weighted losses from different schedule stages can be misleading: the weights differ even before any model parameters change.
Illustrative case study
Fictional case: investigating unused latent codes
A fictional language-modeling group trains a variational autoencoder and finds that changing the latent code barely affects the decoder's output. It investigates whether the encoder distribution has become nearly input-independent.
The group tests a KL warm-up alongside its fixed-weight baseline. It records the unweighted KL, reconstruction term, held-out objective at a common evaluation weight, and sensitivity of outputs to latent changes. It also inspects samples generated from the prior.
The group avoids declaring success solely because the KL value increases. The added latent information must support its intended modeling task, and a larger distributional mismatch could make prior-generated samples less useful. No result is assumed in this fictional experiment.
Common misconceptions and mistakes
KL annealing is not the same as reducing the learning rate. One changes the objective's relative terms; the other changes the size of optimization updates. A training run may use both schedules.
The unweighted KL need not increase monotonically when its weight increases. The model responds to the changing objective, so the measured divergence can rise, fall or fluctuate.
A nonzero KL is not by itself proof that the latent variable contains useful information about the input. For example, every input could share the same posterior distribution that differs from the prior. Likewise, excellent reconstruction alone does not establish good generation from prior samples.
Business use
Use KL annealing as a controlled training experiment when there is evidence that a latent-variable model is failing to use its intended representation. Specify the problem the latent code should help solve.
Record schedule shape, duration, starting and final weights, loss scaling and stopping criteria. Evaluate models with a common objective and comparable held-out data, rather than comparing differently weighted training curves. Check whether apparent benefits persist after the full KL weight is applied. Keep downstream utility, latent information and generation quality as separate evaluation questions.
People also ask
Does annealing always end at one?
Common VAE warm-up does, but other objectives use different final weights. State the intended objective explicitly.
Does it eliminate posterior collapse?
No. It is a mitigation strategy whose effectiveness depends on the model and training setting.
What makes a schedule cyclical?
The KL weight is lowered and increased repeatedly, rather than only once at the start.
Check your understanding
For the worked model states at beta = 0.5, which has the lower weighted loss?
Answer: A scores 23 and B scores 23.5, so A is lower at that weight. This does not imply A is lower under the standard beta = 1 evaluation.
Related terms
- Variational autoencoder
- Latent variable
- Kullback–Leibler divergence
- posterior collapse
- evidence lower bound
- beta-VAE
- cyclical annealing
Learn next
Derive the ordinary VAE objective, then plot reconstruction, unweighted KL and weighted KL separately during a schedule. Compare latent-input dependence with aggregate mismatch to the prior.
More in Probabilistic machine learning
- Iterated extended Kalman filter - The iterated extended Kalman filter refines an extended Kalman filter's measurement update by repeatedly linearizing the observation model around an...
- Iterative soft thresholding algorithm - The iterative soft thresholding algorithm, often called ISTA or iterative shrinkage-thresholding, solves certain optimization problems by alternating a...
- Jacobian-vector product - A Jacobian-vector product, or JVP, multiplies a function's Jacobian at a chosen input by an input-direction vector.
- Knowledge gradient acquisition - A knowledge gradient acquisition function scores a possible measurement by the expected improvement it would produce in the value of the best final decision.
- Label bias problem - The label bias problem is a limitation of certain locally normalized sequence models: each state's outgoing transition probabilities must sum to one, which...
- Laplace approximation - A Laplace approximation replaces a probability density near a smooth mode with a Gaussian whose center and curvature match that local peak.
Sources
Primary warm-up discussion: Bowman and colleagues, Generating Sentences from a Continuous Space, section 3.1: https://aclanthology.org/K16-1002.pdf
Primary cyclical proposal: Fu and colleagues, Cyclical Annealing Schedule: https://aclanthology.org/N19-1021/
The two-state loss calculation and language-modelling case are original teaching examples.
Previous: Kitagawa - Oaxaca - Blinder decomposition Next: Klecka's tau