What is an autoencoder?
An autoencoder is a neural network that learns to copy its input to its output through a narrow middle. The first half, the encoder, squeezes the input down to a small set of numbers called the latent representation or code. The second half, the decoder, rebuilds the input from that code. Because the middle is too small to store everything, the network is forced to learn the most important regularities in the data and discard the rest.
No labels are needed, which places autoencoders in unsupervised learning. The trained encoder produces a low-dimensional representation that can feed other models, and the gap between an input and its reconstruction tells you how typical that input is.
How an autoencoder works
Training minimizes reconstruction error, the difference between each input and the decoder’s attempt to rebuild it. Variants change the training goal. A denoising autoencoder receives a corrupted input and must output the clean version. A variational autoencoder (VAE) learns a smooth probability distribution over codes, so new codes can be sampled to generate new examples, which makes it a generative model. Sparse and contractive autoencoders add penalties that make the code more structured. All of them are trained with ordinary backpropagation and gradient descent.
Autoencoders in practice
A municipal water utility monitors pumping stations with vibration, pressure, and current sensors. An autoencoder is trained only on readings from months of normal operation. In service, each new window of readings passes through it and the reconstruction error is tracked. A bearing that is beginning to fail produces patterns the network never learned to compress, the error climbs, and a work order is raised before the pump stops. The same approach catches card transactions that do not resemble a customer’s normal behavior, and the encoder half of an autoencoder is a common way to compress hundreds of product attributes into a handful of features for a recommendation system.
What to watch for
- Train on clean normal data. If the training set already contains faults, the model learns to reconstruct them and stops flagging them.
- The reconstruction error threshold is a business decision that trades missed faults against false alarms, so set it with the operations team.
- Choose the size of the code deliberately. Too large and the network copies everything, too small and it loses signal.
- For tabular anomaly detection, compare against simpler methods such as isolation forests before committing to a neural approach.