code: def main(cfg: EvaluationConfig):
      torch.set_grad_enabled(False)
  
      if is_dataclass(cfg):
          cfg = OmegaConf.structured(cfg)
  
      if cfg.audio_dir is not None:
          raise RuntimeError(
              "Evaluation script requires ground truth labels to be passed via a manifest file. "
              "If manifest file is available, submit it via `dataset_manifest` argument."
          )
  
      if not os.path.exists(cfg.dataset_manifest):
          raise FileNotFoundError(
              f"The dataset manifest file could not be found at path : {cfg.dataset_manifest}"
          )
  
      if not cfg.only_score_manifest:
          # Transcribe speech into an output directory
          transcription_cfg = transcribe_speech.main(
              cfg
          )  # type: EvaluationConfig
  
          # Release GPU memory if it was used during transcription
          if torch.cuda.is_available():
              torch.cuda.empty_cache()
  
          logging.info(
              "Finished transcribing speech dataset. Computing ASR metrics.."
          )
  
      else:
          cfg.output_filename = cfg.dataset_manifest
          transcription_cfg = cfg
  
      ground_truth_text = []
      predicted_text = []
      invalid_manifest = False
      with open(transcription_cfg.output_filename, "r") as f:
          for line in f:
              data = json.loads(line)
  
              if "pred_text" not in data:
                  invalid_manifest = True
                  break
  
              ground_truth_text.append(data["text"])
  
              predicted_text.append(data["pred_text"])
  
      pc = PunctuationCapitalization(
          cfg.text_processing.punctuation_marks
      )
      if cfg.text_processing.separate_punctuation:
          ground_truth_text = pc.separate_punctuation(ground_truth_text)
          predicted_text = pc.separate_punctuation(predicted_text)
      if cfg.text_processing.do_lowercase:
          ground_truth_text = pc.do_lowercase(ground_truth_text)
          predicted_text = pc.do_lowercase(predicted_text)
      if cfg.text_processing.rm_punctuation:
          ground_truth_text = pc.rm_punctuation(ground_truth_text)
          predicted_text = pc.rm_punctuation(predicted_text)
  
      # Test for invalid manifest supplied
      if invalid_manifest:
          raise ValueError(
              f"Invalid manifest provided: {transcription_cfg.output_filename} does not "
              f"contain value for `pred_text`."
          )
  
      if cfg.use_punct_er:
          dper_obj = DatasetPunctuationErrorRate(
              hypotheses=predicted_text,
              references=ground_truth_text,
              punctuation_marks=list(
                  cfg.text_processing.punctuation_marks
              ),
          )
          dper_obj.compute()
  
      if cfg.scores_per_sample:
          metrics_to_compute = ["wer", "cer"]
  
          if cfg.use_punct_er:
              metrics_to_compute.append("punct_er")
  
          samples_with_metrics = compute_metrics_per_sample(
              manifest_path=cfg.dataset_manifest,
              reference_field="text",
              hypothesis_field="pred_text",
              metrics=metrics_to_compute,
              punctuation_marks=cfg.text_processing.punctuation_marks,
              output_manifest_path=cfg.output_filename,
          )
  
      # Compute the WER
      cer = word_error_rate(
          hypotheses=predicted_text,
          references=ground_truth_text,
          use_cer=True,
      )
      wer = word_error_rate(
          hypotheses=predicted_text,
          references=ground_truth_text,
          use_cer=False,
      )
  
      if cfg.use_cer:
          metric_name = "CER"
          metric_value = cer
      else:
          metric_name = "WER"
          metric_value = wer
  
      if cfg.tolerance is not None:
          if metric_value > cfg.tolerance:
              raise ValueError(
                  f"Got {metric_name} of {metric_value}, which was higher than tolerance={cfg.tolerance}"
              )
  
          logging.info(
              f"Got {metric_name} of {metric_value}. Tolerance was {cfg.tolerance}"
          )
  
      logging.info(
          f"Dataset WER/CER "
          + str(round(100 * wer, 2))
          + "%/"
          + str(round(100 * cer, 2))
          + "%"
      )
  
      if cfg.use_punct_er:
          dper_obj.print()
          dper_obj.reset()
  
      # Inject the metric name and score into the config, and return the entire config
      with open_dict(cfg):
          cfg.metric_name = metric_name
          cfg.metric_value = metric_value
  
      return cfg
  
file_path: NeMo/examples/asr/speech_to_text_eval.py
imports: import json
  import os
  from dataclasses import dataclass, is_dataclass
  from typing import Optional
  import torch
  import transcribe_speech
  from omegaconf import MISSING, OmegaConf, open_dict
  from nemo.collections.asr.metrics.wer import word_error_rate
  from nemo.collections.asr.parts.utils.transcribe_utils import PunctuationCapitalization, TextProcessingConfig, compute_metrics_per_sample
  from nemo.collections.common.metrics.punct_er import DatasetPunctuationErrorRate
  from nemo.core.config import hydra_runner
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling a global function with example usage: main(cfg) and returns: cfg