code: def get_filtered_logprobs(
      hypothesis: Hypothesis, exclude_blank: bool
  ) -> torch.Tensor:
      """Returns logprobs from the hypothesis object with optional blanks filter.
  
      This function supports both CTC and Transducer hypotheses. Will place the
      logprobs on GPU if it's available.
  
      Args:
          hypothesis: generated hypothesis as returned from the transcribe
              method of the ASR model.
          exclude_blank: whether to filter out all ``<blank>`` tokens.
  
      Returns:
          torch.Tensor: of shape [S, V], where S is (filtered) sequence length and
          V is the vocabulary size.
      """
      if isinstance(hypothesis.alignments, list):  # Transducer
          filtered_logprobs = []
          for alignment in hypothesis.alignments:
              for align_elem in alignment:
                  if not exclude_blank:
                      filtered_logprobs.append(align_elem[0])
                  elif (
                      align_elem[1].item()
                      != align_elem[0].shape[-1] - 1
                  ):
                      filtered_logprobs.append(align_elem[0])
          if not filtered_logprobs:  # for the edge-case of all blanks
              filtered_logprobs.append(align_elem[0])
          filtered_logprobs = torch.stack(filtered_logprobs)
          if (
              torch.cuda.is_available()
          ):  # by default logprobs are placed on cpu in nemo
              filtered_logprobs = filtered_logprobs.cuda()
      else:  # CTC
          logprobs = hypothesis.y_sequence
          if (
              torch.cuda.is_available()
          ):  # by default logprobs are placed on cpu in nemo
              logprobs = logprobs.cuda()
          if exclude_blank:  # filtering blanks
              labels = logprobs.argmax(dim=-1)
              filtered_logprobs = logprobs[
                  labels != logprobs.shape[1] - 1
              ]
              if (
                  filtered_logprobs.shape[0] == 0
              ):  # for the edge-case of all blanks
                  filtered_logprobs = logprobs[:1]
          else:
              filtered_logprobs = logprobs
  
      # need to make sure logprobs are always normalized, so checking if they sum up to 1
      if not torch.allclose(
          filtered_logprobs[0].exp().sum(), torch.tensor(1.0)
      ):
          filtered_logprobs = torch.log_softmax(
              filtered_logprobs, dim=1
          )
  
      return filtered_logprobs
  
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 for calling a global function with example usage: get_filtered_logprobs(hypothesis, exclude_blank) and returns: filtered_logprobs