code: def _numpy_collate_batch(
      examples, tokenizer, pad_to_multiple_of: Optional[int] = None
  ):
      """Collate `examples` into a batch, using the information in `tokenizer` for padding if necessary."""
      # Tensorize if necessary.
      if isinstance(examples[0], (list, tuple)):
          examples = [np.array(e, dtype=np.int64) for e in examples]
  
      # Check if padding is necessary.
      length_of_first = len(examples[0])
      are_tensors_same_length = all(
          len(x) == length_of_first for x in examples
      )
      if are_tensors_same_length and (
          pad_to_multiple_of is None
          or length_of_first % pad_to_multiple_of == 0
      ):
          return np.stack(examples, axis=0)
  
      # If yes, check if we have a `pad_token`.
      if tokenizer._pad_token is None:
          raise ValueError(
              "You are attempting to pad samples but the tokenizer you are using"
              f" ({tokenizer.__class__.__name__}) does not have a pad token."
          )
  
      # Creating the full tensor and filling it with our data.
      max_length = max(len(x) for x in examples)
      if pad_to_multiple_of is not None and (
          max_length % pad_to_multiple_of != 0
      ):
          max_length = (
              (max_length // pad_to_multiple_of) + 1
          ) * pad_to_multiple_of
      result = np.full(
          shape=(len(examples), max_length),
          fill_value=tokenizer.pad_token_id,
          dtype=examples[0].dtype,
      )
      for i, example in enumerate(examples):
          if tokenizer.padding_side == "right":
              result[i, : example.shape[0]] = example
          else:
              result[i, -example.shape[0] :] = example
      return result
  
imports: import random
  import warnings
  from collections.abc import Mapping
  from dataclasses import dataclass
  from random import randint
  from typing import Any, Callable, Dict, List, NewType, Optional, Tuple, Union
  import numpy
  from ..models.bert import BertTokenizer, BertTokenizerFast
  from ..tokenization_utils_base import PreTrainedTokenizerBase
  from ..utils import PaddingStrategy
label_desc: Use image node_id 8 for calling a global function with example usage: _numpy_collate_batch(examples, tokenizer, pad_to_multiple_of) and returns: result, np