rasbt / machine-learning-book

Code Repository for Machine Learning with PyTorch and Scikit-Learn
https://sebastianraschka.com/books/#machine-learning-with-pytorch-and-scikit-learn
MIT License
3.64k stars 1.31k forks source link

Chapter 13, Page 438. Missing the final activation function (SoftMax) #142

Closed acmoudleysa closed 1 year ago

acmoudleysa commented 1 year ago

The note mentions that the softmax function is used at the end, but it's missing in the code you've provided.

all_layers.append(nn.Linear(hidden_units[-1], 10))

To be added: all_layers.append(torch.softmax(dim=1))

rasbt commented 1 year ago

Hi there, thanks for the note. The Softmax function should not be included of you use CrossEntropyLoss in PyTorch since the loss already performs Softmax implicitly. Thanks for commenting, though. Let me know if you have any questions, happy to discuss.