# Temporal Ensembling for Semi-Supervised Learning

Temporal ensembling trains semi-supervised networks on averaged predictions from earlier epochs

Samuli Laine, Timo Aila · arXiv · 2016-10-7

- **Problem** Semi-supervised training has only a few labels, so unlabeled inputs need targets, and one network's current output is a noisy source of them.
- **Method** Temporal ensembling trains one network and uses an exponentially weighted average of its earlier epoch outputs as targets. Unlike the Π-model, it evaluates the network once per input per epoch.
- **Results** Temporal ensembling reaches 7.05% error on SVHN with 500 labels, down from 18.44% without augmentation.

## Why earlier epoch predictions could serve as targets

Semi-supervised learning starts from a training set in which only a small share of the inputs carry labels, so the unlabeled inputs need some other source of training targets. The authors argue that predictions gathered from the network across earlier epochs, each made under different dropout and augmentation, tend to be closer to the unknown labels than the prediction the network makes at its current state.

Using such aggregated predictions as targets for the unlabeled inputs is what turns this observation into a training method.

The argument also depends on the regularization. Dropout makes each evaluation of the same input differ, and stochastic augmentation adds further variation, so the spread of outputs across epochs carries information that a single evaluation lacks. The same mechanism is claimed to help when all labels are present, which the authors tie to tolerance against ambiguous labels.

## The Π-model loss and its two branches

In the Π-model each minibatch is passed through the network twice. Dropout and the stochastic augmentation are drawn again for each pass, so the two output vectors differ even though the weights and the input are the same. The network is therefore trained to make its output stable under this perturbation, rather than only to make the final class correct.

The total loss has two parts. The supervised part is a cross-entropy term, the negative mean of the log probability assigned to the correct class, taken over only the labeled inputs in the minibatch. The unsupervised part is a mean squared difference between the two output vectors, averaged over every input in the minibatch and divided by the number of classes C, and it is multiplied by the ramp-up weight w(t).

\\\[ \\text{loss} = -\\frac{1}{\|B\|}\\sum\_{i\\in B\\cap L}\\log z\_i\[y\_i\] \\;+\\; w(t)\\,\\frac{1}{C\|B\|}\\sum\_{i\\in B}\\lVert z\_i-\\tilde z\_i\\rVert^2 \\\]

The weight w(t) starts at zero and grows along a Gaussian curve over the first 80 epochs, so early gradients come almost entirely from the labeled data. The authors found the ramp-up has to be slow, because a faster ramp let the network fall into a degenerate solution with no meaningful classification.

The Π-model resembles the Γ-model of the ladder network, but it is simpler. It compares the outputs after softmax directly, with no learned mapping between branches, and it applies the same augmentation and noise to both branches rather than making one branch clean and the other corrupted.

## Accumulating epoch predictions into targets

Temporal ensembling starts from the same observation as the Π-model but removes the second evaluation. The targets for the unsupervised term are built from earlier outputs, so the network is evaluated only once per input per epoch. The authors describe the single-evaluation design as an approximately 2x speedup over the Π-model.

After each epoch the outputs z\_i for the inputs of that epoch are folded into a stored matrix Z by the rule \\( Z\_i \\leftarrow \\alpha Z\_i + (1-\\alpha) z\_i \\), where alpha is the ensembling momentum. Because the update is exponential, recent epochs carry more weight than distant ones, and alpha decides how far back the average reaches into training history.

At the start Z holds zeros, so it is biased toward zero. The targets are therefore obtained by dividing Z by a bias-correction factor that depends on alpha and on the epoch number, a correction the authors compare with the one used in Adam and in mean-only batch normalization. On the first epoch there is no history, so Z and the targets are zero and the ramp-up weight is set to zero for that epoch.

Temporal ensembling needs Z for every training input and class, which is an N by C matrix, and it adds alpha as a new hyperparameter. The authors note that Z can be large, but its elements are accessed fairly rarely, so it can be kept in a memory-mapped file. Besides the mean, the same accumulation could track the second raw moment of the outputs to estimate per-output variance, which the authors leave for future work.

## SVHN and CIFAR-10 error rates

