Skip to content
New issue

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

关于3.13章丢弃法的疑惑 #17

Closed
VittorioYan opened this issue Sep 30, 2019 · 2 comments
Closed

关于3.13章丢弃法的疑惑 #17

VittorioYan opened this issue Sep 30, 2019 · 2 comments

Comments

@VittorioYan
Copy link

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.]])
@biggoood
Copy link

biggoood commented Oct 9, 2019

这里应该用torch.rand()

@yongboy
Copy link
Contributor

yongboy commented Oct 23, 2019

建议如下使用:

torch.randn(X.shape).uniform_(0, 1)

具体见 PR #39,等待合并 :))

ShusenTang added a commit that referenced this issue Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants