---
title: Hinge Loss
description: Compute the mean Hinge loss typically used for Support Vector Machines (SVMs).
canonical: 'https://lightning.ai/docs/torchmetrics/stable/classification/hinge_loss'
---
# Hinge Loss {#hinge-loss}

## Module Interface {#module-interface}

### `class torchmetrics.HingeLoss(**kwargs)` {#torchmetrics.HingeLoss}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/hinge.py#L326-L380)

Compute the mean [Hinge loss](https://en.wikipedia.org/wiki/Hinge_loss) typically used for Support Vector Machines (SVMs).

This function is a simple wrapper to get the task specific versions of this metric, which is done by setting the `task` argument to either `'binary'` or `'multiclass'`. See the documentation of [`BinaryHingeLoss`](#torchmetrics.classification.BinaryHingeLoss "torchmetrics.classification.BinaryHingeLoss") and [`MulticlassHingeLoss`](#torchmetrics.classification.MulticlassHingeLoss "torchmetrics.classification.MulticlassHingeLoss") for the specific details of each argument influence and examples.

Legacy Example:

```python
>>> from torch import tensor
>>> target = tensor([0, 1, 1])
>>> preds = tensor([0.5, 0.7, 0.1])
>>> hinge = HingeLoss(task="binary")
>>> hinge(preds, target)
tensor(0.9000)
```

```python
>>> target = tensor([0, 1, 2])
>>> preds = tensor([[-1.0, 0.9, 0.2], [0.5, -1.1, 0.8], [2.2, -0.5, 0.3]])
>>> hinge = HingeLoss(task="multiclass", num_classes=3)
>>> hinge(preds, target)
tensor(1.5551)
```

```python
>>> target = tensor([0, 1, 2])
>>> preds = tensor([[-1.0, 0.9, 0.2], [0.5, -1.1, 0.8], [2.2, -0.5, 0.3]])
>>> hinge = HingeLoss(task="multiclass", num_classes=3, multiclass_mode="one-vs-all")
>>> hinge(preds, target)
tensor([1.3743, 1.1945, 1.2359])
```

#### `static __new__(cls, task, num_classes=None, squared=False, multiclass_mode='crammer-singer', ignore_index=None, validate_args=True, **kwargs)` {#torchmetrics.HingeLoss.__new__}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/hinge.py#L356-L380)

Initialize task metric.

Return type:

[`Metric`](/docs/torchmetrics/1.9.0/api-reference/metric.md#torchmetrics.Metric "torchmetrics.metric.Metric")

### BinaryHingeLoss {#binaryhingeloss}

### `class torchmetrics.classification.BinaryHingeLoss(squared=False, ignore_index=None, validate_args=True, **kwargs)` {#torchmetrics.classification.BinaryHingeLoss}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/hinge.py#L42-L169)

Compute the mean [Hinge loss](https://en.wikipedia.org/wiki/Hinge_loss) typically used for Support Vector Machines (SVMs) for binary tasks.

```math
\text{Hinge loss} = \max(0, 1 - y \times \hat{y})
```

Where $`y \in {-1, 1}`$ is the target, and $`\hat{y} \in \mathbb{R}`$ is the prediction.

As input to `forward` and `update` the metric accepts the following input:

*   `preds` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A float tensor of shape `(N, ...)`. Preds should be a tensor containing probabilities or logits for each observation. If preds has values outside \[0,1\] range we consider the input to be logits and will auto apply sigmoid per element.
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): An int tensor of shape `(N, ...)`. Target should be a tensor containing ground truth labels, and therefore only contain {0,1} values (except if ignore\_index is specified). The value 1 always encodes the positive class.
    

Tip

Additional dimension `...` will be flattened into the batch dimension.

As output to `forward` and `compute` the metric returns the following output:

*   `bhl` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A tensor containing the hinge loss.
    

Parameters:

*   **squared** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If True, this will compute the squared hinge loss. Otherwise, computes the regular hinge loss.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Example

```python
>>> from torchmetrics.classification import BinaryHingeLoss
>>> preds = torch.tensor([0.25, 0.25, 0.55, 0.75, 0.75])
>>> target = torch.tensor([0, 0, 1, 1, 1])
>>> bhl = BinaryHingeLoss()
>>> bhl(preds, target)
tensor(0.6900)
>>> bhl = BinaryHingeLoss(squared=True)
>>> bhl(preds, target)
tensor(0.6905)
```

#### `plot(val=None, ax=None)` {#torchmetrics.classification.BinaryHingeLoss.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/hinge.py#L129-L169)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure object and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # Example plotting a single value
>>> from torch import rand, randint
>>> from torchmetrics.classification import BinaryHingeLoss
>>> metric = BinaryHingeLoss()
>>> metric.update(rand(10), randint(2,(10,)))
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/hinge\_loss-1.png](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-1.png)](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-1.png)

```python
>>> # Example plotting multiple values
>>> from torch import rand, randint
>>> from torchmetrics.classification import BinaryHingeLoss
>>> metric = BinaryHingeLoss()
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(rand(10), randint(2,(10,))))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/hinge\_loss-2.png](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-2.png)](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-2.png)

### MulticlassHingeLoss {#multiclasshingeloss}

### `class torchmetrics.classification.MulticlassHingeLoss(num_classes, squared=False, multiclass_mode='crammer-singer', ignore_index=None, validate_args=True, **kwargs)` {#torchmetrics.classification.MulticlassHingeLoss}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/hinge.py#L172-L323)

Compute the mean [Hinge loss](https://en.wikipedia.org/wiki/Hinge_loss) typically used for Support Vector Machines (SVMs) for multiclass tasks.

The metric can be computed in two ways. Either, the definition by Crammer and Singer is used:

```math
\text{Hinge loss} = \max\left(0, 1 - \hat{y}_y + \max_{i \ne y} (\hat{y}_i)\right)
```

Where $`y \in {0, ..., \mathrm{C}}`$ is the target class (where $`\mathrm{C}`$ is the number of classes), and $`\hat{y} \in \mathbb{R}^\mathrm{C}`$ is the predicted output per class. Alternatively, the metric can also be computed in one-vs-all approach, where each class is valued against all other classes in a binary fashion.

As input to `forward` and `update` the metric accepts the following input:

*   `preds` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A float tensor of shape `(N, C, ...)`. Preds should be a tensor containing probabilities or logits for each observation. If preds has values outside \[0,1\] range we consider the input to be logits and will auto apply softmax per sample.
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): An int tensor of shape `(N, ...)`. Target should be a tensor containing ground truth labels, and therefore only contain values in the \[0, n\_classes-1\] range (except if ignore\_index is specified).
    

Tip

Additional dimension `...` will be flattened into the batch dimension.

As output to `forward` and `compute` the metric returns the following output:

*   `mchl` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A tensor containing the multi-class hinge loss.
    

Parameters:

*   **num\_classes** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Integer specifying the number of classes
    
*   **squared** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If True, this will compute the squared hinge loss. Otherwise, computes the regular hinge loss.
    
*   **multiclass\_mode** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'crammer-singer'`, `'one-vs-all'`\]) – Determines how to compute the metric
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Example

