code: def as_stacked_batches(
      dataset: Dataset,
      *,
      batch_size: int,
      output_type: Optional[Callable] = None,
      num_batches_per_epoch: Optional[int] = None,
      shuffle_buffer_length: Optional[int] = None,
      field_names: Optional[list] = None,
  ):
      """
      Prepare data in batches to be passed to a network.
  
      Input data is collected into batches of size ``batch_size`` and then
      columns are stacked on top of each other. In addition, the result is
      wrapped in ``output_type`` if provided.
  
      If ``num_batches_per_epoch`` is provided, only those number of batches are
      effectively returned. This is especially useful for training when
      providing a cyclic dataset.
  
      To pseudo shuffle data, ``shuffle_buffer_length`` can be set to collect
      inputs into a buffer first, from which we then randomly sample.
  
      Setting ``field_names`` will only consider those columns in the input data
      and discard all other values.
      """
  
      if shuffle_buffer_length:
          dataset = PseudoShuffled(dataset, shuffle_buffer_length)
  
      transform: Transformation = Identity()
  
      if field_names is not None:
          transform += SelectFields(field_names)
  
      transform += Batch(batch_size=batch_size)
      transform += Stack()
  
      if output_type is not None:
          transform += Valmap(output_type)
  
      # Note: is_train needs to be provided but does not have an effect
      transformed_dataset = transform.apply(dataset, is_train=True)
      return IterableSlice(transformed_dataset, num_batches_per_epoch)
  
file_path: gluonts/src/gluonts/dataset/loader.py
imports: import logging
  from typing import Callable, Iterable, Optional
  import numpy
  from gluonts.dataset import DataBatch, Dataset
  from gluonts.itertools import Cyclic, IterableSlice, PseudoShuffled, batcher, rows_to_columns
  from gluonts.pydantic import BaseModel
  from gluonts.transform import AdhocTransform, Identity, SelectFields, Transformation, Valmap
label_desc: Use image node_id 1 for calling a global function with example usage: as_stacked_batches(dataset) and returns: IterableSlice