lstm_update#
- ivy.lstm_update(x, init_h, init_c, kernel, recurrent_kernel, /, *, bias=None, recurrent_bias=None)[source]#
Perform long-short term memory update by unrolling time dimension of input array.
- Parameters:
x (
Union
[Array
,NativeArray
]) – input tensor of LSTM layer [batch_shape, t, in].init_h (
Union
[Array
,NativeArray
]) – initial state tensor for the cell output [batch_shape, out].init_c (
Union
[Array
,NativeArray
]) – initial state tensor for the cell hidden state [batch_shape, out].kernel (
Union
[Array
,NativeArray
]) – weights for cell kernel [in, 4 x out].recurrent_kernel (
Union
[Array
,NativeArray
]) – weights for cell recurrent kernel [out, 4 x out].bias (
Optional
[Union
[Array
,NativeArray
]]) – bias for cell kernel [4 x out]. (Default value = None) (default:None
)recurrent_bias (
Optional
[Union
[Array
,NativeArray
]]) – bias for cell recurrent kernel [4 x out]. (Default value = None) (default:None
)
- Return type:
- Returns:
ret – hidden state for all timesteps [batch_shape,t,out] and cell state for last timestep [batch_shape,out]
- Array.lstm_update(self, init_h, init_c, kernel, recurrent_kernel, /, *, bias=None, recurrent_bias=None)#
ivy.Array instance method variant of ivy.lstm_update. This method simply wraps the function, and so the docstring for ivy.lstm_update also applies to this method with minimal changes.
- Parameters:
init_h (
Union
[Array
,NativeArray
]) – initial state tensor for the cell output [batch_shape, out].init_c (
Union
[Array
,NativeArray
]) – initial state tensor for the cell hidden state [batch_shape, out].kernel (
Union
[Array
,NativeArray
]) – weights for cell kernel [in, 4 x out].recurrent_kernel (
Union
[Array
,NativeArray
]) – weights for cell recurrent kernel [out, 4 x out].bias (
Optional
[Union
[Array
,NativeArray
]]) – bias for cell kernel [4 x out]. (Default value = None) (default:None
)recurrent_bias (
Optional
[Union
[Array
,NativeArray
]]) – bias for cell recurrent kernel [4 x out]. (Default value = None) (default:None
)
- Return type:
Tuple
[Array
,Array
]- Returns:
ret – hidden state for all timesteps [batch_shape,t,out] and cell state for last timestep [batch_shape,out]
Examples
>>> x = ivy.randint(0, 20, shape=(6, 20, 3)) >>> h_i = ivy.random_normal(shape=(6, 5)) >>> c_i = ivy.random_normal(shape=(6, 5)) >>> kernel = ivy.random_normal(shape=(3, 4 * 5)) >>> rc = ivy.random_normal(shape=(5, 4 * 5)) >>> result = x.lstm_update(h_i, c_i, kernel, rc)
>>> result[0].shape (6, 20, 5) >>> result[1].shape (6, 5)
- Container.lstm_update(self, init_h, init_c, kernel, recurrent_kernel, /, *, bias=None, recurrent_bias=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)#
ivy.Container instance method variant of ivy.lstm_update. This method simply wraps the function, and so the docstring for ivy.lstm_update also applies to this method with minimal changes.
- Parameters:
init_h (
Union
[Array
,NativeArray
,Container
]) – initial state tensor for the cell output [batch_shape, out].init_c (
Union
[Array
,NativeArray
,Container
]) – initial state tensor for the cell hidden state [batch_shape, out].kernel (
Union
[Array
,NativeArray
,Container
]) – weights for cell kernel [in, 4 x out].recurrent_kernel (
Union
[Array
,NativeArray
,Container
]) – weights for cell recurrent kernel [out, 4 x out].bias (
Optional
[Union
[Array
,NativeArray
,Container
]]) – bias for cell kernel [4 x out]. (Default value = None) (default:None
)recurrent_bias (
Optional
[Union
[Array
,NativeArray
,Container
]]) – bias for cell recurrent kernel [4 x out]. (Default value = None) (default:None
)
- Return type:
Tuple
[Container
,Container
]- Returns:
ret – hidden state for all timesteps [batch_shape,t,out] and cell state for last timestep [batch_shape,out]
Examples
>>> x = ivy.Container( ... a=ivy.random_normal(shape=(5, 20, 3)), ... b=ivy.random_normal(shape=(5, 20, 3)) ... ) >>> h_i = ivy.random_normal(shape=(5, 6)) >>> c_i = ivy.random_normal(shape=(5, 6))
>>> kernel = ivy.random_normal(shape=(3, 4 * 6)) >>> rc = ivy.random_normal(shape=(6, 4 * 6)) >>> x.lstm_update(h_i, c_i, kernel, rc) { a: (tuple(2), <class ivy.array.array.Array>, shape=[5, 20, 6]), b: (tuple(2), <class ivy.array.array.Array>, shape=[5, 20, 6]) }