code: def generate_train_valid(data, n_folds=5, is_loo=False):
      all_data = data["train"] + data["valid"]
  
      if is_loo:
          # for Leave One Out
          for i in range(len(all_data)):
              data_i = {"train": all_data.copy(), "test": data["test"]}
              data_i["valid"] = [data_i["train"].pop(i)]
  
              yield data_i
      else:
          # for Cross Validation
          kf = KFold(n_splits=n_folds, shuffle=True)
          for train_index, valid_index in kf.split(all_data):
              data_i = {
                  "train": [all_data[i] for i in train_index],
                  "valid": [all_data[i] for i in valid_index],
                  "test": data["test"],
              }
  
              yield data_i
  
file_path: DeepPavlov/deeppavlov/core/common/cross_validation.py
imports: import shutil
  from collections import OrderedDict
  from logging import getLogger
  from pathlib import Path
  import numpy
  from sklearn.model_selection import KFold
  from deeppavlov.core.commands.train import train_evaluate_model_from_config, get_iterator_from_config, read_data_by_config
  from deeppavlov.core.commands.utils import expand_path, parse_config
  from deeppavlov.core.common.params_search import ParamsSearch
label_desc: Use image node_id 4 for calling a global function with example usage: generate_train_valid(data, n_folds, is_loo) without return types