WMCLSTMCell
LuxRecurrentLayers.WMCLSTMCell
— TypeWMCLSTMCell(in_dims => out_dims;
use_bias=true, train_state=false, train_memory=false,
init_bias=nothing, init_recurrent_bias=nothing, init_memory_bias=nothing,
init_weight=nothing, init_recurrent_weight=nothing,
init_memory_weight=nothing, init_state=zeros32, init_memory=zeros32)
Long short term memory cell with working memory connections.
Equations
\[\begin{aligned} \mathbf{i}(t) &= \sigma\left( \mathbf{W}_{ih}^{i} \mathbf{x}(t) + \mathbf{b}_{ih}^{i} + \mathbf{W}_{hh}^{i} \mathbf{h}(t-1) + \mathbf{b}_{hh}^{i} + \mathbf{W}_{mh}^{i} \mathbf{c}(t-1) + \mathbf{b}_{mh}^{i} \right), \\ \mathbf{f}(t) &= \sigma\left( \mathbf{W}_{ih}^{f} \mathbf{x}(t) + \mathbf{b}_{ih}^{f} + \mathbf{W}_{hh}^{f} \mathbf{h}(t-1) + \mathbf{b}_{hh}^{f} + \mathbf{W}_{mh}^{f} \mathbf{c}(t-1) + \mathbf{b}_{mh}^{f} \right), \\ \mathbf{c}(t) &= \mathbf{f}(t) \circ \mathbf{c}(t-1) + \mathbf{i}(t) \circ \sigma_c\left( \mathbf{W}_{ih}^{c} \mathbf{x}(t) + \mathbf{b}_{ih}^{c} \right), \\ \mathbf{o}(t) &= \sigma\left( \mathbf{W}_{ih}^{o} \mathbf{x}(t) + \mathbf{b}_{ih}^{o} + \mathbf{W}_{hh}^{o} \mathbf{h}(t-1) + \mathbf{b}_{hh}^{o} + \mathbf{W}_{mh}^{o} \mathbf{c}(t) + \mathbf{b}_{mh}^{o} \right), \\ \mathbf{h}(t) &= \mathbf{o}(t) \circ \sigma_h\left( \mathbf{c}(t) \right) \end{aligned} \]
Arguments
in_dims
: Input Dimensionout_dims
: Output (Hidden State & Memory) Dimension
Keyword Arguments
use_bias
: Flag to use bias in the computation. Default set totrue
.train_state
: Flag to set the initial hidden state as trainable. Default set tofalse
.train_memory
: Flag to set the initial memory state as trainable. Default set tofalse
.init_bias
: Initializer for input-to-hidden biases $\mathbf{b}_{ih}^{i}, \mathbf{b}_{ih}^{f}, \mathbf{b}_{ih}^{c}, \mathbf{b}_{ih}^{o}$. Must be a tuple containing 4 functions. If a single value is passed, it is copied into a 4-element tuple. If set tonothing
, biases are initialized from a uniform distribution within[-bound, bound]
, wherebound = \mathrm{inv}(\sqrt{\mathrm{out\_dims}})
. The functions are applied in order: the first initializes $\mathbf{b}_{ih}^{i}$, the second $\mathbf{b}_{ih}^{f}$, the third $\mathbf{b}_{ih}^{c}$, the fourth $\mathbf{b}_{ih}^{o}$. Default set tonothing
.init_recurrent_bias
: Initializer for hidden-to-hidden biases $\mathbf{b}_{hh}^{i}, \mathbf{b}_{hh}^{f}, \mathbf{b}_{hh}^{o}$. Must be a tuple containing 3 functions. If a single value is passed, it is copied into a 3-element tuple. If set tonothing
, biases are initialized from a uniform distribution within[-bound, bound]
, wherebound = \mathrm{inv}(\sqrt{\mathrm{out\_dims}})
. The functions are applied in order: the first initializes $\mathbf{b}_{hh}^{i}$, the second $\mathbf{b}_{hh}^{f}$, the third $\mathbf{b}_{hh}^{o}$. Default set tonothing
.init_memory_bias
: Initializer for memory-to-hidden biases $\mathbf{b}_{mh}^{i}, \mathbf{b}_{mh}^{f}, \mathbf{b}_{mh}^{o}$. Must be a tuple containing 3 functions. If a single value is passed, it is copied into a 3-element tuple. If set tonothing
, biases are initialized from a uniform distribution within[-bound, bound]
, wherebound = \mathrm{inv}(\sqrt{\mathrm{out\_dims}})
. The functions are applied in order: the first initializes $\mathbf{b}_{mh}^{i}$, the second $\mathbf{b}_{mh}^{f}$, the third $\mathbf{b}_{mh}^{o}$. Default set tonothing
.init_weight
: Initializer for input-to-hidden weights $\mathbf{W}_{ih}^{i}, \mathbf{W}_{ih}^{f}, \mathbf{W}_{ih}^{c}, \mathbf{W}_{ih}^{o}$. Must be a tuple containing 4 functions. If a single value is passed, it is copied into a 4-element tuple. If set tonothing
, weights are initialized from a uniform distribution within[-bound, bound]
, wherebound = \mathrm{inv}(\sqrt{\mathrm{out\_dims}})
. The functions are applied in order: the first initializes $\mathbf{W}_{ih}^{i}$, the second $\mathbf{W}_{ih}^{f}$, the third $\mathbf{W}_{ih}^{c}$, the fourth $\mathbf{W}_{ih}^{o}$. Default set tonothing
.init_recurrent_weight
: Initializer for hidden-to-hidden weights $\mathbf{W}_{hh}^{i}, \mathbf{W}_{hh}^{f}, \mathbf{W}_{hh}^{o}$. Must be a tuple containing 3 functions. If a single value is passed, it is copied into a 3-element tuple. If set tonothing
, weights are initialized from a uniform distribution within[-bound, bound]
, wherebound = \mathrm{inv}(\sqrt{\mathrm{out\_dims}})
. The functions are applied in order: the first initializes $\mathbf{W}_{hh}^{i}$, the second $\mathbf{W}_{hh}^{f}$, the third $\mathbf{W}_{hh}^{o}$. Default set tonothing
.init_memory_weight
: Initializer for memory-to-hidden weights $\mathbf{W}_{mh}^{i}, \mathbf{W}_{mh}^{f}, \mathbf{W}_{mh}^{o}$. Must be a tuple containing 3 functions. If a single value is passed, it is copied into a 3-element tuple. If set tonothing
, weights are initialized from a uniform distribution within[-bound, bound]
, wherebound = \mathrm{inv}(\sqrt{\mathrm{out\_dims}})
. The functions are applied in order: the first initializes $\mathbf{W}_{mh}^{i}$, the second $\mathbf{W}_{mh}^{f}$, the third $\mathbf{W}_{mh}^{o}$. Default set tonothing
.init_state
: Initializer for hidden state. Default set tozeros32
.init_memory
: Initializer for memory. Default set tozeros32
.
Inputs
- Case 1a: Only a single input
x
of shape(in_dims, batch_size)
,train_state
is set tofalse
,train_memory
is set tofalse
- Creates a hidden state usinginit_state
, hidden memory usinginit_memory
and proceeds to Case 2. - Case 1b: Only a single input
x
of shape(in_dims, batch_size)
,train_state
is set totrue
,train_memory
is set tofalse
- Repeatshidden_state
vector from the parameters to match the shape ofx
, creates hidden memory usinginit_memory
and proceeds to Case 2. - Case 1c: Only a single input
x
of shape(in_dims, batch_size)
,train_state
is set tofalse
,train_memory
is set totrue
- Creates a hidden state usinginit_state
, repeats the memory vector from parameters to match the shape ofx
and proceeds to Case 2. - Case 1d: Only a single input
x
of shape(in_dims, batch_size)
,train_state
is set totrue
,train_memory
is set totrue
- Repeats the hidden state and memory vectors from the parameters to match the shape ofx
and proceeds to Case 2. - Case 2: Tuple
(x, (h, c))
is provided, then the output and a tuple containing the updated hidden state and memory is returned.
Returns
Tuple Containing
- Output $h_{new}$ of shape
(out_dims, batch_size)
- Tuple containing new hidden state $h_{new}$ and new memory $c_{new}$
- Output $h_{new}$ of shape
Updated model state
Parameters
weight_ih
: Concatenated weights to map from input space $\{ \mathbf{W}_{ih}^{f}, \mathbf{W}_{ih}^{c}, \mathbf{W}_{ih}^{i}, \mathbf{W}_{ih}^{o} \}$.weight_hh
: Concatenated weights to map from hidden space $\{ \mathbf{W}_{hh}^{f}, \mathbf{W}_{hh}^{c}, \mathbf{W}_{hh}^{i}, \mathbf{W}_{hh}^{o} \}$.weight_mh
: Concatenated weights to map from memory space $\{ \mathbf{W}_{mh}^{f}, \mathbf{W}_{mh}^{c}, \mathbf{W}_{mh}^{i} \}$.bias_ih
: Concatenated bias vector for the input-hidden connection (not present ifuse_bias=false
) $\{ \mathbf{b}_{ih}^{f}, \mathbf{b}_{ih}^{c}, \mathbf{b}_{ih}^{i}, \mathbf{b}_{ih}^{o} \}$.bias_hh
: Concatenated bias vector for the hidden-hidden connection (not present ifuse_bias=false
) $\{ \mathbf{b}_{hh}^{f}, \mathbf{b}_{hh}^{i}, \mathbf{b}_{hh}^{o} \}$.bias_mh
: Concatenated bias vector for the memory-hidden connection (not present ifuse_bias=false
) $\{ \mathbf{b}_{mh}^{f}, \mathbf{b}_{mh}^{i}, \mathbf{b}_{mh}^{o} \}$.hidden_state
: Initial hidden state vector (not present iftrain_state=false
)memory
: Initial memory vector (not present iftrain_memory=false
)
States
rng
: Controls the randomness (if any) in the initial state generation