---
title: "ClikaRT::ops::nll_loss"
sidebar_label: "nll_loss"
description: "Negative-log-likelihood loss over LOG-probabilities; class dim LAST. \\[ \\ell = -x_{y} \\] input is expected to already be log-probabilities (pair with log_softmax; cross_entropy is the fused form)."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## nll\_loss() {#nll_loss}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`nll_loss`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `target`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`OptionalTensor`](../../index.md#OptionalTensor) `weight` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::optional<int64_t>` `ignore_index` `=` `std::nullopt`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Reduction`](./index.md#Reduction) `reduction` `=` [`Reduction::Mean`](./index.md#Reduction)<br />
)

</div>

Negative-log-likelihood loss over LOG-probabilities; class dim LAST.

$$
\ell = -x_{y}
$$

`input` is expected to already be log-probabilities (pair with [`log_softmax`](./log_softmax.md#log_softmax); [`cross_entropy`](./cross_entropy.md#cross_entropy) is the fused form).

**Parameters**

- `input`: log-probabilities `[.., C]`.
- `target`: class indices `[..]` (integer dtype).
- `weight`: optional per-class weight `[C]`.
- `ignore_index`: optional target value whose positions contribute no loss; absent = no masking.
- `reduction`: `None` / `Mean` / `Sum`; default `Mean`.

**Returns:** the loss (0-D under `Mean`/`Sum`; `[..]` under `None`).

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `target`'s shape is not `input`'s minus the class axis, or a target index is out of range.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 3105

</div>
