class_docstr: This metric computes the number of True Positive, False Negative, and False Positive examples per class.
  When doing distributed training/evaluation the result of res=ClassificationReport(predictions, labels) calls
  will be all-reduced between all workers using SUM operations.
  
  If used with PytorchLightning LightningModule, include TPs, FNs, and FPs inside validation_step results.
  Then aggregate them at the end of validation epoch to correctly compute validation precision, recall, f1
  using get_precision_recall_f1().
  
  Example:
      def validation_step(self, batch, batch_idx):
          ...
          tp, fn, fp, _ = self.classification_report(preds, labels)
  
          return {'val_loss': val_loss, 'tp': tp, 'fn': fn, 'fp': fp}
  
      def on_validation_epoch_end(self):
          ...
          # calculate metrics and classification report
          precision, recall, f1, report = self.classification_report.compute()
  
          logging.info(report)
  
          self.log('val_loss', avg_loss, prog_bar=True)
          self.log('precision', precision)
          self.log('f1', f1)
          self.log('recall', recall)
  
  Args:
      num_classes: number of classes in the dataset
      label_ids (optional): label name to label id mapping
      mode: how to compute the average
      dist_sync_on_step: sync across ddp
      process_group: which processes to sync across
  Return:
      aggregated precision, recall, f1, report
class_docstr_tok: ["This","metric","computes","the","number","of","True","Positive",",","False","Negative",",","and","False","Positive","examples","per","class",".","When","doing","distributed","training\/evaluation","the","result","of","res=ClassificationReport","(","predictions",",","labels",")","calls","will","be","all-reduced","between","all","workers","using","SUM","operations",".","If","used","with","PytorchLightning","LightningModule",",","include","TPs",",","FNs",",","and","FPs","inside","validation_step","results",".","Then","aggregate","them","at","the","end","of","validation","epoch","to","correctly","compute","validation","precision",",","recall",",","f1","using","get_precision_recall_f1","(",")",".","Example",":","def","validation_step","(","self",",","batch",",","batch_idx",")",":","...","tp",",","fn",",","fp",",","_","=","self.classification_report","(","preds",",","labels",")","return","{","'val_loss","'",":","val_loss",",","'tp","'",":","tp",",","'fn","'",":","fn",",","'fp","'",":","fp","}","def","on_validation_epoch_end","(","self",")",":","...","#","calculate","metrics","and","classification","report","precision",",","recall",",","f1",",","report","=","self.classification_report.compute","(",")","logging.info","(","report",")","self.log","(","'val_loss","'",",","avg_loss",",","prog_bar=True",")","self.log","(","'precision","'",",","precision",")","self.log","(","'f1","'",",","f1",")","self.log","(","'recall","'",",","recall",")","Args",":","num_classes",":","number","of","classes","in","the","dataset","label_ids","(","optional",")",":","label","name","to","label","id","mapping","mode",":","how","to","compute","the","average","dist_sync_on_step",":","sync","across","ddp","process_group",":","which","processes","to","sync","across","Return",":","aggregated","precision",",","recall",",","f1",",","report"]
code: def __init__(
      self,
      num_classes: int,
      label_ids: Dict[str, int] = None,
      mode: str = "macro",
      dist_sync_on_step: bool = False,
      process_group: Optional[Any] = None,
  ):
      super().__init__(
          dist_sync_on_step=dist_sync_on_step,
          process_group=process_group,
      )
      self.num_classes = num_classes
      if label_ids:
          self.ids_to_labels = {v: k for k, v in label_ids.items()}
      else:
          self.ids_to_labels = None
      self.mode = mode
  
      self.add_state(
          "tp",
          default=torch.zeros(num_classes),
          dist_reduce_fx="sum",
          persistent=False,
      )
      self.add_state(
          "fn",
          default=torch.zeros(num_classes),
          dist_reduce_fx="sum",
          persistent=False,
      )
      self.add_state(
          "fp",
          default=torch.zeros(num_classes),
          dist_reduce_fx="sum",
          persistent=False,
      )
      self.add_state(
          "num_examples_per_class",
          default=torch.zeros(num_classes),
          dist_reduce_fx="sum",
          persistent=False,
      )
  
file_path: NeMo/nemo/collections/nlp/metrics/classification_report.py
imports: from typing import Any, Dict, Optional, Tuple
  import torch
  from torchmetrics import Metric
  from torchmetrics.utilities.data import METRIC_EPS
label_desc: Use image node_id 1 to create a new ClassificationReport object from inherited base classes: Metric with example: obj = ClassificationReport(num_classes, label_ids, mode, dist_sync_on_step, process_group)