code: def _truncate_tokens(
      wordpieces: WordpieceBatch, mask: numpy.ndarray
  ) -> WordpieceBatch:
      n_seq = len(wordpieces)
      mask1d = mask.ravel()
      mask = mask.reshape((n_seq, -1))
  
      strings: List[List[str]] = []
      for i, seq in enumerate(wordpieces.strings):
          strings.append([])
          for j, token in enumerate(seq):
              if mask[i, j]:
                  strings[-1].append(token)
  
      def filter_array(data: ArrayT) -> ArrayT:
          data1d = data.reshape((-1,))
          return data1d[mask1d].reshape((n_seq, -1))  # type: ignore
  
      filtered_token_type_ids = None
      if wordpieces.token_type_ids is not None:
          filtered_token_type_ids = filter_array(
              wordpieces.token_type_ids
          )
  
      return WordpieceBatch(
          strings=strings,
          input_ids=filter_array(wordpieces.input_ids),
          attention_mask=filter_array(wordpieces.attention_mask),
          lengths=[len(seq) for seq in strings],
          token_type_ids=filtered_token_type_ids,
      )
  
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 3 for calling a global function with example usage: _truncate_tokens(wordpieces, mask) and returns: WordpieceBatch, data1d