Defining and training the autoencoder