Skip to content

Why we calculate the loss between logits and target in CrossEntropyLoss? #166

Answered by mrdbourke
ahmad-alismail asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @afi1289,

Good questions!

Regarding to nn.CrossEntropyLoss(), it calculates the loss between input logits and target. Does nn.CrossEntropyLoss() have a softmax layer?

Yes, you're right!

This is in the documentation for torch.nn.CrossEntropyLoss() with the line:

"Note that this case is equivalent to the combination of LogSoftmax and NLLLoss."

Is the loss always calculated based on the comparison between logits (raw outputs) and labels?

In the case of how the PyTorch functions are implemented, generally, yes.

This is because if you look under the hood of the output layers/how the loss formulas are implemented, the outputs are in the form of a "logit" rather than a "label" (how the gr…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ahmad-alismail
Comment options

Answer selected by ahmad-alismail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants