class_docstr: This metric computes numerator and denominator for Overall Word Error Rate (WER) between prediction and reference
  texts. When doing distributed training/evaluation the result of ``res=WER(predictions, predictions_lengths, targets, target_lengths)``
  calls will be all-reduced between all workers using SUM operations. Here ``res`` contains three numbers
  ``res=[wer, total_levenstein_distance, total_number_of_words]``.
  
  If used with PytorchLightning LightningModule, include wer_numerator and wer_denominators inside validation_step
  results. Then aggregate (sum) then at the end of validation epoch to correctly compute validation WER.
  
  Example:
      def validation_step(self, batch, batch_idx):
          ...
          wer_num, wer_denom = self.__wer(predictions, predictions_len, transcript, transcript_len)
          self.val_outputs = {'val_loss': loss_value, 'val_wer_num': wer_num, 'val_wer_denom': wer_denom}
          return self.val_outputs
  
      def on_validation_epoch_end(self):
          ...
          wer_num = torch.stack([x['val_wer_num'] for x in self.val_outputs]).sum()
          wer_denom = torch.stack([x['val_wer_denom'] for x in self.val_outputs]).sum()
          tensorboard_logs = {'validation_loss': val_loss_mean, 'validation_avg_wer': wer_num / wer_denom}
          self.val_outputs.clear()  # free memory
          return {'val_loss': val_loss_mean, 'log': tensorboard_logs}
  
  Args:
      decoding: An instance of CTCDecoding or RNNTDecoding.
      use_cer: Whether to use Character Error Rate instead of Word Error Rate.
      log_prediction: Whether to log a single decoded sample per call.
      batch_dim_index: Index corresponding to batch dimension. (For RNNT.)
      dist_dync_on_step: Whether to perform reduction on forward pass of metric.
  
  Returns:
      res: a tuple of 3 zero dimensional float32 ``torch.Tensor` objects: a WER score, a sum of Levenstein's
          distances for all prediction - reference pairs, total number of words in all references.
class_docstr_tok: ["This","metric","computes","numerator","and","denominator","for","Overall","Word","Error","Rate","(","WER",")","between","prediction","and","reference","texts",".","When","doing","distributed","training\/evaluation","the","result","of","``","res=WER","(","predictions",",","predictions_lengths",",","targets",",","target_lengths",")","``","calls","will","be","all-reduced","between","all","workers","using","SUM","operations",".","Here","``","res","``","contains","three","numbers","``","res=","[","wer",",","total_levenstein_distance",",","total_number_of_words","]","``",".","If","used","with","PytorchLightning","LightningModule",",","include","wer_numerator","and","wer_denominators","inside","validation_step","results",".","Then","aggregate","(","sum",")","then","at","the","end","of","validation","epoch","to","correctly","compute","validation","WER",".","Example",":","def","validation_step","(","self",",","batch",",","batch_idx",")",":","...","wer_num",",","wer_denom","=","self.__wer","(","predictions",",","predictions_len",",","transcript",",","transcript_len",")","self.val_outputs","=","{","'val_loss","'",":","loss_value",",","'val_wer_num","'",":","wer_num",",","'val_wer_denom","'",":","wer_denom","}","return","self.val_outputs","def","on_validation_epoch_end","(","self",")",":","...","wer_num","=","torch.stack","(","[","x","[","'val_wer_num","'","]","for","x","in","self.val_outputs","]",")",".sum","(",")","wer_denom","=","torch.stack","(","[","x","[","'val_wer_denom","'","]","for","x","in","self.val_outputs","]",")",".sum","(",")","tensorboard_logs","=","{","'validation_loss","'",":","val_loss_mean",",","'validation_avg_wer","'",":","wer_num","\/","wer_denom","}","self.val_outputs.clear","(",")","#","free","memory","return","{","'val_loss","'",":","val_loss_mean",",","'log","'",":","tensorboard_logs","}","Args",":","decoding",":","An","instance","of","CTCDecoding","or","RNNTDecoding",".","use_cer",":","Whether","to","use","Character","Error","Rate","instead","of","Word","Error","Rate",".","log_prediction",":","Whether","to","log","a","single","decoded","sample","per","call",".","batch_dim_index",":","Index","corresponding","to","batch","dimension",".","(","For","RNNT",".",")","dist_dync_on_step",":","Whether","to","perform","reduction","on","forward","pass","of","metric",".","Returns",":","res",":","a","tuple","of","3","zero","dimensional","float32","``","torch.Tensor","`","objects",":","a","WER","score",",","a","sum","of","Levenstein's","distances","for","all","prediction","-","reference","pairs",",","total","number","of","words","in","all","references","."]
docstr: Updates metric state.
  Args:
      predictions: an integer torch.Tensor of shape ``[Batch, Time, {Vocabulary}]`` (if ``batch_dim_index == 0``) or
          ``[Time, Batch]`` (if ``batch_dim_index == 1``)
      prediction_lengths: an integer torch.Tensor of shape ``[Batch]``
      targets: an integer torch.Tensor of shape ``[Batch, Time]`` (if ``batch_dim_index == 0``) or
          ``[Time, Batch]`` (if ``batch_dim_index == 1``)
      target_lengths: an integer torch.Tensor of shape ``[Batch]``
      predictions_lengths: an integer torch.Tensor of shape ``[Batch]``
