code: def hinge_loss(
      preds: Tensor,
      target: Tensor,
      task: Literal["binary", "multiclass"],
      num_classes: Optional[int] = None,
      squared: bool = False,
      multiclass_mode: Literal[
          "crammer-singer", "one-vs-all"
      ] = "crammer-singer",
      ignore_index: Optional[int] = None,
      validate_args: bool = True,
  ) -> Tensor:
      r"""Compute the mean `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
      :func:`~torchmetrics.functional.classification.binary_hinge_loss` and
      :func:`~torchmetrics.functional.classification.multiclass_hinge_loss` for the specific details of
      each argument influence and examples.
  
      Legacy Example:
          >>> 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)
  
          >>> 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)
  
          >>> 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])
  
      """
      task = ClassificationTaskNoMultilabel.from_str(task)
      if task == ClassificationTaskNoMultilabel.BINARY:
          return binary_hinge_loss(
              preds, target, squared, ignore_index, validate_args
          )
      if task == ClassificationTaskNoMultilabel.MULTICLASS:
          if not isinstance(num_classes, int):
              raise ValueError(
                  f"`num_classes` is expected to be `int` but `{type(num_classes)} was passed.`"
              )
          return multiclass_hinge_loss(
              preds,
              target,
              num_classes,
              squared,
              multiclass_mode,
              ignore_index,
              validate_args,
          )
      raise ValueError(f"Not handled value: {task}")
  
file_path: torchmetrics/src/torchmetrics/functional/classification/hinge.py
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor, tensor
  from typing_extensions import Literal
  from torchmetrics.functional.classification.confusion_matrix import _binary_confusion_matrix_format, _binary_confusion_matrix_tensor_validation, _multiclass_confusion_matrix_format, _multiclass_confusion_matrix_tensor_validation
  from torchmetrics.utilities.data import to_onehot
  from torchmetrics.utilities.enums import ClassificationTaskNoMultilabel
label_desc: Use image node_id 10 for calling a global function with example usage: hinge_loss(preds, target, task, num_classes, squared, multiclass_mode, ignore_index, validate_args) and returns: binary_hinge_loss, multiclass_hinge_loss