The authors also note that the 500-label result is less than half the earlier error without augmentation, and that its standard deviation is much smaller. The gap between the Π-model and temporal ensembling at 500 labels with augmentation is 1.5 percentage points.

Temporal ensembling is slightly better and is also twice as fast to train. The authors measured that the Π-model benefits by about 0.5 percentage points from drawing horizontal flips once per pair of evaluations, rather than independently for each epoch as temporal ensembling does.

Comparison with Sajjadi et al. (2016b) is hard, because their setup uses a wider set of augmentations and fractional max pooling, which the authors describe as introducing random local stretching inside the network. Their supervised-only error with 4000 labels is 13.60%, against 34.85% for this paper's augmented supervised baseline, and their semi-supervised error falls from 13.60% to 11.29%.

This paper's augmented error falls from 34.85% to 12.16%, a 65% relative drop, while the 17% drop reported for Sajjadi et al. is from their own baseline.

## Adding unlabeled Tiny Images inputs on CIFAR-100

The authors report these as 7.8 and 5.9 percentage point improvements over supervised learning with labeled inputs only.

The authors read this as evidence that the extra data only needs to lie roughly in the same space as the real inputs, here natural images, and they hypothesize that properly crafted synthetic data might also work. That is a hypothesis and was not tested here.

To keep training times acceptable, the number of unlabeled inputs is capped at 50k per epoch, and the 50k are drawn at random each epoch from the 500k or 237k extra inputs. Temporal ensembling updates only the rows of Z that belong to the inputs used in that epoch.

## Tolerance to randomized labels

The test assigns a random label to a chosen fraction of the SVHN training set before training starts, and tracks classification accuracy over epochs for standard supervised training and for temporal ensembling.

With standard supervised training, accuracy drops as soon as a small share of labels is wrong, and it degrades quickly once the randomized share reaches 50% or more. Temporal ensembling keeps almost perfect accuracy with half of the labels random and stays above ninety percent with 80% of the labels random.

The authors explain this by the two loss terms. The unsupervised term makes the mapping flat around every input, while the supervised term fixes the output near the labeled points, so wrong labels are outvoted by the many inputs that the unsupervised term smooths over. The authors contrast this with classical regularizers, which smooth over the whole input domain; their smoothing acts only on the manifold of likely inputs.

## Results when all labels are used

The authors find it surprising that the methods help even with all labels, and they believe the consistency requirement makes the network resistant to ambiguous labels and encourages features that are more invariant to stochastic sampling.

## How the methods relate to earlier consistency and ensemble ideas

The transform/stability loss sums pairwise squared distances between n network outputs obtained under augmentation and perturbation, so the Π-model is its special case with n equal to 2. Its cost grows linearly with n, whereas the cost of temporal ensembling does not grow with the effective ensemble size formed by averaging earlier epochs.

The Γ-model keeps a clean branch and a corrupted branch, compares a denoised pre-activation estimate with the clean output, and uses a parametric nonlinearity with 10 auxiliary trainable parameters per unit. The Π-model removes the parametric nonlinearity and the denoising, uses two corrupted paths, and compares network outputs instead of pre-activations of the final layer.

Bagging trains multiple networks on subsets of the training data, whereas this approach draws its variability from one network under different dropout and augmentation. Huang et al. (2017) store snapshots during training as an explicit ensemble, a parallel work the authors contrast with their implicit one. Unlike label propagation, which compares training inputs with one another, the methods never compare training inputs and rely only on unknown labels staying constant while the network produces the labels for unlabeled inputs.

## Limitations

Temporal ensembling stores the ensemble matrix across epochs and introduces the momentum alpha, which must be chosen. The Π-model and temporal ensembling both depend on a slow ramp-up of the unsupervised weight, since a fast ramp let the network settle into a degenerate solution.

The Tiny Images runs are capped at 50k unlabeled inputs per epoch, which the authors chose to keep training times tolerable. The authors also note that the comparison methods are rarely stated to use input augmentation, so their error rates are reported without augmentation unless stated otherwise.

## Paper info

