An encoder is a neural-network component that maps an input into a smaller latent representation, preserving essential features while discarding variable information. In an autoencoder, it produces a latent vector; in a variational autoencoder, it produces the parameters of a latent-space distribution. section 10.5.1 section 14.7.1
For an image, the encoder commonly chains convolution, ReLU, and max-pooling layers so height and width shrink progressively. A final flattening and linear layer maps the resulting features to the latent dimension. The decoder reconstructs the input, and training minimizes reconstruction error. section 14.5
A VAE encoder does not directly emit one latent point. For a Gaussian family, it emits a mean and covariance or variance, samples a latent vector from that distribution during training, and uses the mean directly during inference. Reconstruction loss preserves input fidelity, while KL-divergence loss encourages a compact latent distribution. section 14.7.1 section 14.7.2
A typical encoder-centered computation proceeds as follows:
- For a VAE, reparameterize the Gaussian sample as z = μ + εσ so backpropagation can learn the encoder parameters. section 14.7.8
MNIST autoencoder and VAE
With 28×28 MNIST digits and a two-dimensional latent space, an autoencoder can reconstruct images but may learn a sparse, widely spread latent space. A VAE adds KL regularization, producing a more compact latent space while retaining useful reconstructions. section 14.7.8




















