Skip to content

Commit

Permalink
Made softmax numerically stable
Browse files Browse the repository at this point in the history
  • Loading branch information
dscolby committed Jan 22, 2024
1 parent 928f542 commit 59315ca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/activation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ julia> softmax([1, 2, 3])
0.6652409557748219
```
"""
softmax(x::Vector{Float64}) = @fastmath exp.(x)/sum(exp.(x))
softmax(x::Vector{Float64}) = @fastmath exp.(x.-maximum(x))/sum(exp.(x.-maximum(x)))

"""
softmax(x)
Expand Down

0 comments on commit 59315ca

Please sign in to comment.