docs: def iterate_sequences(
      consumer_fn, output_template, sequences, length, chunk_length=None,
      batch_size=None, num_epochs=1, padding_value=0):
    """Iterate over batches of chunks of sequences for multiple epochs.
  
    The batch dimension of the length tensor must be set because it is used to
    infer buffer sizes.
  
    Args:
      consumer_fn: Function creating the operation to process the data.
      output_template: Nested tensors of same shape and dtype as outputs.
      sequences: Nested collection of tensors with batch and time dimension.
      length: Tensor containing the length for each sequence.
      chunk_length: Split sequences into chunks of this size; optional.
      batch_size: Split epochs into batches of this size; optional.
      num_epochs: How many times to repeat over the data.
      padding_value: Value used for padding the last chunk after the sequence.
  
    Raises:
      ValueError: Unknown batch size of the length tensor.
  
    Returns:
      Concatenated nested tensors returned by the consumer.
    """
    if not length.shape[0].value:
      raise ValueError('Batch size of length tensor must be set.')
    num_sequences = length.shape[0].value
    sequences = dict(sequence=sequences, length=length)
    dataset = tf.data.Dataset.from_tensor_slices(sequences)
    dataset = dataset.repeat(num_epochs)
    if chunk_length:
      dataset = dataset.map(remove_padding).flat_map(
          # pylint: disable=g-long-lambda
          lambda x: tf.data.Dataset.from_tensor_slices(
              chunk_sequence(x, chunk_length, padding_value)))
      num_chunks = tf.reduce_sum((length - 1) // chunk_length + 1)
    else:
      num_chunks = num_sequences
    if batch_size:
      dataset = dataset.shuffle(num_sequences // 2)
    dataset = dataset.batch(batch_size or num_sequences)
    dataset = dataset.prefetch(num_epochs)
    iterator = dataset.make_initializable_iterator()
    with tf.control_dependencies([iterator.initializer]):
      num_batches = num_epochs * num_chunks // (batch_size or num_sequences)
      return tf.scan(
          # pylint: disable=g-long-lambda
          lambda _1, index: consumer_fn(iterator.get_next()),
          tf.range(num_batches), output_template, parallel_iterations=1)