code: def create_serialization_dir(
      params: Params,
      serialization_dir: Union[str, PathLike],
      recover: bool,
      force: bool,
  ) -> None:
      """
      This function creates the serialization directory if it doesn't exist.  If it already exists
      and is non-empty, then it verifies that we're recovering from a training with an identical configuration.
  
      # Parameters
  
      params : `Params`
          A parameter object specifying an AllenNLP Experiment.
      serialization_dir : `str`
          The directory in which to save results and logs.
      recover : `bool`
          If `True`, we will try to recover from an existing serialization directory, and crash if
          the directory doesn't exist, or doesn't match the configuration we're given.
      force : `bool`
          If `True`, we will overwrite the serialization directory if it already exists.
      """
      if recover and force:
          raise ConfigurationError(
              "Illegal arguments: both force and recover are true."
          )
  
      if os.path.exists(serialization_dir) and force:
          shutil.rmtree(serialization_dir)
  
      if os.path.exists(serialization_dir) and os.listdir(
          serialization_dir
      ):
          if not recover:
              raise ConfigurationError(
                  f"Serialization directory ({serialization_dir}) already exists and is "
                  f"not empty. Specify --recover to recover from an existing output folder."
              )
  
          logger.info(
              f"Recovering from prior training at {serialization_dir}."
          )
  
          recovered_config_file = os.path.join(
              serialization_dir, CONFIG_NAME
          )
          if not os.path.exists(recovered_config_file):
              raise ConfigurationError(
                  "The serialization directory already exists but doesn't "
                  "contain a config.json. You probably gave the wrong directory."
              )
          loaded_params = Params.from_file(recovered_config_file)
  
          # Check whether any of the training configuration differs from the configuration we are
          # resuming.  If so, warn the user that training may fail.
          fail = False
          flat_params = params.as_flat_dict()
          flat_loaded = loaded_params.as_flat_dict()
          for key in flat_params.keys() - flat_loaded.keys():
              logger.error(
                  f"Key '{key}' found in training configuration but not in the serialization "
                  f"directory we're recovering from."
              )
              fail = True
          for key in flat_loaded.keys() - flat_params.keys():
              logger.error(
                  f"Key '{key}' found in the serialization directory we're recovering from "
                  f"but not in the training config."
              )
              fail = True
          for key in flat_params.keys():
              if flat_params.get(key) != flat_loaded.get(key):
                  logger.error(
                      f"Value for '{key}' in training configuration does not match that the value in "
                      f"the serialization directory we're recovering from: "
                      f"{flat_params[key]} != {flat_loaded[key]}"
                  )
                  fail = True
          if fail:
              raise ConfigurationError(
                  "Training configuration does not match the configuration we're recovering from."
              )
      else:
          if recover:
              raise ConfigurationError(
                  f"--recover specified but serialization_dir ({serialization_dir}) "
                  "does not exist.  There is nothing to recover from."
              )
          os.makedirs(serialization_dir, exist_ok=True)
  
imports: import datetime
  import logging
  import os
  import shutil
  import json
  from os import PathLike
  from typing import Any, Dict, Iterable, Optional, Union, Tuple, Set, List
  from collections import Counter
  import torch
  from torch.nn.utils import clip_grad_norm_
  from allennlp.common.checks import check_for_gpu, ConfigurationError
  from allennlp.common.params import Params
  from allennlp.common.tqdm import Tqdm
  from allennlp.common.util import dump_metrics, sanitize, int_to_device
  from allennlp.data import Instance, Vocabulary, Batch, DataLoader
  from allennlp.data.dataset_readers import DatasetReader
  from allennlp.models.archival import CONFIG_NAME
  from allennlp.models.model import Model
  from allennlp.nn import util
label_desc: Use image node_id 6 for calling a global function with example usage: create_serialization_dir(params, serialization_dir, recover, force) without return types