code: def backtrack(trellis, emission, tokens, blank_id=0):
      t, j = trellis.size(0) - 1, trellis.size(1) - 1
  
      path = [Point(j, t, emission[t, blank_id].exp().item())]
      while j > 0:
          # Should not happen but just in case
          assert t > 0
  
          # 1. Figure out if the current position was stay or change
          # Frame-wise score of stay vs change
          p_stay = emission[t - 1, blank_id]
          p_change = emission[t - 1, tokens[j]]
  
          # Context-aware score for stay vs change
          stayed = trellis[t - 1, j] + p_stay
          changed = trellis[t - 1, j - 1] + p_change
  
          # Update position
          t -= 1
          if changed > stayed:
              j -= 1
  
          # Store the path with frame-wise probability.
          prob = (p_change if changed > stayed else p_stay).exp().item()
          path.append(Point(j, t, prob))
  
      # Now j == 0, which means, it reached the SoS.
      # Fill up the rest for the sake of visualization
      while t > 0:
          prob = emission[t - 1, blank_id].exp().item()
          path.append(Point(j, t - 1, prob))
          t -= 1
  
      return path[::-1]
  
file_path: audio/examples/tutorials/forced_alignment_tutorial.py
imports: import torch
  import torchaudio
  from dataclasses import dataclass
  import IPython
  import matplotlib.pyplot
label_desc: Use image node_id 4 for calling a global function with example usage: backtrack(trellis, emission, tokens, blank_id) and returns: path