Class SoftmaxCrossEntropyLoss


  • public class SoftmaxCrossEntropyLoss
    extends Loss
    SoftmaxCrossEntropyLoss is a type of Loss that calculates the softmax cross entropy loss.

    If sparse_label is true (default), label should contain integer category indicators. Then, \(L = -\sum_i \log p_{i, label_i}\). If sparse_label is false, label should contain probability distribution and its shape should be the same as the shape of prediction. Then, \(L = -\sum_i \sum_j {label}_j \log p_{ij}\).

    • Constructor Detail

      • SoftmaxCrossEntropyLoss

        public SoftmaxCrossEntropyLoss()
        Creates a new instance of SoftmaxCrossEntropyLoss with default parameters.
      • SoftmaxCrossEntropyLoss

        public SoftmaxCrossEntropyLoss​(java.lang.String name)
        Creates a new instance of SoftmaxCrossEntropyLoss 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 of SoftmaxCrossEntropyLoss with the given parameters.
        Parameters:
        name - the name of the loss
        weight - the weight to apply on the loss value, default 1
        classAxis - the axis that represents the class probabilities, default -1
        sparseLabel - whether labels are 1-D integer array or 2-D probabilities of [batch_size, n-class], default true
        fromLogit - whether predictions are un-normalized numbers or log probabilities, if true, logSoftmax will be applied to input, default true
    • Method Detail

      • evaluate

        public NDArray evaluate​(NDList label,
                                NDList prediction)
        Calculates the evaluation between the labels and the predictions.
        Specified by:
        evaluate in class Evaluator
        Parameters:
        label - the correct values
        prediction - the predicted values
        Returns:
        the evaluation result