Decoding maps a reduced or latent representation back into input space. Because encoding discards information, the result is generally a reconstruction rather than an exact recovery. The decoder supplies the reverse half of a representation-learning system: it expands a compact vector into an image, vector, or other input-shaped output. section 14.5 section 14.4
In an autoencoder, an encoder maps input x to a smaller latent vector z, and a decoder maps z to reconstructed input x̃. Both networks train end to end by minimizing reconstruction loss, such as mean squared error or binary cross-entropy, between x̃ and x. The latent-space size is a fixed hyperparameter that sets the representation budget. section 14.5 section 10.5.1
Figure 14.5 Schematic representation of an autoencoder. The encoder transforms input into a latent vector. The decoder transforms the latent vector into reconstructed input. We minimize the reconstruction loss—the distance between the reconstructed input and the original input.
Follow the complete reconstruction path: input becomes a latent vector, the decoder produces reconstructed input, and reconstruction loss compares it with the original. section 14.5
Decoding takes distinct forms across latent-space methods:
- PCA reconstructs an input at its original dimensionality from a lower-dimensional projection, using information retained in the learned best-fit plane; the reconstructed point need not equal the original. section 14.4
- A convolutional autoencoder uses transposed convolutions to progressively increase image height and width from a latent vector to an input-sized tensor. section 10.5.1 section 14.5
- A variational autoencoder decodes a latent sample into x̃; its decoder can also be viewed as modeling the input distribution conditioned on the latent point. section 14.7.1 section 14.7.3
Reconstructing digit images
For 32×32 image inputs, a PyTorch decoder can begin with a latent vector of size 10 and use ConvTranspose2d, BatchNorm2d, ReLU, and a final Sigmoid to generate Xr. Training computes Xr = decoder(z) and minimizes its difference from X. On MNIST, both autoencoders and VAEs reconstruct held-out digit images, while VAE regularization produces a more compact latent space. section 14.5 section 14.7.8
VAE decoding is trained alongside a stochastic encoder. Each input produces a latent distribution, a latent vector is sampled during training, and the decoder reconstructs the input. Reconstruction loss encourages fidelity, while KL-divergence loss makes latent distributions resemble a chosen prior. Sampling nearby latent values during training forces nearby codes to decode to nearby input regions, promoting smoothness. section 14.7.2 section 14.7.4














