code: def train(
      domain: Text,
      config: Text,
      training_files: Optional[Union[Text, List[Text]]],
      output: Text = rasa.shared.constants.DEFAULT_MODELS_PATH,
      dry_run: bool = False,
      force_training: bool = False,
      fixed_model_name: Optional[Text] = None,
      persist_nlu_training_data: bool = False,
      core_additional_arguments: Optional[Dict] = None,
      nlu_additional_arguments: Optional[Dict] = None,
      model_to_finetune: Optional[Text] = None,
      finetuning_epoch_fraction: float = 1.0,
  ) -> TrainingResult:
      """Trains a Rasa model (Core and NLU).
  
      Args:
          domain: Path to the domain file.
          config: Path to the config file.
          training_files: List of paths to training data files.
          output: Output directory for the trained model.
          dry_run: If `True` then no training will be done, and the information about
              whether the training needs to be done will be printed.
          force_training: If `True` retrain model even if data has not changed.
          fixed_model_name: Name of model to be stored.
          persist_nlu_training_data: `True` if the NLU training data should be persisted
              with the model.
          core_additional_arguments: Additional training parameters for core training.
          nlu_additional_arguments: Additional training parameters forwarded to training
              method of each NLU component.
          model_to_finetune: Optional path to a model which should be finetuned or
              a directory in case the latest trained model should be used.
          finetuning_epoch_fraction: The fraction currently specified training epochs
              in the model configuration which should be used for finetuning.
  
      Returns:
          An instance of `TrainingResult`.
      """
      file_importer = TrainingDataImporter.load_from_config(
          config, domain, training_files, core_additional_arguments
      )
  
      stories = file_importer.get_stories()
      nlu_data = file_importer.get_nlu_data()
  
      training_type = TrainingType.BOTH
  
      if nlu_data.has_e2e_examples():
          rasa.shared.utils.common.mark_as_experimental_feature(
              "end-to-end training"
          )
          training_type = TrainingType.END_TO_END
  
      if stories.is_empty() and nlu_data.contains_no_pure_nlu_data():
          rasa.shared.utils.cli.print_error(
              "No training data given. Please provide stories and NLU data in "
              "order to train a Rasa model using the '--data' argument."
          )
          return TrainingResult(code=1)
  
      domain_object = file_importer.get_domain()
      if domain_object.is_empty():
          rasa.shared.utils.cli.print_warning(
              "Core training was skipped because no valid domain file was found. "
              "Only an NLU-model was created. Please specify a valid domain using "
              "the '--domain' argument or check if the provided domain file exists."
          )
          training_type = TrainingType.NLU
  
      elif stories.is_empty():
          rasa.shared.utils.cli.print_warning(
              "No stories present. Just a Rasa NLU model will be trained."
          )
          training_type = TrainingType.NLU
  
      # We will train nlu if there are any nlu example, including from e2e stories.
      elif (
          nlu_data.contains_no_pure_nlu_data()
          and not nlu_data.has_e2e_examples()
      ):
          rasa.shared.utils.cli.print_warning(
              "No NLU data present. Just a Rasa Core model will be trained."
          )
          training_type = TrainingType.CORE
  
      _check_unresolved_slots(domain_object, stories)
  
      with telemetry.track_model_training(
          file_importer, model_type="rasa"
      ):
          return _train_graph(
              file_importer,
              training_type=training_type,
              output_path=output,
              fixed_model_name=fixed_model_name,
              model_to_finetune=model_to_finetune,
              force_full_training=force_training,
              persist_nlu_training_data=persist_nlu_training_data,
              finetuning_epoch_fraction=finetuning_epoch_fraction,
              dry_run=dry_run,
              **(core_additional_arguments or {}),
              **(nlu_additional_arguments or {}),
          )
  
imports: import time
  from pathlib import Path
  from typing import Text, NamedTuple, Optional, List, Union, Dict, Any
  import randomname
  import rasa.engine.validation
  from rasa.engine.caching import LocalTrainingCache
  from rasa.engine.recipes.recipe import Recipe
  from rasa.engine.runner.dask import DaskGraphRunner
  from rasa.engine.storage.local_model_storage import LocalModelStorage
  from rasa.engine.storage.storage import ModelStorage
  from rasa.engine.training.components import FingerprintStatus
  from rasa.engine.training.graph_trainer import GraphTrainer
  from rasa.shared.core.events import SlotSet
  from rasa.shared.core.training_data.structures import StoryGraph
  from rasa.shared.data import TrainingType
  from rasa.shared.importers.importer import TrainingDataImporter
  from rasa import telemetry
  from rasa.shared.core.domain import Domain
  import rasa.utils.common
  import rasa.shared.utils.common
  import rasa.shared.utils.cli
  import rasa.shared.exceptions
  import rasa.shared.utils.io
  import rasa.shared.constants
  import rasa.model
label_desc: Use image node_id 4 for calling a global function with example usage: train(domain, config, training_files, output, dry_run, force_training, fixed_model_name, persist_nlu_training_data, core_additional_arguments, nlu_additional_arguments, model_to_finetune, finetuning_epoch_fraction) and returns: TrainingResult, _train_graph