Implementing weighted poisson_nll_loss

I am using torch.nn.functional.poisson_nll_loss as a loss function. Now I would like to take into account the weights for each instance (for example, exposure in a risk application). I am thinking all I need to do is set reduction='none' and then dot the vector of losses with the weights column. Does that sound right?

Yes, your idea sounds reasonable. Iā€™m not familiar with your exact use case, but you should consider normalizing the reduced mean with the used weight as seen here to avoid creating a data-dependent loss spike.

1 Like

Thank you @ptrblck! Very helpful.