class_docstr: Compute F-1 score.
  
  .. math::
      F_{1} = 2\frac{\text{precision} * \text{recall}}{(\text{precision}) + \text{recall}}
  
  The metric is only proper defined when :math:`\text{TP} + \text{FP} \neq 0 \wedge \text{TP} + \text{FN} \neq 0`
  where :math:`\text{TP}`, :math:`\text{FP}` and :math:`\text{FN}` represent the number of true positives, false
  positives and false negatives respectively. If this case is encountered for any class/label, the metric for that
  class/label will be set to 0 and the overall metric may therefore be affected in turn.
  
  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'``, ``'multiclass'`` or ``multilabel``. See the documentation of
  :class:`~torchmetrics.classification.BinaryF1Score`, :class:`~torchmetrics.classification.MulticlassF1Score` and
  :class:`~torchmetrics.classification.MultilabelF1Score` for the specific details of each argument influence and
  examples.
  
  Legacy Example:
      >>> from torch import tensor
      >>> target = tensor([0, 1, 2, 0, 1, 2])
      >>> preds = tensor([0, 2, 1, 0, 0, 1])
      >>> f1 = F1Score(task="multiclass", num_classes=3)
      >>> f1(preds, target)
      tensor(0.3333)
class_docstr_tok: ["Compute","F-1","score",".","..","math",":",":","F_","{","1","}","=","2\\frac","{","\\text","{","precision","}","*","\\text","{","recall","}","}","{","(","\\text","{","precision","}",")","+","\\text","{","recall","}","}","The","metric","is","only","proper","defined","when",":","math",":","`","\\text","{","TP","}","+","\\text","{","FP","}","\\neq","0","\\wedge","\\text","{","TP","}","+","\\text","{","FN","}","\\neq","0","`","where",":","math",":","`","\\text","{","TP","}","`",",",":","math",":","`","\\text","{","FP","}","`","and",":","math",":","`","\\text","{","FN","}","`","represent","the","number","of","true","positives",",","false","positives","and","false","negatives","respectively",".","If","this","case","is","encountered","for","any","class\/label",",","the","metric","for","that","class\/label","will","be","set","to","0","and","the","overall","metric","may","therefore","be","affected","in","turn",".","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","'","``",",","``","'multiclass","'","``","or","``","multilabel","``",".","See","the","documentation","of",":","class",":","`","~torchmetrics.classification.BinaryF1Score","`",",",":","class",":","`","~torchmetrics.classification.MulticlassF1Score","`","and",":","class",":","`","~torchmetrics.classification.MultilabelF1Score","`","for","the","specific","details","of","each","argument","influence","and","examples",".","Legacy","Example",":",">",">",">","from","torch","import","tensor",">",">",">","target","=","tensor","(","[","0",",","1",",","2",",","0",",","1",",","2","]",")",">",">",">","preds","=","tensor","(","[","0",",","2",",","1",",","0",",","0",",","1","]",")",">",">",">","f1","=","F1Score","(","task=","''","multiclass","''",",","num_classes=3",")",">",">",">","f1","(","preds",",","target",")","tensor","(","0.3333",")"]
docstr: Initialize task metric.
code: def __new__(
      cls: Type["F1Score"],
      task: Literal["binary", "multiclass", "multilabel"],
      threshold: float = 0.5,
      num_classes: Optional[int] = None,
      num_labels: Optional[int] = None,
      average: Optional[
          Literal["micro", "macro", "weighted", "none"]
      ] = "micro",
      multidim_average: Optional[
          Literal["global", "samplewise"]
      ] = "global",
      top_k: Optional[int] = 1,
      ignore_index: Optional[int] = None,
      validate_args: bool = True,
      **kwargs: Any,
  ) -> Metric:
      """Initialize task metric."""
      task = ClassificationTask.from_str(task)
      assert (
          multidim_average is not None
      )  # noqa: S101  # needed for mypy
      kwargs.update(
          {
              "multidim_average": multidim_average,
              "ignore_index": ignore_index,
              "validate_args": validate_args,
          }
      )
      if task == ClassificationTask.BINARY:
          return BinaryF1Score(threshold, **kwargs)
      if task == ClassificationTask.MULTICLASS:
          if not isinstance(num_classes, int):
              raise ValueError(
                  f"`num_classes` is expected to be `int` but `{type(num_classes)} was passed.`"
              )
          if not isinstance(top_k, int):
              raise ValueError(
                  f"`top_k` is expected to be `int` but `{type(top_k)} was passed.`"
              )
          return MulticlassF1Score(
              num_classes, top_k, average, **kwargs
          )
      if task == ClassificationTask.MULTILABEL:
          if not isinstance(num_labels, int):
              raise ValueError(
                  f"`num_labels` is expected to be `int` but `{type(num_labels)} was passed.`"
              )
          return MultilabelF1Score(
              num_labels, threshold, average, **kwargs
          )
      raise ValueError(f"Task {task} not supported!")
  
imports: from typing import Any, Optional, Sequence, Type, Union
  from torch import Tensor
  from typing_extensions import Literal
  from torchmetrics.classification.base import _ClassificationTaskWrapper
  from torchmetrics.classification.stat_scores import BinaryStatScores, MulticlassStatScores, MultilabelStatScores
  from torchmetrics.functional.classification.f_beta import _binary_fbeta_score_arg_validation, _fbeta_reduce, _multiclass_fbeta_score_arg_validation, _multilabel_fbeta_score_arg_validation
  from torchmetrics.metric import Metric
  from torchmetrics.utilities.enums import ClassificationTask
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE
label_desc: Use image node_id 1 for calling the F1Score obj's underlying member method code with example usage: obj.__new__(cls, task, threshold, num_classes, num_labels, average, multidim_average, top_k, ignore_index, validate_args) and returns: BinaryF1Score, MulticlassF1Score, MultilabelF1Score