```python
>>> from torchmetrics.classification import MulticlassHingeLoss
>>> preds = torch.tensor([[0.25, 0.20, 0.55],
...                       [0.55, 0.05, 0.40],
...                       [0.10, 0.30, 0.60],
...                       [0.90, 0.05, 0.05]])
>>> target = torch.tensor([0, 1, 2, 0])
>>> mchl = MulticlassHingeLoss(num_classes=3)
>>> mchl(preds, target)
tensor(0.9125)
>>> mchl = MulticlassHingeLoss(num_classes=3, squared=True)
>>> mchl(preds, target)
tensor(1.1131)
>>> mchl = MulticlassHingeLoss(num_classes=3, multiclass_mode='one-vs-all')
>>> mchl(preds, target)
tensor([0.8750, 1.1250, 1.1000])
```

#### `plot(val=None, ax=None)` {#torchmetrics.classification.MulticlassHingeLoss.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/hinge.py#L283-L323)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure object and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # Example plotting a single value per class
>>> from torch import randint, randn
>>> from torchmetrics.classification import MulticlassHingeLoss
>>> metric = MulticlassHingeLoss(num_classes=3)
>>> metric.update(randn(20, 3), randint(3, (20,)))
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/hinge\_loss-3.png](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-3.png)](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-3.png)

