Sparse autoencoder
The autoencoder we covered in the previous section works more like an identity network; it simply reconstructs the input. The emphasis is on reconstructing the image at the pixel level, and the only constraint is the number of units in the bottleneck layer. While it is interesting, pixel-level reconstruction is primarily a compression mechanism and does not necessarily ensure that the network will learn abstract features from the dataset. We can ensure that a network learns abstract features from the dataset by adding further constraints.
In sparse autoencoders, a sparse penalty term is added to the reconstruction error. This tries to ensure that fewer units in the bottleneck layer will fire at any given time. We can include the sparse penalty within the encoder layer itself.
In the following code, you can see that the dense layer of Encoder
now has an additional parameter, activity_regularizer
:
class SparseEncoder(K.layers.Layer):
def __init__...