How to avoid nan in softmax?

you can use nn.LogSoftmax, it is numerically more stable and is less likely to nan than using Softmax

1 Like