gelu#
- ivy.gelu(x, /, *, approximate=False, out=None)[source]#
Apply the Gaussian error linear unit (GELU) activation function.
- Parameters:
- Return type:
- Returns:
ret – The input array with gelu applied element-wise.
Examples
With
ivy.Array
input:>>> x = ivy.array([-1.2, -0.6, 1.5]) >>> y = ivy.gelu(x) >>> y ivy.array([-0.138, -0.165, 1.4])
With
ivy.NativeArray
input:>>> x = ivy.native_array([-1.3, 3.8, 2.1]) >>> y = ivy.gelu(x) >>> y ivy.array([-0.126, 3.8, 2.06])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1., 2.]), b=ivy.array([-0.9, -1.])) >>> y = ivy.gelu(x) >>> y { a: ivy.array([0.841, 1.95]), b: ivy.array([-0.166, -0.159]) }
- Array.gelu(self, /, *, approximate=False, out=None)#
ivy.Array instance method variant of ivy.gelu. This method simply wraps the function, and so the docstring for ivy.gelu also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array.approximate (
bool
) – whether to use the approximate version of the gelu function. (default:False
)out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – an array with the gelu activation function applied element-wise.
Examples
>>> x = ivy.array([-1.2, -0.6, 1.5]) >>> y = x.gelu() >>> print(y) ivy.array([-0.138, -0.165, 1.4])
- Container.gelu(self, /, *, approximate=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
ivy.Container instance method variant of ivy.gelu. This method simply wraps the function, and so the docstring for ivy.gelu also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container.approximate (
bool
) – whether to use the gelu approximation algorithm or exact formulation. (default:False
)key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container with the gelu unit function applied element-wise.
Examples
>>> x = ivy.Container(a=ivy.array([1., 2.]), b=ivy.array([-0.9, -1.])) >>> y = x.gelu() print(y) { a: ivy.array([0.841, 1.95]), b: ivy.array([-0.166, -0.159]) }