nn_multi_margin_loss {torch} | R Documentation |
Multi margin loss
Description
Creates a criterion that optimizes a multi-class classification hinge
loss (margin-based loss) between input (a 2D mini-batch
Tensor
) and
output (which is a 1D tensor of target class indices,
):
Usage
nn_multi_margin_loss(p = 1, margin = 1, weight = NULL, reduction = "mean")
Arguments
p |
(int, optional): Has a default value of |
margin |
(float, optional): Has a default value of |
weight |
(Tensor, optional): a manual rescaling weight given to each
class. If given, it has to be a Tensor of size |
reduction |
(string, optional): Specifies the reduction to apply to the output:
|
Details
For each mini-batch sample, the loss in terms of the 1D input and scalar
output
is:
where
and
.
Optionally, you can give non-equal weighting on the classes by passing
a 1D weight
tensor into the constructor.
The loss function then becomes: