Package ai.djl.training.loss
Class SoftmaxCrossEntropyLoss
- java.lang.Object
-
- ai.djl.training.evaluator.Evaluator
-
- ai.djl.training.loss.Loss
-
- ai.djl.training.loss.SoftmaxCrossEntropyLoss
-
public class SoftmaxCrossEntropyLoss extends Loss
SoftmaxCrossEntropyLoss
is a type ofLoss
that calculates the softmax cross entropy loss.If
sparse_label
istrue
(default),label
should contain integer category indicators. Then, \(L = -\sum_i \log p_{i, label_i}\). Ifsparse_label
isfalse
,label
should contain probability distribution and its shape should be the same as the shape ofprediction
. Then, \(L = -\sum_i \sum_j {label}_j \log p_{ij}\).
-
-
Field Summary
-
Fields inherited from class ai.djl.training.evaluator.Evaluator
totalInstances
-
-
Constructor Summary
Constructors Constructor Description SoftmaxCrossEntropyLoss()
Creates a new instance ofSoftmaxCrossEntropyLoss
with default parameters.SoftmaxCrossEntropyLoss(java.lang.String name)
Creates a new instance ofSoftmaxCrossEntropyLoss
with default parameters.SoftmaxCrossEntropyLoss(java.lang.String name, float weight, int classAxis, boolean sparseLabel, boolean fromLogit)
Creates a new instance ofSoftmaxCrossEntropyLoss
with the given parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NDArray
evaluate(NDList label, NDList prediction)
Calculates the evaluation between the labels and the predictions.-
Methods inherited from class ai.djl.training.loss.Loss
addAccumulator, elasticNetWeightedDecay, elasticNetWeightedDecay, elasticNetWeightedDecay, elasticNetWeightedDecay, getAccumulator, hingeLoss, hingeLoss, hingeLoss, l1Loss, l1Loss, l1Loss, l1WeightedDecay, l1WeightedDecay, l1WeightedDecay, l2Loss, l2Loss, l2Loss, l2WeightedDecay, l2WeightedDecay, l2WeightedDecay, maskedSoftmaxCrossEntropyLoss, maskedSoftmaxCrossEntropyLoss, maskedSoftmaxCrossEntropyLoss, resetAccumulator, sigmoidBinaryCrossEntropyLoss, sigmoidBinaryCrossEntropyLoss, sigmoidBinaryCrossEntropyLoss, softmaxCrossEntropyLoss, softmaxCrossEntropyLoss, softmaxCrossEntropyLoss, updateAccumulator
-
Methods inherited from class ai.djl.training.evaluator.Evaluator
checkLabelShapes, checkLabelShapes, getName
-
-
-
-
Constructor Detail
-
SoftmaxCrossEntropyLoss
public SoftmaxCrossEntropyLoss()
Creates a new instance ofSoftmaxCrossEntropyLoss
with default parameters.
-
SoftmaxCrossEntropyLoss
public SoftmaxCrossEntropyLoss(java.lang.String name)
Creates a new instance ofSoftmaxCrossEntropyLoss
with default parameters.- Parameters:
name
- the name of the loss
-
SoftmaxCrossEntropyLoss
public SoftmaxCrossEntropyLoss(java.lang.String name, float weight, int classAxis, boolean sparseLabel, boolean fromLogit)
Creates a new instance ofSoftmaxCrossEntropyLoss
with the given parameters.- Parameters:
name
- the name of the lossweight
- the weight to apply on the loss value, default 1classAxis
- the axis that represents the class probabilities, default -1sparseLabel
- whether labels are 1-D integer array or 2-D probabilities of [batch_size, n-class], default truefromLogit
- whether predictions are un-normalized numbers or log probabilities, if true, logSoftmax will be applied to input, default true
-
-