code: def cal_write_wer(
      pred_manifest: str = None,
      gt_text_attr_name: str = "text",
      pred_text_attr_name: str = "pred_text",
      clean_groundtruth_text: bool = False,
      langid: str = "en",
      use_cer: bool = False,
      output_filename: str = None,
      ignore_capitalization: bool = False,
      ignore_punctuation: bool = False,
      punctuations: Optional[list] = None,
  ) -> Tuple[str, dict, str]:
      """
      Calculate wer, inserion, deletion and substitution rate based on groundtruth text and pred_text_attr_name (pred_text)
      We use WER in function name as a convention, but Error Rate (ER) currently support Word Error Rate (WER) and Character Error Rate (CER)
      """
      samples = []
      hyps = []
      refs = []
      eval_metric = "cer" if use_cer else "wer"
  
      with open(pred_manifest, "r") as fp:
          for line in fp:
              sample = json.loads(line)
  
              if gt_text_attr_name not in sample:
                  if "text" in sample:
                      gt_text_attr_name = "text"
                  else:
                      logging.info(
                          f"ground-truth text attribute {gt_text_attr_name} is not present in manifest! Cannot calculate WER. Returning!"
                      )
                  return None, None, eval_metric
  
              hyp = sample[pred_text_attr_name].strip()
              ref = sample[gt_text_attr_name].strip()
  
              if clean_groundtruth_text:
                  ref = clean_label(ref, langid=langid)
  
              if ignore_punctuation:
                  ref = remove_punctuations(
                      ref, punctuations=punctuations
                  )
                  hyp = remove_punctuations(
                      hyp, punctuations=punctuations
                  )
  
              if ignore_capitalization:
                  ref = ref.lower()
                  hyp = hyp.lower()
  
              (
                  wer,
                  tokens,
                  ins_rate,
                  del_rate,
                  sub_rate,
              ) = word_error_rate_detail(
                  hypotheses=[hyp], references=[ref], use_cer=use_cer
              )
              sample[
                  eval_metric
              ] = wer  # evaluatin metric, could be word error rate of character error rate
              sample[
                  "tokens"
              ] = tokens  # number of word/characters/tokens
              sample["ins_rate"] = ins_rate  # insertion error rate
              sample["del_rate"] = del_rate  # deletion error rate
              sample["sub_rate"] = sub_rate  # substitution error rate
  
              samples.append(sample)
              hyps.append(hyp)
              refs.append(ref)
  
      (
          total_wer,
          total_tokens,
          total_ins_rate,
          total_del_rate,
          total_sub_rate,
      ) = word_error_rate_detail(
          hypotheses=hyps, references=refs, use_cer=use_cer
      )
  
      if not output_filename:
          output_manifest_w_wer = pred_manifest
      else:
          output_manifest_w_wer = output_filename
  
      with open(output_manifest_w_wer, "w") as fout:
          for sample in samples:
              json.dump(sample, fout)
              fout.write("\n")
              fout.flush()
  
      total_res = {
          "samples": len(samples),
          "tokens": total_tokens,
          eval_metric: total_wer,
          "ins_rate": total_ins_rate,
          "del_rate": total_del_rate,
          "sub_rate": total_sub_rate,
      }
      return output_manifest_w_wer, total_res, eval_metric
  
file_path: NeMo/nemo/collections/asr/parts/utils/eval_utils.py
imports: import json
  from typing import Optional, Tuple, Union
  from torchmetrics.text import SacreBLEUScore
  from torchmetrics.text.rouge import ROUGEScore
  from nemo.collections.asr.metrics.wer import word_error_rate_detail
  from nemo.utils import logging
  from nemo.utils.nemo_logging import LogMode
label_desc: Use image node_id 4 for calling a global function with example usage: cal_write_wer(pred_manifest, gt_text_attr_name, pred_text_attr_name, clean_groundtruth_text, langid, use_cer, output_filename, ignore_capitalization, ignore_punctuation, punctuations) and returns: output_manifest_w_wer,  total_res,  eval_metric, None,  None,  eval_metric