Code
Algorithm for a Dropout Layer
A dropout layer can be implemented algorithmically from scratch by first checking if the dropout probability equals ; if so, it immediately returns a tensor of zeros. For , it generates a boolean mask by evaluating where a tensor of uniform random numbers is strictly greater than . This boolean mask is cast to a floating-point format, multiplied element-wise with the input tensor, and divided by to rescale the surviving elements.
0
1
Updated 2026-05-07
Tags
D2L
Dive into Deep Learning @ D2L