code: def create_serialization_dir(params, serialization_dir, recover):
      """
      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.
      """
      if os.path.exists(serialization_dir) and os.listdir(
          serialization_dir
      ):
          if not recover:
              raise ConfigurationError(
                  "Serialization directory ({serialization_dir}) already exists and is "
                  "not empty. Specify --recover to recover training from existing output."
              )
  
          logger.info(
              "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."
              )
          else:
              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 list(flat_params.keys()) - list(
                  flat_loaded.keys()
              ):
                  logger.error(
                      "Key '{key}' found in training configuration but not in the serialization "
                      "directory we're recovering from."
                  )
                  fail = True
              for key in list(flat_loaded.keys()) - list(
                  flat_params.keys()
              ):
                  logger.error(
                      "Key '{key}' found in the serialization directory we're recovering from "
                      "but not in the training config."
                  )
                  fail = True
              for key in list(flat_params.keys()):
                  if flat_params.get(key, None) != flat_loaded.get(
                      key, None
                  ):
                      logger.error(
                          "Value for '{key}' in training configuration does not match that the value in "
                          "the serialization directory we're recovering from: "
                          "{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(
                  "--recover specified but serialization_dir ({serialization_dir}) "
                  "does not exist.  There is nothing to recover from."
              )
          os.makedirs(serialization_dir, exist_ok=True)
  
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import argparse
  import json
  import logging
  import os
  import re
  import torch
  from allennlp.commands.evaluate import evaluate
  from allennlp.commands.subcommand import Subcommand
  from allennlp.common.checks import ConfigurationError, check_for_gpu
  from allennlp.common import Params
  from allennlp.common.util import prepare_environment, prepare_global_logging, get_frozen_and_tunable_parameter_names
  from allennlp.data import Vocabulary
  from allennlp.data.instance import Instance
  from allennlp.data.dataset_readers.dataset_reader import DatasetReader
  from allennlp.data.iterators.data_iterator import DataIterator
  from allennlp.models.archival import archive_model, CONFIG_NAME
  from allennlp.models.model import Model, _DEFAULT_WEIGHTS
  from allennlp.training.trainer import Trainer
  from io import open
label_desc: Use image node_id 4 for calling a global function with example usage: create_serialization_dir(params, serialization_dir, recover) without return types