Class Dropout

  • All Implemented Interfaces:
    Block

    public class Dropout
    extends AbstractBlock
    A dropout layer benefits a network by allowing some units (neurons), and hence their respective connections, of a network to be randomly and temporarily removed by setting its value to 0 only during training by specified probability \(p\), usually set to 0.5. The use of dropout acts as if multiple networks with different architectures had been trained, and during test/inference, the removed unit's output is multiplied by \(p\) as an approximation of the averaged output of all the possible network architectures for that unit. The implementation of dropout gives state-of-the-art performances for diverse tasks as shown in the proposal's paper, suggesting its general-use capability.

    The idea of dropout itself was proposed in 2014, with the purpose of improving the performance of large networks due to co-adaptation, where some connections are stronger and learned more while other connections become weaker and loses their impact on the prediction, resulting in network overfitting. It was also created as an alternative for costly networks, such as large or ensemble networks, by removing several units, hence creating different thinned network architectures and simulates multiple networks within a single network, greatly reducing the computation cost.

    Dropout is recommended to be used when one is trying to optimize an overfitting network or when large dataset is available. It is still quite commonly used in many publications due to its generalization capability. However, using dropout may not prevent overfitting due to variation and limited size of the dataset, and it is reported that dropout layer increases training time by 2-3 times since different simulated multiple networks are trained for each iteration, thus resulting in noisy parameter updates.

    See Also:
    The D2L chapter on dropout
    • Method Detail

      • getOutputShapes

        public Shape[] getOutputShapes​(Shape[] inputShapes)
        Returns the expected output shapes of the block for the specified input shapes.
        Parameters:
        inputShapes - the shapes of the inputs
        Returns:
        the expected output shapes of the block
      • loadMetadata

        public void loadMetadata​(byte loadVersion,
                                 java.io.DataInputStream is)
                          throws java.io.IOException,
                                 MalformedModelException
        Overwrite this to load additional metadata with the parameter values.

        If you overwrite AbstractBaseBlock.saveMetadata(DataOutputStream) or need to provide backward compatibility to older binary formats, you prabably need to overwrite this. This default implementation checks if the version number fits, if not it throws an MalformedModelException. After that it restores the input shapes.

        Overrides:
        loadMetadata in class AbstractBaseBlock
        Parameters:
        loadVersion - the version used for loading this metadata.
        is - the input stream we are loading from
        Throws:
        java.io.IOException - loading failed
        MalformedModelException - data can be loaded but has wrong format
      • dropout

        public static NDList dropout​(NDArray input)
        Applies Dropout to the input.
        Parameters:
        input - input to apply dropout
        Returns:
        output
      • dropout

        public static NDList dropout​(NDArray input,
                                     float rate)
        Applies Dropout to the input.
        Parameters:
        input - input to apply dropout
        rate - Fraction of the input units to drop
        Returns:
        output
      • dropout

        public static NDList dropout​(NDArray input,
                                     float rate,
                                     boolean training)
        Applies Dropout to the input.
        Parameters:
        input - input to apply dropout
        rate - Fraction of the input units to drop
        training - apply dropout if true
        Returns:
        output
      • builder

        public static Dropout.Builder builder()
        Creates a builder to build a Dropout.
        Returns:
        a new builder