Dropout Layers#
IndependentDropout#
- class supar.modules.dropout.IndependentDropout(p: float = 0.5)[source]#
For \(N\) tensors, they use different dropout masks respectively. When \(N-M\) of them are dropped, the remaining \(M\) ones are scaled by a factor of \(N/M\) to compensate, and when all of them are dropped together, zeros are returned.
- Parameters:
p (float) – The probability of an element to be zeroed. Default: 0.5.
Examples
>>> batch_size, seq_len, hidden_size = 1, 3, 5 >>> x, y = torch.ones(batch_size, seq_len, hidden_size), torch.ones(batch_size, seq_len, hidden_size) >>> x, y = IndependentDropout()(x, y) >>> x tensor([[[1., 1., 1., 1., 1.], [0., 0., 0., 0., 0.], [2., 2., 2., 2., 2.]]]) >>> y tensor([[[1., 1., 1., 1., 1.], [2., 2., 2., 2., 2.], [0., 0., 0., 0., 0.]]])