Skip to content

Raw logits or softmax probability outputs in nn.CrossEntropyLoss()? #252

Answered by AlienSarlak
gigasurgeon asked this question in Q&A
Discussion options

You must be logged in to vote

As I mentioned, it is indeed an interesting observation. So, thank you for sharing this.

But back to your question. According to PyTorch documentation:
The input is expected to contain the unnormalized logits for each class (which do not need to be positive or sum to 1, in general).
Therefore it is recommended to set the raw logit instead of probabilities.

But it is beyond that. Have you noticed that the input is in the shape of logits and y_train or probs and 'y_train'? If you have a closer look, you will notice that the logits and 'probs' are in the shape of [number_of_sample, number_of_classes], but y_train is in [number_of_sample]! So, how does cross-entropy loss calculate the loss?
T…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@gigasurgeon
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by gigasurgeon
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