Search notes:
torch.nn.Dropout
torch.nn.Dropout
(which is kind of an alias for
torch.nn.modules.dropout.Dropout
) inherits (indirectly) from
torch.nn.Module
.
Set elements of the input tensor to zero with a given probability (here: p
) and adjust the the other elements with 1/(1-p)
.
import torch
torch.manual_seed(27)
p = 0.25
drp = torch.nn.Dropout( p )
tns = torch.Tensor([ [-1.0,2.0] , [4.0,5.0] ])
print(tns)
#
# tensor([[-1., 2.],
# [ 4., 5.]])
print(drp(tns))
#
# tensor([[-0.0000, 2.6667],
# [5.3333, 6.6667]])