class_docstr: k2 Mixin class that simplifies the construction of various k2-based CTC-like losses.
  
  It does the following:
      -   Prepares and adapts the input tensors (method _prepare_log_probs_and_targets).
      -   Creates Emissions graphs (method _prepare_emissions_graphs).
      -   Extracts the labels and probabilities of the best lattice path (method _extract_labels_and_probabilities).
class_docstr_tok: ["k2","Mixin","class","that","simplifies","the","construction","of","various","k2-based","CTC-like","losses",".","It","does","the","following",":","-","Prepares","and","adapts","the","input","tensors","(","method","_prepare_log_probs_and_targets",")",".","-","Creates","Emissions","graphs","(","method","_prepare_emissions_graphs",")",".","-","Extracts","the","labels","and","probabilities","of","the","best","lattice","path","(","method","_extract_labels_and_probabilities",")","."]
docstr: Extracts the labels and probabilities of the best lattice path,
  dropping <epsilon> arcs and restoring the targets shift, if needed.
docstr_tok: ["Extracts","the","labels","and","probabilities","of","the","best","lattice","path",",","dropping","<","epsilon",">","arcs","and","restoring","the","targets","shift",",","if","needed","."]
code: def _extract_labels_and_probabilities(
      self,
      shortest_path_fsas: "k2.Fsa",
      return_ilabels: bool = False,
      output_aligned: bool = True,
  ) -> Tuple[List[torch.Tensor], List[torch.Tensor]]:
      """Extracts the labels and probabilities of the best lattice path,
      dropping <epsilon> arcs and restoring the targets shift, if needed.
      """
      shortest_paths = []
      probs = []
      # direct iterating does not work as expected
      for i in range(shortest_path_fsas.shape[0]):
          shortest_path_fsa = shortest_path_fsas[i]
          # suppose that artificial input epsilon numbers >= self.num_classes
          non_eps_mask = (shortest_path_fsa.labels != -1) & (
              shortest_path_fsa.labels < self.num_classes
          )
          if return_ilabels:
              labels = shortest_path_fsa.labels[non_eps_mask]
          else:
              labels = shortest_path_fsa.aux_labels[non_eps_mask]
              if self.blank != 0:
                  # suppose output epsilon number == 0
                  # since the input epsilons were removed, we treat all remaining epsilons as blanks
                  labels[labels == 0] = self.blank
                  labels[(labels > 0) & (labels < self.blank)] -= 1
          labels = labels.to(dtype=torch.long)
          if not return_ilabels and not output_aligned:
              labels = labels[labels != self.blank]
          shortest_paths.append(labels)
          probs.append(
              get_arc_weights(shortest_path_fsa)[non_eps_mask]
              .exp()
              .to(device=shortest_path_fsas.device)
          )
      return shortest_paths, probs
  
file_path: NeMo/nemo/collections/asr/parts/k2/loss_mixins.py
imports: from abc import ABC
  from typing import List, Optional, Tuple
  import torch
  from nemo.collections.asr.parts.k2.grad_utils import GradExpNormalize
  from nemo.collections.asr.parts.k2.utils import create_supervision, get_arc_weights, get_uniform_rnnt_prune_ranges, make_non_pad_mask, make_non_pad_mask_3d, prep_padded_densefsavec
  from nemo.core.utils.k2_guard import k2
label_desc: Use image node_id 4 for calling the CtcK2Mixin obj's underlying member method code with example usage: obj._extract_labels_and_probabilities(shortest_path_fsas, return_ilabels, output_aligned) and returns: shortest_paths,  probs