File tree Expand file tree Collapse file tree 1 file changed +3
-15
lines changed Expand file tree Collapse file tree 1 file changed +3
-15
lines changed Original file line number Diff line number Diff line change @@ -17,24 +17,12 @@ independent.
17
17
0.244728
18
18
0.665241
19
19
"""
20
- softmax (xs; dims= 1 ) = softmax! (similar (xs), xs, dims)
21
-
22
- function softmax! (out:: AbstractArray{T} , xs:: AbstractArray{T} , dims) where {T}
20
+ function softmax (xs:: AbstractArray{T} ; dims= 1 ) where {T}
23
21
max = maximum (xs, dims= dims)
24
- out .= exp .(xs.- max)
25
- out ./= sum (out, dims= dims)
26
- return out
27
- end
28
-
29
- function ∇softmax! (out:: AbstractVecOrMat , Δ:: AbstractVecOrMat , xs:: AbstractVecOrMat )
30
- sf = softmax (xs)
31
- out .= sf .* (Δ .- sum (Δ .* sf, dims = 1 ))
22
+ out = exp .(xs .- max)
23
+ out = out ./ sum (out, dims= dims)
32
24
end
33
25
34
- ∇softmax (Δ, xs) = ∇softmax! (similar (Δ), Δ, xs)
35
- ∇softmax! (Δ, xs) = ∇softmax! (Δ, Δ, xs)
36
-
37
-
38
26
"""
39
27
logsoftmax(xs) = log.(exp.(xs) ./ sum(exp.(xs)))
40
28
You can’t perform that action at this time.
0 commit comments