# Implementing weighted poisson\_nll\_loss

**URL:** <https://discuss.pytorch.org/t/implementing-weighted-poisson-nll-loss/148675>\
**Category:** Uncategorized\
**Created:** [April 8, 2022, 7:34pm UTC](https://discuss.pytorch.org/t/implementing-weighted-poisson-nll-loss/148675 "2022-04-08T19:34:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EvanZ](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/evanz/32/372_2.png) [@EvanZ](https://discuss.pytorch.org/u/EvanZ)\
**Post date:** [April 8, 2022, 7:34pm UTC](https://discuss.pytorch.org/t/implementing-weighted-poisson-nll-loss/148675/1 "2022-04-08T19:34:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [April 8, 2022, 11:08pm UTC](https://discuss.pytorch.org/t/implementing-weighted-poisson-nll-loss/148675/2 "2022-04-08T23:08:31Z")

</div>

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](https://discuss.pytorch.org/t/passing-the-weights-to-crossentropyloss-correctly/14731/10) to avoid creating a data-dependent loss spike.

---

<div class="post-metadata">

**Author:** ![EvanZ](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/evanz/32/372_2.png) [@EvanZ](https://discuss.pytorch.org/u/EvanZ)\
**Post date:** [April 14, 2022, 1:38pm UTC](https://discuss.pytorch.org/t/implementing-weighted-poisson-nll-loss/148675/3 "2022-04-14T13:38:29Z")

</div>

Thank you @ptrblck! Very helpful.
