After unrolling, Hinton and Salakhutdinov (2006) fine-tune every weight of the deep autoencoder by back-propagating the reconstruction error. Pixels in use logistic output units and the cross-entropy error; word-frequency vectors of documents use a softmax output layer and the multiclass cross-entropy. All hidden units are logistic except the code units, which are linear. Compute the error and its gradient with respect to every weight and bias.
Implement finetune_gradients(layers, X, code_layer, output).
Inputs
layers: a list of layers, input side first. Layer is a dict with "W" (shape (n_k, n_{k+1})) and "b" (length n_{k+1}). Encoder and decoder weights are separate entries (they are not tied).X: the batch, shape (N, n_0). The target of the reconstruction is the input itself.code_layer: the index of the layer whose units are the linear code ().output: "logistic" or "softmax". With "softmax" every row of X is a probability distribution.Forward pass, with and for layers numbered (list index ):
"logistic", or the softmax of each row, , for "softmax";Error, averaged over the cases:
Output: a dict {"loss": E, "grads": [...]} where grads[k] is a dict with "W" and "b" holding and for list layer , as nested lists with the same shapes as the layer.