class_docstr: This metric computes the number of True Positive, False Negative, and False Positive examples per class for
  a multi-label dataset.
  
  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","for","a","multi-label","dataset",".","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"]
docstr: Updates attributes needed for new classification report (true positive, false negative, false postive, examples per class)
  
  Args:
      predictions: predicted labels 
      labels: actual labels
  
  Return:
      None
docstr_tok: ["Updates","attributes","needed","for","new","classification","report","(","true","positive",",","false","negative",",","false","postive",",","examples","per","class",")","Args",":","predictions",":","predicted","labels","labels",":","actual","labels","Return",":","None"]
code: def update(
      self, predictions: torch.Tensor, labels: torch.Tensor
  ) -> None:
      """
      Updates attributes needed for new classification report (true positive, false negative, false postive, examples per class)
  
      Args:
          predictions: predicted labels
          labels: actual labels
  
      Return:
          None
      """
      predictions = predictions.t()
  
      TP = []
      FN = []
      FP = []
  
      for label_id in range(self.num_classes):
          current_label = labels[label_id]
          labels_predicted = predictions[label_id]
          TP.append(
              (labels_predicted == current_label)[
                  labels_predicted == 1
              ].sum()
          )
          FP.append(
              (labels_predicted != current_label)[
                  labels_predicted == 1
              ].sum()
          )
          FN.append(
              (labels_predicted != current_label)[
                  current_label == 1
              ].sum()
          )
  
      tp = torch.tensor(TP).to(predictions.device)
      fn = torch.tensor(FN).to(predictions.device)
      fp = torch.tensor(FP).to(predictions.device)
      num_examples_per_class = tp + fn
  
      self.tp += tp
      self.fn += fn
      self.fp += fp
      self.num_examples_per_class += num_examples_per_class
  
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 for calling the MultiLabelClassificationReport obj's underlying member method code with example usage: obj.update(predictions, labels) without return types