We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
def dropout(X, drop_prob): X = X.float() assert 0 <= drop_prob <= 1 keep_prob = 1 - drop_prob # 这种情况下把全部元素都丢弃 if keep_prob == 0: return torch.zeros_like(X) mask = (torch.randn(X.shape) < keep_prob).float() return mask * X / keep_prob
此处randn生成的数不是分布在0-1之间,导致drop_prob为0时也会产生丢弃。
X = torch.arange(16).view(2, 8) dropout(X, 0)
tensor([[ 0., 0., 2., 3., 4., 5., 6., 7.], [ 8., 9., 10., 0., 12., 13., 14., 15.]])
The text was updated successfully, but these errors were encountered:
这里应该用torch.rand()
Sorry, something went wrong.
建议如下使用:
torch.randn(X.shape).uniform_(0, 1)
具体见 PR #39,等待合并 :))
fix bug #17: randn -> rand
737d9c1
No branches or pull requests
此处randn生成的数不是分布在0-1之间,导致drop_prob为0时也会产生丢弃。
The text was updated successfully, but these errors were encountered: