class_docstr: Implementation of the confidence ensemble model.
  
  See https://arxiv.org/abs/2306.15824 for details.
  
  .. note::
      Currently this class only support `transcribe` method as it requires
      full-utterance confidence scores to operate.
class_docstr_tok: ["Implementation","of","the","confidence","ensemble","model",".","See","https",":","\/\/arxiv.org\/abs\/2306.15824","for","details",".","..","note",":",":","Currently","this","class","only","support","`","transcribe","`","method","as","it","requires","full-utterance","confidence","scores","to","operate","."]
code: def __init__(
      self,
      cfg: DictConfig,
      trainer: "Trainer" = None,
  ):
      super().__init__(cfg=cfg, trainer=trainer)
  
      # either we load all models from ``load_models`` cfg parameter
      # or all of them are specified in the config as modelX alongside the num_models key
      #
      # ideally, we'd like to directly store all models in a list, but that
      # is not currently supported by the submodule logic
      # so to access all the models, we do something like
      #
      # for model_idx in range(self.num_models):
      #    model = getattr(self, f"model{model_idx}")
  
      if "num_models" in self.cfg:
          self.num_models = self.cfg.num_models
          for idx in range(self.num_models):
              cfg_field = f"model{idx}"
              model_cfg = self.cfg[cfg_field]
              model_class = model_utils.import_class_by_path(
                  model_cfg["target"]
              )
              self.register_nemo_submodule(
                  name=cfg_field,
                  config_field=cfg_field,
                  model=model_class(model_cfg, trainer=trainer),
              )
      else:
          self.num_models = len(cfg.load_models)
          with open_dict(self.cfg):
              self.cfg.num_models = self.num_models
          for idx, model in enumerate(cfg.load_models):
              cfg_field = f"model{idx}"
              if model.endswith(".nemo"):
                  self.register_nemo_submodule(
                      name=cfg_field,
                      config_field=cfg_field,
                      model=ASRModel.restore_from(
                          model, trainer=trainer, map_location="cpu"
                      ),
                  )
              else:
                  self.register_nemo_submodule(
                      cfg_field,
                      config_field=cfg_field,
                      model=ASRModel.from_pretrained(
                          model, map_location="cpu"
                      ),
                  )
  
      # registering model selection block - this is expected to be a joblib-saved
      # pretrained sklearn pipeline containing standardization + logistic regression
      # trained to predict "most-confident" model index from the confidence scores of all models
      model_selection_block_path = self.register_artifact(
          "model_selection_block", cfg.model_selection_block
      )
      self.model_selection_block = joblib.load(
          model_selection_block_path
      )
      self.confidence_cfg = ConfidenceConfig(**self.cfg.confidence)
  
      # making sure each model has correct temperature setting in the decoder strategy
      for model_idx in range(self.num_models):
          model = getattr(self, f"model{model_idx}")
          # for now we assume users are direclty responsible for matching
          # decoder type when building ensemble with inference type
          # TODO: add automatic checks for errors
          if isinstance(model, EncDecHybridRNNTCTCModel):
              self.update_decoding_parameters(model.cfg.decoding)
              model.change_decoding_strategy(
                  model.cfg.decoding, decoder_type="rnnt"
              )
              self.update_decoding_parameters(
                  model.cfg.aux_ctc.decoding
              )
              model.change_decoding_strategy(
                  model.cfg.aux_ctc.decoding, decoder_type="ctc"
              )
          else:
              self.update_decoding_parameters(model.cfg.decoding)
              model.change_decoding_strategy(model.cfg.decoding)
  
imports: from dataclasses import dataclass
  from typing import Dict, List, Optional, Union
  import joblib
  import numpy
  import torch
  from omegaconf import DictConfig, open_dict
  from pytorch_lightning import Trainer
  from nemo.collections.asr.models.asr_model import ASRModel
  from nemo.collections.asr.models.hybrid_rnnt_ctc_models import EncDecHybridRNNTCTCModel
  from nemo.collections.asr.parts.utils.asr_confidence_utils import ConfidenceConfig, ConfidenceMethodConfig, get_confidence_aggregation_bank, get_confidence_measure_bank
  from nemo.collections.asr.parts.utils.audio_utils import ChannelSelectorType
  from nemo.collections.asr.parts.utils.rnnt_utils import Hypothesis
  from nemo.core.classes import ModelPT
  from nemo.utils import model_utils
label_desc: Use image node_id 1 to create a new ConfidenceEnsembleModel object from inherited base classes: ModelPT with example: obj = ConfidenceEnsembleModel(cfg, trainer)