Built-in way to calculate accuracy over padded sequences of softmax/logsoftmax outputs?

Is there some built-in method for calculating prediction accuracy over sequences of softmax/logsoftmax vectors?

So i have a batch of sequences, the inputs padded by some padding index, the targets of identical lengths where the targets are class indices and the prediction of the network is in the form of softmax or logsoftmax scores.

I would like to calculate the accuracy of the predictions on the current batch as efficiently as possible. This means, all the elements in each of the sequences where the input is a padding index need to get ignored and for the rest, the prediction index needs to get calculated as the index of the element in the output vector with the highest prob or log/prob and then all the correctly predicted indices need to get counted etc.

The loss functions like LogSoftmax automatically take care of ignoring padding indices. Is there an equivalent method for calculating accuracy?

And also, what if the sequences are packed, is there are method for that situation?

1 Like

Hey John. Have you had any answers to your question?