code: def train_model_selection(
      training_features: np.ndarray,
      training_labels: np.ndarray,
      dev_features: Optional[np.ndarray] = None,
      dev_labels: Optional[np.ndarray] = None,
      tune_lr: bool = False,
      tune_lr_cfg: Optional[TuneLogisticRegressionConfig] = None,
      verbose: bool = False,
  ) -> Tuple[Pipeline, float]:
      """Trains model selection block with an (optional) tuning of the parameters.
  
      Returns a pipeline consisting of feature standardization and logistic
      regression. If tune_lr is set to True, dev features/labels will be used
      to tune the hyperparameters of the logistic regression with the grid
      search that's defined via ``tune_lr_cfg``.
  
      If no tuning is requested, uses the following parameters::
  
          best_pipe = make_pipeline(
              StandardScaler(),
              LogisticRegression(
                  multi_class="multinomial",
                  C=10000.0,
                  max_iter=1000,
                  class_weight="balanced",
              ),
          )
  
      Args:
          training_features: numpy array of features of shape [N x D], where N is
              the number of objects (typically a total number of utterances in
              all training datasets) and D is the total number of confidence
              scores used to train the model (typically = number of models).
          training_labels: numpy array of shape [N] contatining ground-truth
              model indices.
          dev_features: same as training, but for the validation subset.
          dev_labels: same as training, but for the validation subset.
          tune_lr: controls whether tuning of LR hyperparameters is performed.
              If set to True, it's required to also provide dev features/labels.
          tune_lr_cfg: specifies what values of LR hyperparameters to try.
          verbose: if True, will output final training/dev scores.
  
      Returns:
          tuple: trained model selection pipeline, best score (or -1 if no tuning
          was done).
      """
      if not tune_lr:
          # default parameters: C=10000.0 disables regularization
          best_pipe = make_pipeline(
              StandardScaler(),
              LogisticRegression(
                  multi_class="multinomial",
                  C=10000.0,
                  max_iter=1000,
                  class_weight="balanced",
              ),
          )
          max_score = -1
      else:
          C_pms = np.append(
              np.exp(
                  np.linspace(
                      np.log(tune_lr_cfg.C_min),
                      np.log(tune_lr_cfg.C_max),
                      tune_lr_cfg.C_num_points,
                  )
              ),
              10000.0,
          )
          max_score = 0
          best_pipe = None
          for class_weight in tune_lr_cfg.class_weight:
              for multi_class in tune_lr_cfg.multi_class:
                  for C in C_pms:
                      pipe = make_pipeline(
                          StandardScaler(),
                          LogisticRegression(
                              multi_class=multi_class,
                              C=C,
                              max_iter=tune_lr_cfg.max_iter,
                              class_weight=class_weight,
                          ),
                      )
                      pipe.fit(training_features, training_labels)
                      score, confusion = calculate_score(
                          dev_features, dev_labels, pipe
                      )
                      if score > max_score:
                          max_score = score
                          best_pipe = pipe
  
      best_pipe.fit(training_features, training_labels)
      if verbose:
          accuracy, confusion = calculate_score(
              training_features, training_labels, best_pipe
          )
          LOG.info("Training fit accuracy: %.4f", accuracy * 100.0)
          LOG.info("Training confusion matrix:\n%s", str(confusion))
      if dev_features is not None and verbose:
          accuracy, confusion = calculate_score(
              dev_features, dev_labels, best_pipe
          )
          LOG.info("Dev fit accuracy: %.4f", accuracy * 100.0)
          LOG.info("Dev confusion matrix:\n%s", str(confusion))
  
      return best_pipe, max_score
  
imports: import atexit
  import logging
  import os
  import random
  import sys
  import tempfile
  from copy import deepcopy
  from dataclasses import dataclass, field
  from pathlib import Path
  from typing import Dict, List, Optional, Tuple
  import joblib
  import numpy
  import pytorch_lightning
  from omegaconf import MISSING, DictConfig, OmegaConf
  from sklearn.linear_model import LogisticRegression
  from sklearn.metrics import confusion_matrix
  from sklearn.pipeline import Pipeline, make_pipeline
  from sklearn.preprocessing import StandardScaler
  from tqdm import tqdm
  from nemo.collections.asr.models.confidence_ensemble import ConfidenceEnsembleModel, ConfidenceSpec, compute_confidence, get_filtered_logprobs
  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.rnnt_utils import Hypothesis
  from nemo.core.config import hydra_runner
label_desc: Use image node_id 2 for calling a global function with example usage: train_model_selection(training_features, training_labels, dev_features, dev_labels, tune_lr, tune_lr_cfg, verbose) and returns: best_pipe,  max_score