PoissonNLLLoss

class paddle.nn. PoissonNLLLoss ( log_input=True, full=False, epsilon=1e-08, reduction='mean', name=None ) [source]

Generate a callable object of ‘PoissonNLLLoss’ to calculate the Poisson negative log likelihood loss between Input(input) and Input(label). Notes that Input(input) is the expectation of underlying Poisson distribution and Input(label) is the random samples from the Poisson distribution

Poisson negative log likelihood loss is calculated as follows:

\[\text{loss}(\text{input}, \text{label}) = \text{input} - \text{label} * \log(\text{label}) + \log(\text{label!})\]

The last term can be approximated with Stirling formula. This approximation term is used when full is True. The approximation is added when label values are more than 1 and omitted when the labels are less than or equal to 1.

Parameters
  • log_input (bool, optional) – Whether to the treat input tensor as log input. If True the loss is computed as, \(\exp(\text{input}) - \text{label} * \text{input}\) . If False then loss is \(\text{input} - \text{label} * \log(\text{input}+\text{epsilon})\) . Default: True.

  • full (bool, optional) – Whether to compute full loss. If True, the Stirling approximation term is added. If False, the Stirling approximation is dropped. Default: False.

  • epsilon (float, optional) – A small value to avoid evaluation of \(\log(0)\) when log_input = False. epsilon > 0. Default: 1e-8.

  • reduction (str, optional) – Indicate how to reduce the loss, the candidates are 'none' | 'mean' | 'sum'. If reduction is 'mean', the reduced mean loss is returned; if reduction is 'sum', the reduced sum loss is returned; if reduction is 'none', no reduction will be applied. Default is 'mean'.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Shape:
  • input (Tensor): The shape of input tensor should be (N, *) or (*) where (*) denotes any number of extra dimensions.

  • label (Tensor): The shape of input tensor should be (N, *) or (*), same shape as the input tensor.

  • output (Tensor): scalar if reduction is 'mean' (default) or 'sum'. If reduction is 'none', then \((N, *)\), same shape as the input

Examples

>>> import paddle
>>> paddle.seed(2023)
>>> poisson_nll_loss = paddle.nn.loss.PoissonNLLLoss()
>>> input = paddle.randn([5, 2], dtype=paddle.float32)
>>> label = paddle.randn([5, 2], dtype=paddle.float32)
>>> loss = poisson_nll_loss(input, label)
>>> print(loss)
Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
1.52983975)
forward ( input, label )

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments