Skip to content

Commit 6c61abc

Browse files
authored
Merge pull request #107 from lucasb-eyer/gelu
Add GELU non-linearity.
2 parents 1ef598a + 1e5b2b2 commit 6c61abc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

DeepFried2/layers/GELU.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import DeepFried2 as df
2+
3+
class GELU(df.Module):
4+
""" Gaussian Error Linear Unit (https://arxiv.org/abs/1606.08415) """
5+
6+
def symb_forward(self, x):
7+
""" A very close, much more efficient approximation. """
8+
return 0.5 * x * (1 + df.T.tanh(0.79788456 * (x + 0.044715 * x*x*x)))
9+

DeepFried2/layers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .Bias import Bias
44
from .Dropout import Dropout
55
from .Embedding import Embedding
6+
from .GELU import GELU
67
from .Identity import Identity
78
from .Linear import Linear
89
from .Log import Log

0 commit comments

Comments
 (0)