A softmax layer is defined such that: Each element in a softmax output vector gives the probability of being one class, as following figure shows
However, these probabilties might be very small. Logsoftmax is to take the log() of the softmax output vector, such that elements will not be too small. Each element in the Logsoftmax output can still denote the score of being one class.
Logsoftmax may be used to prevent underflow.
At forward time we have (with x = input vector, y = output vector, f = logsoftmax, i = i-th component):
When computing the jacobian Jf of f you have:
This gives for Jf:
So, If we name gradInput the gradient w.r.t input and gradOutput the gradient w.r.t output the backpropagation gives (chain rule):
This is equivalent to:
Artificial Intelligence + NLP + deep learning > AI > Machine Learning > Neural Networks > Deep Learning > Torch >