weight: (Tensor, optional): a manual rescaling weight given to the loss of each batch element. If given, has to be a Tensor of size nbatch.
reduction: (string, optional): Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'. 'none': no reduction will be applied, 'mean': the sum of the output will be divided by the number of elements in the output, 'sum': the output will be summed.
pos_weight: (Tensor, optional): a weight of positive examples. Must be a vector with length equal to the number of classes.
Details
The unreduced (i.e. with reduction set to 'none') loss can be described as:
This is used for measuring the error of a reconstruction in for example an auto-encoder. Note that the targets t[i] should be numbers between 0 and 1. It's possible to trade off recall and precision by adding weights to positive examples. In the case of multi-label classification the loss can be described as:
where c is the class number (c>1 for multi-label binary classification,
c=1 for single-label binary classification), n is the number of the sample in the batch and pc is the weight of the positive answer for the class c. pc>1 increases the recall, pc<1 increases the precision. For example, if a dataset contains 100 positive and 300 negative examples of a single class, then pos_weight for the class should be equal to 100300=3. The loss would act as if the dataset contains 3×100=300 positive examples.
Shape
Input: (N,∗) where ∗ means, any number of additional dimensions
Target: (N,∗), same shape as the input
Output: scalar. If reduction is 'none', then (N,∗), same shape as input.