- **Authors**: Samuli Laine, Timo Aila
- **Venue**: arXiv · Preprint
- **First published**: 2016-10-7
- **Added**: 2026-11-12
- **Updated**: 2017-3-15
- **Version**: v3
- **arXiv**: 1610.02242
- **Category**: cs.NE · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1610.02242v3) · [PDF ↗](https://arxiv.org/pdf/1610.02242v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Samuli Laine, Timo Aila (2016). Temporal Ensembling for Semi-Supervised Learning. arXiv:1610.02242v3. https://arxiv.org/abs/1610.02242v3

**BibTeX**

```
@misc{laine2016temporal,
  title = {{Temporal Ensembling for Semi-Supervised Learning}},
  author = {Samuli Laine and Timo Aila},
  year = {2016},
  eprint = {1610.02242},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1610.02242v3}
}
```

## Other paper commentary

- [Modeling Long- and Short-Term Temporal Patterns with Deep Neural Networks](https://refivu.com/en/papers/2ced2044-9976-4c74-bbf8-ff344f253f42-modeling-long-and-short-term-temporal-patterns-with.md)
- [PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization](https://refivu.com/en/papers/d88e659c-e7cf-4fb4-acf4-46e297868666-posenet-a-convolutional-network-for-real-time-6.md)
- [Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks](https://refivu.com/en/papers/15731593-7d6d-4afb-b434-961a20dea639-gate-variants-of-gated-recurrent-unit-gru-neural.md)
- [Recurrent Neural Networks for Multivariate Time Series with Missing Values](https://refivu.com/en/papers/04779a68-ae30-4f73-bc85-9bae7235eaaf-recurrent-neural-networks-for-multivariate-time-series-with.md)
- [Non-negative matrix factorization with sparseness constraints](https://refivu.com/en/papers/56eb7310-b0a6-4b18-9880-4ca6ff6f54dc-non-negative-matrix-factorization-with-sparseness.md)
- [Neural Turing Machines](https://refivu.com/en/papers/98345e56-0459-409a-bde9-37eadc2f2d0a-neural-turing-machines.md)
- [Tutorial on Variational Autoencoders](https://refivu.com/en/papers/51a9cfc2-6285-4935-b55a-3d6450af8eff-tutorial-on-variational-autoencoders.md)
- [VoxCeleb: a large-scale speaker identification dataset](https://refivu.com/en/papers/4f6bddda-2d26-4b56-93a3-d11745f2af0d-voxceleb-a-large-scale-speaker-identification-dataset.md)
- [AffectNet: A Database for Facial Expression, Valence, and Arousal Computing in the Wild](https://refivu.com/en/papers/93b39bb6-a5c2-45b8-8cd8-f4785271bb90-affectnet-a-database-for-facial-expression-valence-and.md)
- [AID: A Benchmark Dataset for Performance Evaluation of Aerial Scene Classification](https://refivu.com/en/papers/7ff42b05-661d-4b69-9f82-81042fe1d6b3-aid-a-benchmark-dataset-for-performance-evaluation-of.md)
- [MS MARCO: A Human Generated MAchine Reading COmprehension Dataset](https://refivu.com/en/papers/5bd254d7-7f81-466f-936c-2233b75bea95-ms-marco-a-human-generated-machine-reading-comprehension.md)
- [Objects as Points](https://refivu.com/en/papers/15289860-cbb9-4b2e-92d1-6e9088d6effa-objects-as-points.md)

## Terms in this paper

- [dropout](https://refivu.com/en/terms/db73f75bbdd3-dropout)
- [ADAM](https://refivu.com/en/terms/0e9ad0199e08-adam)
- [semi-supervised learning](https://refivu.com/en/terms/437382161673-semi-supervised-learning)
- [Temporal Ensembling](https://refivu.com/en/terms/0f052e50777c-temporal-ensembling)
- [ladder network](https://refivu.com/en/terms/00d230ca9545-ladder-network)
- [network architecture](https://refivu.com/en/terms/654ea6c1b7ac-network-architecture)
- [Π-Model](https://refivu.com/en/terms/69ac697bce02-model)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/5823cdfc-4033-4589-9f86-a6c88d27f620-temporal-ensembling-for-semi-supervised-learning)
