code: def plot_trellis_with_segments(trellis, segments, transcript):
      # To plot trellis with path, we take advantage of 'nan' value
      trellis_with_path = trellis.clone()
      for i, seg in enumerate(segments):
          if seg.label != "|":
              trellis_with_path[seg.start : seg.end, i] = float("nan")
  
      fig, [ax1, ax2] = plt.subplots(2, 1, sharex=True)
      ax1.set_title("Path, label and probability for each label")
      ax1.imshow(trellis_with_path.T, origin="lower", aspect="auto")
  
      for i, seg in enumerate(segments):
          if seg.label != "|":
              ax1.annotate(
                  seg.label, (seg.start, i - 0.7), size="small"
              )
              ax1.annotate(
                  f"{seg.score:.2f}", (seg.start, i + 3), size="small"
              )
  
      ax2.set_title("Label probability with and without repetation")
      xs, hs, ws = [], [], []
      for seg in segments:
          if seg.label != "|":
              xs.append((seg.end + seg.start) / 2 + 0.4)
              hs.append(seg.score)
              ws.append(seg.end - seg.start)
              ax2.annotate(seg.label, (seg.start + 0.8, -0.07))
      ax2.bar(
          xs, hs, width=ws, color="gray", alpha=0.5, edgecolor="black"
      )
  
      xs, hs = [], []
      for p in path:
          label = transcript[p.token_index]
          if label != "|":
              xs.append(p.time_index + 1)
              hs.append(p.score)
  
      ax2.bar(xs, hs, width=0.5, alpha=0.5)
      ax2.axhline(0, color="black")
      ax2.grid(True, axis="y")
      ax2.set_ylim(-0.1, 1.1)
      fig.tight_layout()
  
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 7 for calling a global function with example usage: plot_trellis_with_segments(trellis, segments, transcript) without return types