gelu#
- ivy.gelu(x, /, *, approximate=False, complex_mode='jax', out=None)[source]#
Apply the Gaussian error linear unit (GELU) activation function.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array.approximate (
bool
, default:False
) – Whether to approximate, default isTrue
. An approximation is always used if the input array is complex.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- 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, complex_mode='jax', out=None)[source]#
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
, default:False
) – whether to use the approximate version of the gelu function.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.out (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape 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, complex_mode='jax', out=None)[source]#
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 (
Union
[bool
,Container
], default:False
) – whether to use the gelu approximation algorithm or exact formulation.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.complex_mode (
Literal
['split'
,'magnitude'
,'jax'
], default:'jax'
) – optional specifier for how to handle complex data types. Seeivy.func_wrapper.handle_complex_input
for more detail.out (
Optional
[Container
], default:None
) – optional output container, for writing the result to. It must have a shape 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]) }