Interface Batchifier

  • All Known Implementing Classes:
    PaddingStackBatchifier, SimplePaddingStackBatchifier, StackBatchifier

    public interface Batchifier
    An interface for different strategies to convert between Record NDLists and Batch NDList.

    Different implementations of Batchifier represent different ways of creating batches. The most common would be the StackBatchifier that batchifies by creating a new batch axis as axis 0. Another implementation could be a concatenated batchifier for sequence elements that will concatenate the data elements along the time axis.

    • Method Detail

      • fromString

        static Batchifier fromString​(java.lang.String name)
        Returns a batchifier from a batchifier name.
        Parameters:
        name - the batchifier name
        Returns:
        the batchifier with the given name
        Throws:
        java.lang.IllegalArgumentException - if an invalid name is given
      • batchify

        NDList batchify​(NDList[] inputs)
        Converts an array of Record NDLists into a combined Batch NDList.

        The size of the input array is the batch size. The data in each of the NDList are assumed to be the same, and are batched together to form one batched NDList.

        Parameters:
        inputs - the input array of NDList where each element is a
        Returns:
        the batchified NDList
      • unbatchify

        NDList[] unbatchify​(NDList inputs)
        Splits a combined Batch NDList into it's constituent Record NDLists.

        This reverses the batchify operation.

        Parameters:
        inputs - the NDList that needs to be 'unbatchified'
        Returns:
        an array of NDLists, of size equal to batch size, where each NDList is one element from the batch of inputs
      • split

        default NDList[] split​(NDList list,
                               int numOfSlices,
                               boolean evenSplit)
        Partitions the given Batch NDList into multiple Batch lists with smaller batch size.

        As an example, this function might be used for multi-GPU training where it takes the main batch and splits it into sub-batches that can be run on each GPU.

        This function unbatchifies the input NDList, redistributes them into the given number of slices, and then batchify each of the slices to form an array of NDList.

        Parameters:
        list - the NDList that needs to be split
        numOfSlices - the number of slices the list must be sliced into
        evenSplit - whether each slice must have the same shape
        Returns:
        an array of NDList that contains all the slices