add nn module for sigmoid activation (#111)

* add nn module for sigmoid activation

* update .gitignore with .cache folder generated by jetbrains fleet ide

* remove .cache folder
This commit is contained in:
Henry Ansah 2023-12-10 15:00:39 +00:00 committed by GitHub
parent 600db7d754
commit 68bf1d7867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

3
.gitignore vendored
View File

@ -74,3 +74,6 @@ build/
# VSCode # VSCode
.vscode/ .vscode/
.DS_Store .DS_Store
# Jetbrains
.cache

View File

@ -15,6 +15,16 @@ def _make_activation_module(f):
return decorator return decorator
def sigmoid(x):
r"""Applies the element-wise function:
.. math::
\text{Sigmoid}(x) = \sigma(x) = \frac{1}{1 + \exp(-x)}
"""
return mx.sigmoid(x)
def relu(x): def relu(x):
"""Applies the Rectified Linear Unit. """Applies the Rectified Linear Unit.
@ -79,6 +89,9 @@ def gelu_fast_approx(x):
""" """
return x * mx.sigmoid(1.773 * x) return x * mx.sigmoid(1.773 * x)
@_make_activation_module
class Sigmoid(Module):
pass
@_make_activation_module(relu) @_make_activation_module(relu)
class ReLU(Module): class ReLU(Module):