https://yuridekim.github.io//posts/Torch-adding-custom-loss-functions/
Torch adding custom loss functions - Yuri Kim