code: def gen_factors(
      FACTORS_tasks,
      data_dir,
      train_dir,
      valid_dir,
      test_dir,
      shard_size=2000,
  ):
      """Loads the FACTORS dataset; does not do train/test split"""
  
      time1 = time.time()
  
      train_files = os.path.join(data_dir, TRAIN_FILENAME)
      valid_files = os.path.join(data_dir, VALID_FILENAME)
      test_files = os.path.join(data_dir, TEST_FILENAME)
  
      if not os.path.exists(train_files):
          logger.info("Downloading train file...")
          deepchem.utils.data_utils.download_url(
              url=TRAIN_URL, dest_dir=data_dir
          )
          logger.info("Training file download complete.")
  
          logger.info("Downloading validation file...")
          deepchem.utils.data_utils.download_url(
              url=VALID_URL, dest_dir=data_dir
          )
          logger.info("Validation file download complete.")
  
          logger.info("Downloading test file...")
          deepchem.utils.data_utils.download_url(
              url=TEST_URL, dest_dir=data_dir
          )
          logger.info("Test file download complete")
  
      # Featurize the FACTORS dataset
      logger.info("About to featurize the FACTORS dataset")
      featurizer = deepchem.feat.UserDefinedFeaturizer(
          merck_descriptors
      )
      loader = deepchem.data.UserCSVLoader(
          tasks=FACTORS_tasks,
          id_field="Molecule",
          featurizer=featurizer,
      )
  
      logger.info("Featurizing the train dataset...")
      train_dataset = loader.featurize(
          train_files, shard_size=shard_size
      )
  
      logger.info("Featurizing the validation dataset...")
      valid_dataset = loader.featurize(
          valid_files, shard_size=shard_size
      )
  
      logger.info("Featurizing the test dataset...")
      test_dataset = loader.featurize(test_files, shard_size=shard_size)
  
      logger.info("Remove missing entries from dataset")
      remove_missing_entries(train_dataset)
      remove_missing_entries(valid_dataset)
      remove_missing_entries(test_dataset)
  
      # Shuffle the training data
      logger.info("Shuffling the training dataset")
      train_dataset.sparse_shuffle()
  
      # Apply transformations
      logger.info("Transforming datasets with transformers")
      transformers = get_transformers(train_dataset)
  
      for transformer in transformers:
          logger.info(
              "Performing transformations with {}".format(
                  transformer.__class__.__name__
              )
          )
  
          logger.info("Transforming the training dataset...")
          train_dataset = transformer.transform(train_dataset)
  
          logger.info("Transforming the validation dataset...")
          valid_dataset = transformer.transform(valid_dataset)
  
          logger.info("Transforming the test dataset...")
          test_dataset = transformer.transform(test_dataset)
  
      logger.info("Transformations complete.")
      logger.info("Moving datasets to corresponding directories")
  
      train_dataset.move(train_dir)
      logger.info("Train dataset moved.")
  
      valid_dataset.move(valid_dir)
      logger.info("Validation dataset moved.")
  
      test_dataset.move(test_dir)
      logger.info("Test dataset moved.")
  
      time2 = time.time()
  
      # TIMING
      logger.info(
          "TIMING: FACTORS fitting took %0.3f s" % (time2 - time1)
      )
  
      return train_dataset, valid_dataset, test_dataset
  
file_path: deepchem/deepchem/molnet/load_function/factors_datasets.py
imports: import os
  import logging
  import time
  import deepchem
  from deepchem.molnet.load_function.kaggle_features import merck_descriptors
  from deepchem.utils import remove_missing_entries
label_desc: Use image node_id 2 for calling a global function with example usage: gen_factors(FACTORS_tasks, data_dir, train_dir, valid_dir, test_dir, shard_size) and returns: train_dataset,  valid_dataset,  test_dataset