code: def compute_num_folds_from_example_counts(
      cv_folds: int,
      labels: Optional[np.ndarray],
      model_type: str,
      logger: Optional[logging.Logger] = None,
  ) -> int:
      """
      Calculate number of cross-validation folds, based on number of examples per label.
  
      Parameters
      ----------
      cv_folds : int
          The number of cross-validation folds.
      labels : numpy.ndarray
          The example labels.
      model_type : str
          One of "classifier" or "regressor".
      logger : Optional[logging.Logger], default=None
          A logger instance to use for logging messages and warnings.
          If ``None``, a new one is created.
  
      Returns
      -------
      int
          The number of folds to use, based on the number of examples
          for each label.
  
      Raises
      ------
      ValueError
          If ``cv_folds`` is not an integer or if the training set has
          fewer than 2 examples associated with a label (for classification).
      """
      # get a logger if not provided
      logger = logger if logger else logging.getLogger(__name__)
  
      try:
          assert isinstance(cv_folds, int)
      except AssertionError:
          raise ValueError("`cv_folds` must be an integer.")
  
      # For regression models, we can just return the current cv_folds
      if model_type == "regressor":
          return cv_folds
  
      min_examples_per_label = min(Counter(labels).values())
      if min_examples_per_label <= 1:
          raise ValueError(
              f"The training set has only {min_examples_per_label}"
              " example for a label."
          )
      if min_examples_per_label < cv_folds:
          logger.warning(
              "The minimum number of examples per label was "
              f"{min_examples_per_label}. Setting the number of "
              "cross-validation folds to that value."
          )
          cv_folds = min_examples_per_label
      return cv_folds
  
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 3 for calling a global function with example usage: compute_num_folds_from_example_counts(cv_folds, labels, model_type, logger) and returns: cv_folds, cv_folds