code: def test_truncate_alignment_from_end(
      sequences, max_length, align, mask_from_end
  ):
      # print("Max length", max_length)
      # print("Sequences", sequences)
      # print("Mask", mask_from_end)
      ops = NumpyOps()
      truncated = _truncate_alignment(align, mask_from_end)
      # print(truncated.dataXd.shape, truncated.lengths.sum())
      # print("Before", list(map(list, ops.unflatten(align.dataXd, align.lengths))))
      # print("After", list(map(list, ops.unflatten(truncated.dataXd, truncated.lengths))))
      # Check that the number of tokens hasn't changed. We still need to have
      # alignment for every token.
      assert truncated.lengths.shape[0] == align.lengths.shape[0]
      start = 0
      for i, seq in enumerate(sequences):
          end = start + len(seq)
          # Get the alignment for this sequence of tokens. Each length in the
          # alignment indicates the number of wordpiece tokens, so we need to
          # check that the sum of the lengths doesn't exceed the maximum.
          wp_indices = truncated[start:end]
          assert wp_indices.lengths.sum() <= max_length
          # We're truncating from the end, so we shouldn't see different values
          # except at the end of the sequence.
          seen_zero = False
          before = align[start:end]
          for length_now, length_before in zip(
              wp_indices.lengths, before.lengths
          ):
              if seen_zero:
                  assert length_now == 0, wp_indices.lengths
              elif length_now == 0:
                  seen_zero = True
              else:
                  length_now == length_before
  
file_path: spacy-transformers/spacy_transformers/tests/test_truncation.py
imports: import pytest
  import numpy
  from thinc.types import Ragged
  from thinc.api import NumpyOps
  from ..data_classes import WordpieceBatch
  from ..truncate import _truncate_tokens, _truncate_alignment
label_desc: Use image node_id 9 for calling a global function with example usage: test_truncate_alignment_from_end(sequences, max_length, align, mask_from_end) without return types