Hi Kapil!



 Kapil_Rana:

In my case i want to apply softmax in last layer


You don’t actually want to apply softmax() as the last layer of your
model.  You should simply use the output of your last Linear layer
(to be understood as logits), and pass them to CrossEntropyLoss.
If you really need probabilities (rather than logits) for some purpose
(and you probably don’t), you should still use CrossEntropyLoss
as your loss function, passing in logits, and separately generate
the probabilities by applying softmax() to the output of your model.


Is CrossEntropyloss is good enough.


If you insist on building a model that outputs probabilities by
using softmax() as your last layer, then you shouldn’t use
CrossEntropyLoss as it doesn’t expect probabilities as inputs.
You would have to write your own version of cross-entropy that
does take probabilities (straightforward to do), but this approach
is numerically less stable than passing logits to CrossEntropyLoss
(even thought the two approaches are mathematically equivalent).
Best.
K. Frank