I think the torch.dot is wrong. My understanding was that it should be * and then
right_reasons = l_one * ((dot_prod) ** 2).sum()

But this doesn’t explain why you would have trouble with the right_reasons term if the mask matrix is all zeros…
Do you have a toy example to demonstrate this, maybe form the paper?