class_docstr: k2 Mixin class that simplifies the construction of various k2-based RNNT-like losses. Inherits CtcK2Mixin.
  
  It does the following:
      -   Prepares and adapts the input tensors.
      -   Creates 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","RNNT-like","losses",".","Inherits","CtcK2Mixin",".","It","does","the","following",":","-","Prepares","and","adapts","the","input","tensors",".","-","Creates","Emissions","graphs",".","-","Extracts","the","labels","and","probabilities","of","the","best","lattice","path","(","method","_extract_labels_and_probabilities",")","."]
docstr: Overrides super()._prepare_emissions_graphs.
  Creates DenseFsaVec, adding <epsilon> outputs to the end of the D dimension.
  
  If pruning is used, this method also pads the DenseFsaVec with <epsilon> frames 
  according to the <epsilon> steps, calculated before.
  
  <epsilon> frame is a frame with <epsilon> log-probability zero and every other log-probability is -inf.
docstr_tok: ["Overrides","super","(",")","._prepare_emissions_graphs",".","Creates","DenseFsaVec",",","adding","<","epsilon",">","outputs","to","the","end","of","the","D","dimension",".","If","pruning","is","used",",","this","method","also","pads","the","DenseFsaVec","with","<","epsilon",">","frames","according","to","the","<","epsilon",">","steps",",","calculated","before",".","<","epsilon",">","frame","is","a","frame","with","<","epsilon",">","log-probability","zero","and","every","other","log-probability","is","-inf","."]
code: def _prepare_emissions_graphs(
      self, log_probs: torch.Tensor, supervisions: torch.Tensor
  ) -> "k2.DenseFsaVec":
      """Overrides super()._prepare_emissions_graphs.
      Creates DenseFsaVec, adding <epsilon> outputs to the end of the D dimension.
  
      If pruning is used, this method also pads the DenseFsaVec with <epsilon> frames
      according to the <epsilon> steps, calculated before.
  
      <epsilon> frame is a frame with <epsilon> log-probability zero and every other log-probability is -inf.
      """
      if self.__step_indices is None or self.__supervisions_add is None:
          log_probs_eps = torch.cat(
              (
                  log_probs,
                  torch.zeros(
                      (log_probs.size(0), log_probs.size(1), 1),
                      device=log_probs.device,
                  ),
              ),
              dim=2,
          )
      else:
          mask = torch.zeros(
              (
                  log_probs.size(0),
                  log_probs.size(1)
                  + int(
                      len(self.__step_indices[0]) / log_probs.size(0)
                  ),
              ),
              dtype=torch.bool,
          )
          mask[self.__step_indices] = True
          log_probs_eps = torch.zeros(
              (mask.size(0), mask.size(1), log_probs.size(2) + 1),
              device=log_probs.device,
          )
          log_probs_eps[mask] = torch.tensor(
              [torch.finfo(torch.float32).min] * log_probs.size(2)
              + [0],
              device=log_probs.device,
          )
          log_probs_eps[~mask] = torch.cat(
              (
                  log_probs,
                  torch.zeros(
                      (log_probs.size(0), log_probs.size(1), 1),
                      device=log_probs.device,
                  ),
              ),
              dim=2,
          ).view(-1, log_probs.size(-1) + 1)
          input_lengths = (
              supervisions[:, -1]
              + self.__supervisions_add[
                  supervisions[:, 0].to(dtype=torch.long)
              ]
          )
          if not torch.all(input_lengths[:-1] - input_lengths[1:] >= 0):
              # have to reorder supervisions inplace
              order = torch.argsort(input_lengths, descending=True)
              # the second column is assumed to be zero
              supervisions[:, 0] = supervisions[order, 0]
              supervisions[:, -1] = input_lengths[order]
          else:
              supervisions[:, -1] = input_lengths
          self.__step_indices = None
          self.__supervisions_add = None
      return k2.DenseFsaVec(log_probs_eps, supervisions)
  
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 2 for calling the RnntK2Mixin obj's underlying member method code with example usage: obj._prepare_emissions_graphs(log_probs, supervisions) and returns: k2