code: def plot_alignments(
      trellis,
      segments,
      word_segments,
      waveform,
      sample_rate=bundle.sample_rate,
  ):
      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)
  
      ax1.imshow(trellis_with_path.T, origin="lower", aspect="auto")
      ax1.set_facecolor("lightgray")
      ax1.set_xticks([])
      ax1.set_yticks([])
  
      for word in word_segments:
          ax1.axvspan(
              word.start - 0.5,
              word.end - 0.5,
              edgecolor="white",
              facecolor="none",
          )
  
      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"
              )
  
      # The original waveform
      ratio = waveform.size(0) / sample_rate / trellis.size(0)
      ax2.specgram(waveform, Fs=sample_rate)
      for word in word_segments:
          x0 = ratio * word.start
          x1 = ratio * word.end
          ax2.axvspan(
              x0, x1, facecolor="none", edgecolor="white", hatch="/"
          )
          ax2.annotate(
              f"{word.score:.2f}",
              (x0, sample_rate * 0.51),
              annotation_clip=False,
          )
  
      for seg in segments:
          if seg.label != "|":
              ax2.annotate(
                  seg.label,
                  (seg.start * ratio, sample_rate * 0.55),
                  annotation_clip=False,
              )
      ax2.set_xlabel("time [second]")
      ax2.set_yticks([])
      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 9 for calling a global function with example usage: plot_alignments(trellis, segments, word_segments, waveform, sample_rate) without return types