code: def _truncate_alignment(align: Ragged, mask: numpy.ndarray) -> Ragged:
      # We're going to have fewer wordpieces in the new array, so all of our
      # wordpiece indices in the alignment table will be off --- they'll point
      # to the wrong row. So we need to do three things here:
      #
      # 1) Adjust all the indices in align.dataXd to account for the dropped data
      # 2) Remove the dropped indices from the align.dataXd
      # 3) Calculate new align.lengths
      #
      # The wordpiece mapping is easily calculated by the cumulative sum of the
      # mask table.
      # Let's say we have [True, False, False, True]. The mapping of the dropped
      # wordpieces doesn't matter, because we can filter it with the mask. So we
      # have [0, 0, 0, 1], i.e the wordpiece that was
      # at 0 is still at 0, and the wordpiece that was at 3 is now at 1.
      mask = mask.ravel()
      idx_map = mask.cumsum() - 1
      idx_map[~mask] = -1
      # Step 1: Adjust all the indices in align.dataXd.
      new_align = idx_map[align.data.ravel()]
      # Step 2: Remove the dropped indices
      new_align = new_align[new_align >= 0]
      # Step 3: Calculate new align.lengths
      new_lengths = align.lengths.copy()
      for i in range(len(align.lengths)):
          drops = ~mask[align[i].data.ravel()]
          new_lengths[i] -= drops.sum()
      return Ragged(new_align, new_lengths)
  
imports: from typing import Tuple, List, Union, TypeVar
  import numpy
  from thinc.types import Ragged, Ints2d, Floats2d
  from .data_classes import WordpieceBatch
label_desc: Use image node_id 4 for calling a global function with example usage: _truncate_alignment(align, mask) and returns: Ragged