def get_training_image_text_data_iters(source_root: str,
                                       source: str, target: str,
                                       validation_source_root: str,
                                       validation_source: str, validation_target: str,
                                       vocab_target: vocab.Vocab,
                                       vocab_target_path: Optional[str],
                                       batch_size: int,
                                       batch_by_words: bool,
                                       batch_num_devices: int,
                                       source_image_size: tuple,
                                       max_seq_len_target: int,
                                       bucketing: bool,
                                       bucket_width: int,
                                       use_feature_loader: bool = False,
                                       preload_features: bool = False) -> Tuple['ParallelSampleIter',
                                                                                'ParallelSampleIter',
                                                                                'DataConfig', 'DataInfo']:
    """
    Returns data iterators for training and validation data.

    :param source_root: Path to source images since the file in source contains relative paths.
    :param source: Path to source training data.
    :param target: Path to target training data.
    :param validation_source_root: Path to validation source images since the file in validation_source contains relative paths.
    :param validation_source: Path to source validation data.
    :param validation_target: Path to target validation data.
    :param vocab_target: Target vocabulary.
    :param vocab_target_path: Path to target vocabulary.
    :param batch_size: Batch size.
    :param batch_by_words: Size batches by words rather than sentences.
    :param batch_num_devices: Number of devices batches will be parallelized across.
    :param source_image_size: size to resize the image to (for iterator)
    :param max_seq_len_target: Maximum target sequence length.
    :param bucketing: Whether to use bucketing.
    :param bucket_width: Size of buckets.
    :param use_feature_loader: If True, features are loaded instead of images.
    :param preload_features: If use_feature_loader si True, this enables load all the feature to memory
    :return: Tuple of (training data iterator, validation data iterator, data config).
    """
    logger.info("===============================")
    logger.info("Creating training data iterator")
    logger.info("===============================")

    # define buckets
    buckets = define_empty_source_parallel_buckets(max_seq_len_target, bucket_width) if bucketing else [
        (0, max_seq_len_target)]

    source_images = [FileListReader(source, source_root)]
    target_sentences = SequenceReader(target, vocab_target, add_bos=True)

    # 2. pass: Get data statistics only on target (source not considered)
    data_statistics = get_data_statistics(source_readers=None,
                                          target_reader=target_sentences,
                                          buckets=buckets,
                                          length_ratio_mean=1.0,
                                          length_ratio_std=1.0,
                                          source_vocabs=None,
                                          target_vocab=vocab_target)

    bucket_batch_sizes = define_bucket_batch_sizes(buckets,
                                                   batch_size,
                                                   batch_by_words,
                                                   batch_num_devices,
                                                   data_statistics.average_len_target_per_bucket)

    data_statistics.log(bucket_batch_sizes)

    data_loader = RawListTextDatasetLoader(buckets=buckets,
                                           eos_id=vocab_target[C.EOS_SYMBOL],
                                           pad_id=C.PAD_ID)

    training_data = data_loader.load(source_images[0], target_sentences,
                                     data_statistics.num_sents_per_bucket).fill_up(bucket_batch_sizes)

    data_info = DataInfo(sources=source_images,
                         target=target,
                         source_vocabs=None,
                         target_vocab=vocab_target_path,
                         shared_vocab=False,
                         num_shards=1)

    config_data = DataConfig(data_statistics=data_statistics,
                             max_seq_len_source=0,
                             max_seq_len_target=max_seq_len_target,
                             num_source_factors=len(source_images))

    # Add useful stuff to config_data
    config_data.source_root = source_root
    config_data.validation_source_root = validation_source_root
    config_data.use_feature_loader = use_feature_loader

    train_iter = ImageTextSampleIter(data=training_data,
                                     buckets=buckets,
                                     batch_size=batch_size,
                                     bucket_batch_sizes=bucket_batch_sizes,
                                     image_size=source_image_size,
                                     use_feature_loader=use_feature_loader,
                                     preload_features=preload_features)

    validation_iter = get_validation_image_text_data_iter(data_loader=data_loader,
                                                          validation_source_root=validation_source_root,
                                                          validation_source=validation_source,
                                                          validation_target=validation_target,
                                                          buckets=buckets,
                                                          bucket_batch_sizes=bucket_batch_sizes,
                                                          source_image_size=source_image_size,
                                                          vocab_target=vocab_target,
                                                          max_seq_len_target=max_seq_len_target,
                                                          batch_size=batch_size,
                                                          use_feature_loader=use_feature_loader,
                                                          preload_features=preload_features)

    return train_iter, validation_iter, config_data, data_info
Returns data iterators for training and validation data.

    :param source_root: Path to source images since the file in source contains relative paths.
    :param source: Path to source training data.
    :param target: Path to target training data.
    :param validation_source_root: Path to validation source images since the file in validation_source contains relative paths.
    :param validation_source: Path to source validation data.
    :param validation_target: Path to target validation data.
    :param vocab_target: Target vocabulary.
    :param vocab_target_path: Path to target vocabulary.
    :param batch_size: Batch size.
    :param batch_by_words: Size batches by words rather than sentences.
    :param batch_num_devices: Number of devices batches will be parallelized across.
    :param source_image_size: size to resize the image to (for iterator)
    :param max_seq_len_target: Maximum target sequence length.
    :param bucketing: Whether to use bucketing.
    :param bucket_width: Size of buckets.
    :param use_feature_loader: If True, features are loaded instead of images.
    :param preload_features: If use_feature_loader si True, this enables load all the feature to memory
    :return: Tuple of (training data iterator, validation data iterator, data config).