Pytorch Loss Functions in Plain Python
A side by side translation of all of Pytorch’s built-in loss functions to Python and Numpy
1 min readJul 31, 2018
While learning Pytorch, I found some of its loss functions not very straightforward to understand from the documentation. To help myself understand I wrote all of Pytorch’s loss functions in plain Python and Numpy while confirming the results are the same. Python code seems to me easier to understand than mathematical formula, especially when running and changing them.
Pytorch here is 0.4.0
and the order of the loss functions follow the Pytorch documentation: https://pytorch.org/docs/0.4.0/nn.html#loss-functions