When we are applying a mask onto the padded values in an input sequence, it is typically done through setting the padded values as negative infinity. For example, a tensor of values [1,2,3,0,0]
should result in a padding mask of pad_mask = [True, True, True, False, False]
(or the opposite depending on your flavour). However, if we apply the mask i.e attention_scores = attention_scores.masked_fill_(pad_mask.T == False, float('-inf'))
before applying softmax, won't we get the 4th and 5th row of the attention_scores as 'nan' when we softmax attempts to calculate the probability distribution along each row?
Does that mean the step of where to apply the mask is incorrect, and we should apply a zero-ing out of the pad token rows in the attention_score matrix after applying the softmax function? or is there another key concept/step I am missing here