docstr_tok: ["Updates","metric","state",".","Args",":","predictions",":","an","integer","torch.Tensor","of","shape","``","[","Batch",",","Time",",","{","Vocabulary","}","]","``","(","if","``","batch_dim_index","==","0","``",")","or","``","[","Time",",","Batch","]","``","(","if","``","batch_dim_index","==","1","``",")","prediction_lengths",":","an","integer","torch.Tensor","of","shape","``","[","Batch","]","``","targets",":","an","integer","torch.Tensor","of","shape","``","[","Batch",",","Time","]","``","(","if","``","batch_dim_index","==","0","``",")","or","``","[","Time",",","Batch","]","``","(","if","``","batch_dim_index","==","1","``",")","target_lengths",":","an","integer","torch.Tensor","of","shape","``","[","Batch","]","``","predictions_lengths",":","an","integer","torch.Tensor","of","shape","``","[","Batch","]","``"]
code: def update(
      self,
      predictions: torch.Tensor,
      predictions_lengths: torch.Tensor,
      targets: torch.Tensor,
      targets_lengths: torch.Tensor,
  ):
      """
      Updates metric state.
      Args:
          predictions: an integer torch.Tensor of shape ``[Batch, Time, {Vocabulary}]`` (if ``batch_dim_index == 0``) or
              ``[Time, Batch]`` (if ``batch_dim_index == 1``)
          prediction_lengths: an integer torch.Tensor of shape ``[Batch]``
          targets: an integer torch.Tensor of shape ``[Batch, Time]`` (if ``batch_dim_index == 0``) or
              ``[Time, Batch]`` (if ``batch_dim_index == 1``)
          target_lengths: an integer torch.Tensor of shape ``[Batch]``
          predictions_lengths: an integer torch.Tensor of shape ``[Batch]``
      """
      words = 0
      scores = 0
      references = []
      with torch.no_grad():
          tgt_lenths_cpu_tensor = targets_lengths.long().cpu()
          targets_cpu_tensor = targets.long().cpu()
          # check batch_dim_index is first dim
          if self.batch_dim_index != 0:
              targets_cpu_tensor = move_dimension_to_the_front(
                  targets_cpu_tensor, self.batch_dim_index
              )
          # iterate over batch
          for ind in range(targets_cpu_tensor.shape[0]):
              tgt_len = tgt_lenths_cpu_tensor[ind].item()
              target = (
                  targets_cpu_tensor[ind][:tgt_len].numpy().tolist()
              )
              reference = self.decoding.decode_tokens_to_str(target)
              references.append(reference)
          hypotheses, _ = self.decode(predictions, predictions_lengths)
  
      if self.log_prediction:
          logging.info(f"\n")
          logging.info(f"reference:{references[0]}")
          logging.info(f"predicted:{hypotheses[0]}")
  
      for h, r in zip(hypotheses, references):
          if self.use_cer:
              h_list = list(h)
              r_list = list(r)
          else:
              h_list = h.split()
              r_list = r.split()
          words += len(r_list)
          # Compute Levenstein's distance
          scores += editdistance.eval(h_list, r_list)
  
      self.scores = torch.tensor(
          scores, device=self.scores.device, dtype=self.scores.dtype
      )
      self.words = torch.tensor(
          words, device=self.words.device, dtype=self.words.dtype
      )
  
file_path: NeMo/nemo/collections/asr/metrics/wer.py
imports: from typing import List, Tuple, Union
  import editdistance
  import jiwer
  import torch
  from torchmetrics import Metric
  from nemo.collections.asr.parts.submodules.ctc_decoding import AbstractCTCDecoding
  from nemo.collections.asr.parts.submodules.rnnt_decoding import AbstractRNNTDecoding
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling the WER obj's underlying member method code with example usage: obj.update(predictions, predictions_lengths, targets, targets_lengths) without return types