To pre-train rectifier networks, Glorot, Bordes and Bengio (2011) use denoising auto-encoders: corrupt the input, encode it with a rectifier layer, and train the network to reconstruct the clean input. A rectifier is a poor choice for the reconstruction units, so on image data they reconstruct through a softplus layer with a squared error. Compute the loss of this auto-encoder on a mini-batch and its gradients.
Implement dae_loss_and_grads(X, U, W_enc, b_enc, W_dec, b_dec, p=0.25).
X: clean inputs, shape (B, d), one example per row.U: numbers in of the same shape. Masking noise: entry is corrupted (set to 0) when U[n, i] < p; otherwise it keeps its value. Call the result .W_enc shape (h, d), b_enc shape (h,), W_dec shape (d, h), b_dec shape (d,). The encoder and decoder weights are separate parameters.For each example with corrupted version :
The mini-batch loss is . Treat the derivative of as 0 at .
Output: a dict with "loss" (float), "X_tilde" (nested list) and "grads", a dict with keys "W_enc", "b_enc", "W_dec", "b_dec" holding as nested lists (same shapes as the parameters).