[object Object]

[object Object][object Object]undefined
[object Object]
  • Description: Computes the cross-entropy loss of the input.

  • Formula:

    When reductionOptional is mean, the cross-entropy loss is calculated as:

    ln=weightynlogexp(xn,yn)c=1Cexp(xn,c)1{yn != ignoreIndex}l_n = -weight_{y_n}*log\frac{exp(x_{n,y_n})}{\sum_{c=1}^Cexp(x_{n,c})}*1\{y_n\ !=\ ignoreIndex \} loss={n=1N1n=1Nweightyn1{yn != ignoreIndex}ln,if reductionOptional = ’mean’n=1Nln,if reductionOptional = ’sum’ {l0,l1,...,ln},if reductionOptional = ’None’ loss=\begin{cases}\sum_{n=1}^N\frac{1}{\sum_{n=1}^Nweight_{y_n}*1\{y_n\ !=\ ignoreIndex \}}l_n,&\text{if reductionOptional = 'mean'} \\\sum_{n=1}^Nl_n,&\text {if reductionOptional = 'sum' }\\\{l_0,l_1,...,l_n\},&\text{if reductionOptional = 'None' }\end{cases}

    log_prob is calculated as:

    lsen=logc=1Cexp(xn,c)lse_n = log\sum_{c=1}^{C}exp(x_{n,c}) logProbn,c=xn,clsenlogProb_{n,c} = x_{n,c} - lse_n

    zloss is calculated as:

    zlossn=lseSquareScaleForZloss(lsen)2zloss_n = lseSquareScaleForZloss * (lse_n)^2

    Where N is the batch size and C is the number of labels.

[object Object]

Each operator has calls. First, aclnnCrossEntropyLossGetWorkspaceSize is called to obtain the workspace size required for computation and the executor that contains the operator computation flow. Then, aclnnCrossEntropyLoss is called to perform computation.

[object Object]
[object Object]
[object Object]
  • Parameters

    [object Object]
  • Returns

    [object Object]: status code. For details, see .

    The first-phase API implements input parameter verification. The following errors may be thrown.

    [object Object]
[object Object]
  • Parameters

    [object Object]
  • Returns

    [object Object]: status code. For details, see .

[object Object]
  • target only supports class label indices; probabilistic inputs are not supported.

  • The zloss-related features are currently not supported. Parameters lseSquareScaleForZloss and returnZloss are ignored even if provided.

  • Deterministic computation:

    • aclnnCrossEntropyLoss defaults to a deterministic implementation.
[object Object]

The following example is for reference only. For details, see .

[object Object]