```python
>>> # Example plotting a multiple values per class
>>> from torch import randint, randn
>>> from torchmetrics.classification import MulticlassHingeLoss
>>> metric = MulticlassHingeLoss(num_classes=3)
>>> values = []
>>> for _ in range(20):
...     values.append(metric(randn(20, 3), randint(3, (20,))))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/hinge\_loss-4.png](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-4.png)](/docs/torchmetrics/1.9.0/static/_images/hinge_loss-4.png)

## Functional Interface {#functional-interface}

### `torchmetrics.functional.hinge_loss(preds, target, task, num_classes=None, squared=False, multiclass_mode='crammer-singer', ignore_index=None, validate_args=True)` {#torchmetrics.functional.hinge_loss}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/classification/hinge.py#L245-L288)

Compute the mean [Hinge loss](https://en.wikipedia.org/wiki/Hinge_loss) typically used for Support Vector Machines (SVMs).

This function is a simple wrapper to get the task specific versions of this metric, which is done by setting the `task` argument to either `'binary'` or `'multiclass'`. See the documentation of [`binary_hinge_loss()`](#torchmetrics.functional.classification.binary_hinge_loss "torchmetrics.functional.classification.binary_hinge_loss") and [`multiclass_hinge_loss()`](#torchmetrics.functional.classification.multiclass_hinge_loss "torchmetrics.functional.classification.multiclass_hinge_loss") for the specific details of each argument influence and examples.

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Legacy Example:

```python
>>> from torch import tensor
>>> target = tensor([0, 1, 1])
>>> preds = tensor([0.5, 0.7, 0.1])
>>> hinge_loss(preds, target, task="binary")
tensor(0.9000)
```

```python
>>> target = tensor([0, 1, 2])
>>> preds = tensor([[-1.0, 0.9, 0.2], [0.5, -1.1, 0.8], [2.2, -0.5, 0.3]])
>>> hinge_loss(preds, target, task="multiclass", num_classes=3)
tensor(1.5551)
```

```python
>>> target = tensor([0, 1, 2])
>>> preds = tensor([[-1.0, 0.9, 0.2], [0.5, -1.1, 0.8], [2.2, -0.5, 0.3]])
>>> hinge_loss(preds, target, task="multiclass", num_classes=3, multiclass_mode="one-vs-all")
tensor([1.3743, 1.1945, 1.2359])
```

### binary_hinge_loss {#binary-hinge-loss}

### `torchmetrics.functional.classification.binary_hinge_loss(preds, target, squared=False, ignore_index=None, validate_args=False)` {#torchmetrics.functional.classification.binary_hinge_loss}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/classification/hinge.py#L71-L123)

Compute the mean [Hinge loss](https://en.wikipedia.org/wiki/Hinge_loss) typically used for Support Vector Machines (SVMs) for binary tasks.

```math
\text{Hinge loss} = \max(0, 1 - y \times \hat{y})
```

Where $`y \in {-1, 1}`$ is the target, and $`\hat{y} \in \mathbb{R}`$ is the prediction.

Accepts the following input tensors:

*   `preds` (float tensor): `(N, ...)`. Preds should be a tensor containing probabilities or logits for each observation. If preds has values outside \[0,1\] range we consider the input to be logits and will auto apply sigmoid per element.
    
*   `target` (int tensor): `(N, ...)`. Target should be a tensor containing ground truth labels, and therefore only contain {0,1} values (except if ignore\_index is specified). The value 1 always encodes the positive class.
    

Additional dimension `...` will be flattened into the batch dimension.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with predictions
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with true labels
    
*   **squared** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If True, this will compute the squared hinge loss. Otherwise, computes the regular hinge loss.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Example

```python
>>> from torch import tensor
>>> from torchmetrics.functional.classification import binary_hinge_loss
>>> preds = tensor([0.25, 0.25, 0.55, 0.75, 0.75])
>>> target = tensor([0, 0, 1, 1, 1])
>>> binary_hinge_loss(preds, target)
tensor(0.6900)
>>> binary_hinge_loss(preds, target, squared=True)
tensor(0.6905)
```

### multiclass_hinge_loss {#multiclass-hinge-loss}

### `torchmetrics.functional.classification.multiclass_hinge_loss(preds, target, num_classes, squared=False, multiclass_mode='crammer-singer', ignore_index=None, validate_args=False)` {#torchmetrics.functional.classification.multiclass_hinge_loss}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/classification/hinge.py#L178-L242)

Compute the mean [Hinge loss](https://en.wikipedia.org/wiki/Hinge_loss) typically used for Support Vector Machines (SVMs) for multiclass tasks.

The metric can be computed in two ways. Either, the definition by Crammer and Singer is used:

```math
\text{Hinge loss} = \max\left(0, 1 - \hat{y}_y + \max_{i \ne y} (\hat{y}_i)\right)
```

Where $`y \in {0, ..., \mathrm{C}}`$ is the target class (where $`\mathrm{C}`$ is the number of classes), and $`\hat{y} \in \mathbb{R}^\mathrm{C}`$ is the predicted output per class. Alternatively, the metric can also be computed in one-vs-all approach, where each class is valued against all other classes in a binary fashion.

Accepts the following input tensors:

*   `preds` (float tensor): `(N, C, ...)`. Preds should be a tensor containing probabilities or logits for each observation. If preds has values outside \[0,1\] range we consider the input to be logits and will auto apply softmax per sample.
    
*   `target` (int tensor): `(N, ...)`. Target should be a tensor containing ground truth labels, and therefore only contain values in the \[0, n\_classes-1\] range (except if ignore\_index is specified).
    

Additional dimension `...` will be flattened into the batch dimension.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with predictions
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with true labels
    
*   **num\_classes** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Integer specifying the number of classes
    
*   **squared** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – If True, this will compute the squared hinge loss. Otherwise, computes the regular hinge loss.
    
*   **multiclass\_mode** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'crammer-singer'`, `'one-vs-all'`\]) – Determines how to compute the metric
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Example

```python
>>> from torch import tensor
>>> from torchmetrics.functional.classification import multiclass_hinge_loss
>>> preds = tensor([[0.25, 0.20, 0.55],
...                 [0.55, 0.05, 0.40],
...                 [0.10, 0.30, 0.60],
...                 [0.90, 0.05, 0.05]])
>>> target = tensor([0, 1, 2, 0])
>>> multiclass_hinge_loss(preds, target, num_classes=3)
tensor(0.9125)
>>> multiclass_hinge_loss(preds, target, num_classes=3, squared=True)
tensor(1.1131)
>>> multiclass_hinge_loss(preds, target, num_classes=3, multiclass_mode='one-vs-all')
tensor([0.8750, 1.1250, 1.1000])
```

---

**Navigation**

- Parent: [Classification](/docs/torchmetrics/1.9.0/classification.md)
