(x, approximate=False)
| 104 | |
| 105 | def test_gelu(self): |
| 106 | def gelu(x, approximate=False): |
| 107 | if approximate: |
| 108 | return 0.5 * x * (1.0 + np.tanh(np.sqrt(2.0 / np.pi) * |
| 109 | (x + 0.044715 * np.power(x, 3)))) |
| 110 | else: |
| 111 | from scipy.stats import norm # pylint: disable=g-import-not-at-top |
| 112 | return x * norm.cdf(x) |
| 113 | x = keras.backend.placeholder(ndim=2) |
| 114 | f = keras.backend.function([x], [keras.activations.gelu(x)]) |
| 115 | test_values = np.random.random((2, 5)) |