code: def setup_cv_fold_iterator(
      cv_folds: Union[int, FoldMapping],
      examples: FeatureSet,
      model_type: str,
      stratified: bool = False,
      logger: Optional[logging.Logger] = None,
  ) -> Tuple[
      Union[FilteredLeaveOneGroupOut, KFold, StratifiedKFold],
      Optional[List[str]],
  ]:
      """
      Set up a cross-validation fold iterator for the given ``FeatureSet``.
  
      Parameters
      ----------
      cv_folds : Union[int, :class:`skll.types.FoldMapping`]
          The number of folds to use for cross-validation, or
          a mapping from example IDs to folds.
      examples : :class:`skll.data.featureset.FeatureSet`
          The ``FeatureSet`` instance for which the CV iterator is to be computed.
      model_type : str
          One of "classifier" or "regressor".
      stratified : bool, default=False
          Should the cross-validation iterator be set up in a stratified fashion?
      logger : Optional[logging.Logger], default=None
          A logger instance to use for logging messages and warnings.
          If ``None``, a new one is created.
  
      Returns
      -------
      :class:`skll.types.StratifiedKFold`
          k-fold iterator
      Optional[List[str]]
          List of cross-validation groups
      """
      # explicitly declare the return types
      kfold: Union[FilteredLeaveOneGroupOut, KFold, StratifiedKFold]
  
      # Set up the cross-validation iterator.=
      if isinstance(cv_folds, int):
          cv_folds = compute_num_folds_from_example_counts(
              cv_folds, examples.labels, model_type, logger=logger
          )
  
          stratified = stratified and model_type == "classifier"
          if stratified:
              kfold = StratifiedKFold(n_splits=cv_folds)
              cv_groups = None
          else:
              kfold = KFold(n_splits=cv_folds)
              cv_groups = None
      # Otherwise cv_folds is a dict
      else:
          # if we have a mapping from IDs to folds, use it for the overall
          # cross-validation as well as the grid search within each
          # training fold.  Note that this means that the grid search
          # will use K-1 folds because the Kth will be the test fold for
          # the outer cross-validation.
          dummy_label = next(iter(cv_folds.values()))
          fold_groups = [
              cv_folds.get(curr_id, dummy_label)
              for curr_id in examples.ids
          ]
          # Only retain IDs within folds if they're in cv_folds
          kfold = FilteredLeaveOneGroupOut(
              cv_folds, examples.ids, logger=logger
          )
          cv_groups = fold_groups
  
      return kfold, cv_groups
  
imports: from __future__ import annotations
  import inspect
  import logging
  import sys
  import time
  from collections import Counter, defaultdict
  from csv import DictWriter, excel_tab
  from functools import wraps
  from importlib import import_module
  from pathlib import Path
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple, Type, Union
  import joblib
  import numpy
  import scipy.sparse
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.feature_selection import SelectKBest
  from sklearn.metrics import accuracy_score, confusion_matrix, precision_recall_fscore_support
  from sklearn.model_selection import KFold, LeaveOneGroupOut, ShuffleSplit, StratifiedKFold
  from skll.data import FeatureSet
  from skll.metrics import _CUSTOM_METRICS, _PREDEFINED_CUSTOM_METRICS, use_score_func
  from skll.types import ComputeEvalMetricsResults, ConfusionMatrix, FeaturesetIterator, FoldMapping, IdType, IndexIterator, LabelType, PathOrStr, SparseFeatureMatrix
  from skll.utils.constants import CLASSIFICATION_ONLY_METRICS, CORRELATION_METRICS, REGRESSION_ONLY_METRICS, UNWEIGHTED_KAPPA_METRICS, WEIGHTED_KAPPA_METRICS
  from skll.version import VERSION
label_desc: Use image node_id 10 for calling a global function with example usage: setup_cv_fold_iterator(cv_folds, examples, model_type, stratified, logger) and returns: kfold,  cv_groups