-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add logsigmoid (numerically stable) and softshrink #4663
Conversation
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.
LGTM! I will approve it after fixing the comment. Otherwise, the approval will be dismissed.
paddle/operators/activation_op.h
Outdated
@@ -95,6 +95,31 @@ struct SigmoidGradFunctor : public BaseActivationFunctor<T> { | |||
} | |||
}; | |||
|
|||
// Originally: logsigmoid(x) = -log (1 + exp(-x)) | |||
// For numerical stability: logsigmoid(x) = - (max(-x, 0) + log(exp(-max(-x, 0)) | |||
// + exp(-x - max(-x, 0)))) |
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.
maybe we can put the source URL into the comment? (https://hips.seas.harvard.edu/blog/2013/01/09/computing-log-sum-exp/).
For the follow-up maintainers, he may not know the trick, he even cannot check the formula correctness.
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.
Thanks, I added more detailed comments. Please let me know if this seems okay now.
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.
LGTM!
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.
LGTM!
This closes #4622, by adding 2 basic activation functions: logsigmoid and softshrink
However, to make the computation numerically stable for large negative values of x, the well-known "log-sum-exp" trick is employed. (https://hips.seas.harvard.edu/blog/2013/01/09/computing-log-sum-exp/).