class_docstr: W-Transducer loss: RNN-T loss modification for training RNN-T model for the case
  when some text at the beginning/end of the utterance is missing.
  The resulting model behaves like the RNN-T model (no modification for decoding is required).
  For details see "Powerful and Extensible WFST Framework for RNN-Transducer Losses" paper
      https://ieeexplore.ieee.org/document/10096679
class_docstr_tok: ["W-Transducer","loss",":","RNN-T","loss","modification","for","training","RNN-T","model","for","the","case","when","some","text","at","the","beginning\/end","of","the","utterance","is","missing",".","The","resulting","model","behaves","like","the","RNN-T","model","(","no","modification","for","decoding","is","required",")",".","For","details","see","``","Powerful","and","Extensible","WFST","Framework","for","RNN-Transducer","Losses","''","paper","https",":","\/\/ieeexplore.ieee.org\/document\/10096679"]
docstr: Forward method is similar to RNN-T Graph-Transducer forward method,
  but we need to assign eps weight to eps-transitions.
docstr_tok: ["Forward","method","is","similar","to","RNN-T","Graph-Transducer","forward","method",",","but","we","need","to","assign","eps","weight","to","eps-transitions","."]
code: def forward(
      self,
      acts: torch.Tensor,
      labels: torch.Tensor,
      act_lens: torch.Tensor,
      label_lens: torch.Tensor,
  ):
      """
      Forward method is similar to RNN-T Graph-Transducer forward method,
      but we need to assign eps weight to eps-transitions.
      """
      # argument names are consistent with NeMo, see RNNTLoss.forward:
      # self._loss(acts=log_probs, labels=targets, act_lens=input_lengths, label_lens=target_lengths)
      logits, targets, logits_lengths, target_lengths = (
          acts,
          labels,
          act_lens,
          label_lens,
      )
  
      # logits: B x Time x Text+1 x C
      vocab_size = logits.shape[-1]
      target_fsas_vec = self.get_graphs_batched(
          logits_lengths, targets, target_lengths, vocab_size
      )
  
      cast_context = (
          force_float32_context()
          if self.cast_to_float32
          else nullcontext()
      )
      with cast_context:
          log_probs = F.log_softmax(logits, dim=-1)
          with torch.no_grad():
              indices = self.get_logits_indices(
                  target_fsas_vec, logits.shape
              )
              # transition to the last state + eps-transitions
              # use 0 index (for valid index_select) and manually assign score after index_select for this case
              indices[target_fsas_vec.labels == -1] = 0
              indices[target_fsas_vec.labels >= vocab_size] = 0  # eps
  
          # NB: do not assign scores -> modify, k2 will not update all scores correctly (modify -> assign)
          scores = log_probs.flatten().index_select(-1, indices)
          # fix weights for the arcs to the last state + eps-transitions
          scores[target_fsas_vec.labels == -1] = 0
          scores[
              target_fsas_vec.labels >= vocab_size
          ] = self.eps_weight  # eps
  
          target_fsas_vec.scores = scores
          scores = -1 * target_fsas_vec.get_tot_scores(
              use_double_scores=self.double_scores, log_semiring=True
          )
          return scores
  
file_path: NeMo/nemo/collections/asr/parts/k2/w_transducer.py
imports: from contextlib import nullcontext
  from typing import Union
  import torch
  import torch.nn.functional
  from nemo.collections.asr.parts.k2.graph_transducer import GraphRnntLoss, force_float32_context
  from nemo.core.utils.k2_guard import k2
  from nemo.utils.enum import PrettyStrEnum
label_desc: Use image node_id 5 for calling the GraphWTransducerLoss obj's underlying member method code with example usage: obj.forward(acts, labels, act_lens, label_lens) and returns: scores