-
Notifications
You must be signed in to change notification settings - Fork 184
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
activation intrinsics for neural networks #860
base: master
Are you sure you want to change the base?
Conversation
Before moving forward, any opinions on
|
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.
Thank you for this implementation @jalvesz, I have left my comments. I am no machine learning expert, so I focused on the code rather than on the actual math of each function.
src/stdlib_specialfunctions.fypp
Outdated
interface tanh_grad | ||
!! Version: experimental | ||
!! | ||
!! gradient of the gaussian function |
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.
Please add a specs description of this function.
!! | ||
!! Fast approximation of the tanh function | ||
!! Source: https://fortran-lang.discourse.group/t/fastgpt-faster-than-pytorch-in-300-lines-of-fortran/5385/31 | ||
#:for rk, rt in REAL_KINDS_TYPES |
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.
Please add a specs description for ftanh
and ferf
in the docs.
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.
Also: I believe a discussion would be needed for fast, approximate versions of intrinsic functions. Different from gamma
(that returns similar accuracy as the intrinsics), these are fast approximations. I'm fine with the f
prefix (or fast_
would also be OK). I believe that should be standardized somewhere, for example in the library style guide?
integer, parameter :: n = 10 | ||
real(sp) :: x(n), y(n), y_ref(n) | ||
|
||
y_ref = [-0.0455002784729 , -0.093188509345055, -0.148066952824593,& |
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.
Should the tests be run for all accuracies?
Co-authored-by: Federico Perini <[email protected]>
Thanks @perazz for your review! regarding tanh and erf, I wonder if I should actually remove reference to the intrinsic names and simply leave a reference to the fast approximation as that is what makes sense for NNs. Also, should these functions stay here or moved to the Regarding
I agree with you and also wonder which one would be preferable, I don't have strong oppinions on that. |
Add activation functions for neural networks. Relates to #858
Todo:
Previous Art
SciPy Special functions collection: https://docs.scipy.org/doc/scipy/reference/special.html
torch nn: https://pytorch.org/docs/stable/nn.html#non-linear-activations-other
neural-fortran : https://github.com/modern-fortran/neural-fortran/blob/main/src/nf/nf_activation.f90
cc: @Beliavsky @milancurcic @epagone @jvdp1 @perazz