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: Creates k2-style supervisions and shifts targets by one if the <blank> number is not zero.
          
docstr_tok: ["Creates","k2-style","supervisions","and","shifts","targets","by","one","if","the","<","blank",">","number","is","not","zero","."]
code: def _prepare_log_probs_and_targets(
      self,
      log_probs: torch.Tensor,
      input_lengths: torch.Tensor,
      targets: Optional[torch.Tensor] = None,
      target_lengths: Optional[torch.Tensor] = None,
  ) -> Tuple[
      torch.Tensor,
      torch.Tensor,
      Optional[torch.Tensor],
      Optional[torch.Tensor],
  ]:
      """Creates k2-style supervisions and shifts targets by one if the <blank> number is not zero."""
      assert log_probs.size(-1) == self.num_classes
      supervisions = create_supervision(input_lengths)
      # shift targets to make output epsilon ID zero
      return (
          log_probs,
          supervisions,
          torch.where(targets < self.blank, targets + 1, targets)
          if targets is not None
          else None,
          target_lengths,
      )
  
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 1 for calling the CtcK2Mixin obj's underlying member method code with example usage: obj._prepare_log_probs_and_targets(log_probs, input_lengths, targets, target_lengths) and returns: log_probs,  supervisions,  unknown,  target_lengths