code: def smart_truncate_datum(datum, max_seq_length, max_valid_length):
      row_dict = datum["data_row"].to_dict()
      new_row_dict = row_dict.copy()
      for k, v in row_dict.items():
          if not isinstance(v, np.ndarray):
              continue
          if max_seq_length not in v.shape:
              continue
          if not v.shape.count(max_seq_length) == 1:
              raise RuntimeError("confusing dimensions")
          slice_ls = []
          for n in v.shape:
              if n == max_seq_length:
                  slice_ls.append(slice(None, max_valid_length))
              else:
                  slice_ls.append(slice(None))
          new_row_dict[k] = v[tuple(slice_ls)]
      return {
          "data_row": datum["data_row"].__class__(**new_row_dict),
          "metadata": datum["metadata"],
      }
  
file_path: jiant/jiant/proj/main/preprocessing.py
imports: import numpy
  import torch
  import jiant.shared.caching
  import jiant.utils.torch_utils
  from jiant.tasks.core import FeaturizationSpec, TaskTypes
  from jiant.utils.display import maybe_tqdm, maybe_trange
label_desc: Use image node_id 3 for calling a global function with example usage: smart_truncate_datum(datum, max_seq_length, max_valid_length) and returns: dict