code: def _get_splits(
      trainset: Tuple[np.ndarray, np.ndarray],
      valset: Tuple[Optional[np.ndarray], Optional[np.ndarray]],
      kfold_kw: dict,
  ) -> Tuple[
      Tuple[np.ndarray, np.ndarray],
      Tuple[np.ndarray, np.ndarray],
      List[Tuple[np.ndarray, np.ndarray]],
  ]:
      """
      Helper function to obtain appropriate train-validation splits.
  
      If the validation dataset is not provided, then the method returns the appropriate datasets and indices
      to perform k-fold validation. Otherwise, if the validation dataset is provided, then use it instead of performing
      k-fold validation.
  
      Parameters
      ----------
      trainset
          Tuple `(X_train, y_train)` consisting of the training data instances with the corresponding labels.
      valset
          Optional tuple, `(X_val, y_val)`, consisting of validation data instances with the corresponding labels.
      kfold_kw
          Keyword arguments passed to `sklearn.model_selection.KFold`. See parameters description:
          https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html
  
      Returns
      -------
      Tuple consisting of training dataset, validation dataset (can overlap with training if validation is not
      provided), and a list of splits containing indices from the training and validation datasets.
      """
      X_train, y_train = trainset
      X_val, y_val = valset
  
      if X_val is None:
          kfold = KFold(**kfold_kw)
          splits = kfold.split(X=X_train, y=y_train)
          return trainset, trainset, list(splits)
  
      splits = [(np.arange(len(X_train)), np.arange(len(X_val)))]
      return trainset, valset, splits
  
imports: import logging
  from copy import deepcopy
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import matplotlib.pyplot
  import numpy
  from matplotlib.offsetbox import AnnotationBbox, OffsetImage
  from skimage.transform import resize
  from sklearn.model_selection import KFold
  from sklearn.neighbors import KNeighborsClassifier
  from tqdm import tqdm
  from alibi.api.defaults import DEFAULT_DATA_PROTOSELECT, DEFAULT_META_PROTOSELECT
  from alibi.api.interfaces import Explanation, FitMixin, Summariser
  from alibi.utils.distance import batch_compute_kernel_matrix
  from alibi.utils.kernel import EuclideanDistance
label_desc: Use image node_id 2 for calling a global function with example usage: _get_splits(trainset, valset, kfold_kw) and returns: trainset,  valset,  splits, trainset,  trainset,  list