-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Fix AlphaDropout implementation and add tests #1781
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,17 +101,18 @@ mutable struct AlphaDropout{F} | |
end | ||
end | ||
|
||
function (a::AlphaDropout)(x) | ||
function (a::AlphaDropout)(x::AbstractArray{T}) where T | ||
_isactive(a) || return x | ||
λ = eltype(x)(1.0507009873554804934193349852946) | ||
α = eltype(x)(1.6732632423543772848170429916717) | ||
α1 = eltype(x)(-λ*α) | ||
noise = randn(eltype(x), size(x)) | ||
x = @. x*(noise > (1 - a.p)) + α1 * (noise < (1 - a.p)) | ||
A = sqrt(a.p + a.p * (1 - a.p) * α1^2) | ||
B = -A * α1 * (1 - a.p) | ||
x = @. A * x + B | ||
return x | ||
p = a.p | ||
iszero(p) && return x | ||
isone(p) && return sign.(x) .* T(0) | ||
|
||
α′ = T(-1.7580993408473766) # selu(-Inf) == -λα | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
A = T(inv(sqrt((1 - p) * (1 + p * α′^2)))) | ||
B = T(-A * α′ * p) | ||
|
||
noise = rand!(similar(x)) | ||
return A .* ifelse.(noise .> p, x, α′) .+ B | ||
end | ||
|
||
testmode!(m::AlphaDropout, mode=true) = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? Are we intentionally creating
-0.0
values here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, see point 2 in #1781 (comment).