class_docstr: Maximum a Posteriori Probability criterion.
  It implements Lattice-Free Maximum Mutual Information (LF-MMI) and LF-boosted-MMI (LF-bMMI) losses.
  
  Based on https://github.com/k2-fsa/snowfall/blob/master/snowfall/objectives/mmi.py
  
  cfg takes precedence over all optional parameters
  We keep explicit parameter setting to be able to create an instance without the need of a config.
docstr: Intersects emissions_graphs with supervision_graphs and calculates lattice scores.
  This version implicitly assumes supervision_graphs to be a pair of the numerator and the denominator FSAs.
  
  It can also calculate accuracy between the numerator and the denominator lattices to use it as additional loss.
  
  Can be overridden.
docstr_tok: ["Intersects","emissions_graphs","with","supervision_graphs","and","calculates","lattice","scores",".","This","version","implicitly","assumes","supervision_graphs","to","be","a","pair","of","the","numerator","and","the","denominator","FSAs",".","It","can","also","calculate","accuracy","between","the","numerator","and","the","denominator","lattices","to","use","it","as","additional","loss",".","Can","be","overridden","."]
code: def _intersect_calc_scores(
      self,
      emissions_graphs: "k2.DenseFsaVec",
      supervision_graphs: Any,
      supervisions: torch.Tensor,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Intersects emissions_graphs with supervision_graphs and calculates lattice scores.
      This version implicitly assumes supervision_graphs to be a pair of the numerator and the denominator FSAs.
  
      It can also calculate accuracy between the numerator and the denominator lattices to use it as additional loss.
  
      Can be overridden.
      """
      boosted = self.boost_coeff != 0.0
      (
          num_tot_scores,
          den_tot_scores,
          num_lats,
          den_lats,
      ) = self._intersect_calc_scores_impl(
          emissions_graphs,
          supervision_graphs[0],
          supervision_graphs[1],
          boosted,
      )
  
      inverted_batch_order = invert_permutation(
          supervisions[:, 0].to(dtype=torch.long)
      )
      self.__batch_order = None
      tot_scores = (num_tot_scores - den_tot_scores)[
          inverted_batch_order
      ]
      mmi_tot_scores, mmi_valid_mask = get_tot_objf_and_finite_mask(
          tot_scores, self.reduction
      )
  
      if boosted:
          assert num_lats is not None and den_lats is not None
  
          size = (
              emissions_graphs.dim0(),
              emissions_graphs.scores.shape[0],
              emissions_graphs.scores.shape[1] - 1,
          )
          row_ids = emissions_graphs.emissions_graphs.shape().row_ids(1)
          num_sparse = create_sparse_wrapped(
              indices=[
                  k2.index_select(row_ids, num_lats.seqframe_idx),
                  num_lats.seqframe_idx,
                  num_lats.phones,
              ],
              values=num_lats.get_arc_post(False, True).exp(),
              size=size,
              min_col_index=0,
          )
          del num_lats
          den_sparse = create_sparse_wrapped(
              indices=[
                  k2.index_select(row_ids, den_lats.seqframe_idx),
                  den_lats.seqframe_idx,
                  den_lats.phones,
              ],
              values=den_lats.get_arc_post(False, True).exp(),
              size=size,
              min_col_index=0,
          )
          del den_lats
  
          acc_loss = torch.sparse.sum(
              (num_sparse - den_sparse).coalesce().abs(), (1, 2)
          ).to_dense()
          del num_sparse, den_sparse
  
          acc_tot_scores, acc_valid_mask = get_tot_objf_and_finite_mask(
              acc_loss, self.reduction
          )
          valid_mask = mmi_valid_mask & acc_valid_mask
          total_loss = (
              (
                  self.boost_coeff
                  * acc_tot_scores[inverted_batch_order][valid_mask]
                  - mmi_tot_scores[valid_mask]
              )
              if self.reduction == "none"
              else self.boost_coeff * acc_tot_scores - mmi_tot_scores
          )
      else:
          valid_mask = mmi_valid_mask
          total_loss = (
              -mmi_tot_scores[valid_mask]
              if self.reduction == "none"
              else -mmi_tot_scores
          )
      return total_loss, valid_mask
  
imports: from abc import abstractmethod
  from typing import Any, Optional, Tuple, Union
  import torch
  from omegaconf import DictConfig
  from nemo.collections.asr.parts.k2.classes import GraphIntersectDenseConfig
  from nemo.collections.asr.parts.k2.loss_mixins import CtcK2Mixin
  from nemo.collections.asr.parts.k2.ml_loss import MLLoss
  from nemo.collections.asr.parts.k2.utils import create_sparse_wrapped, get_tot_objf_and_finite_mask, invert_permutation, load_graph
  from nemo.core.utils.k2_guard import k2
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling the MAPLoss obj's underlying member method code with example usage: obj._intersect_calc_scores(emissions_graphs, supervision_graphs, supervisions) and returns: total_loss,  valid_mask