code: def compute_am_scores_and_lm_scores(
      lats: k2.Fsa,
      word_fsas_with_epsilon_loops: k2.Fsa,
      path_to_seq_map: torch.Tensor,
      device: str = "cuda",
      batch_size: int = 500,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Compute AM and LM scores of n-best lists (represented as word_fsas).
  
      Args:
        lats:
          An FsaVec, which is the output of `k2.intersect_dense_pruned`.
          It must have the attribute `lm_scores`.
        word_fsas_with_epsilon_loops:
          An FsaVec representing a n-best list. Note that it has been processed
          by `k2.add_epsilon_self_loops`.
        path_to_seq_map:
          A 1-D torch.Tensor with dtype torch.int32. path_to_seq_map[i] indicates
          which sequence the i-th Fsa in word_fsas_with_epsilon_loops belongs to.
          path_to_seq_map.numel() == word_fsas_with_epsilon_loops.arcs.dim0().
        batch_size:
          Batchify the n-best list when intersecting with inverted_lats.
          You could tune this to avoid GPU OOM issue or increase the GPU usage.
      Returns:
        Return a tuple of (1-D torch.Tensor, 1-D torch.Tensor) containing
        the AM and LM scores of each path.
        `am_scores.numel() == word_fsas_with_epsilon_loops.shape[0]`
        `lm_scores.numel() == word_fsas_with_epsilon_loops.shape[0]`
      """
      assert (
          k2 is not None
      ), "k2 is not installed, please follow 'tools/installers' to install"
      assert len(lats.shape) == 3
  
      # k2.compose() currently does not support b_to_a_map. To void
      # replicating `lats`, we use k2.intersect_device here.
      #
      # lats has phone IDs as `labels` and word IDs as aux_labels, so we
      # need to invert it here.
      inverted_lats = k2.invert(lats)
  
      # Now the `labels` of inverted_lats are word IDs (a 1-D torch.Tensor)
      # and its `aux_labels` are phone IDs ( a k2.RaggedInt with 2 axes)
  
      # Remove its `aux_labels` since it is not needed in the
      # following computation
      del inverted_lats.aux_labels
      inverted_lats = k2.arc_sort(inverted_lats)
  
      am_path_lats = _intersect_device(
          inverted_lats,
          word_fsas_with_epsilon_loops,
          b_to_a_map=path_to_seq_map,
          sorted_match_a=True,
          batch_size=batch_size,
      )
  
      am_path_lats = k2.top_sort(k2.connect(am_path_lats))
  
      # The `scores` of every arc consists of `am_scores` and `lm_scores`
      tot_score_device = "cpu"
      if hasattr(lats, "lm_scores"):
          am_path_lats.scores = (
              am_path_lats.scores - am_path_lats.lm_scores
          )
          am_scores = (
              am_path_lats.to(tot_score_device)
              .get_tot_scores(
                  use_double_scores=True, log_semiring=False
              )
              .to(device)
          )
  
          # Start to compute lm_scores
          am_path_lats.scores = am_path_lats.lm_scores
          lm_scores = (
              am_path_lats.to(tot_score_device)
              .get_tot_scores(
                  use_double_scores=True, log_semiring=False
              )
              .to(device)
          )
      else:
          am_scores = (
              am_path_lats.to(tot_score_device)
              .get_tot_scores(
                  use_double_scores=True, log_semiring=False
              )
              .to(device)
          )
          lm_scores = None
  
      return am_scores, lm_scores
  
imports: import math
  from typing import List, Tuple
  import torch
label_desc: Use image node_id 3 for calling a global function with example usage: compute_am_scores_and_lm_scores(lats, word_fsas_with_epsilon_loops, path_to_seq_map, device, batch_size) and returns: am_scores,  lm_scores