SGRNCell
LuxRecurrentLayers.SGRNCell — TypeSGRNCell(in_dims => out_dims;
use_bias=true, use_recurrent_bias=true, train_state=false,
init_bias=nothing, init_recurrent_bias=nothing,
init_weight=nothing, init_recurrent_weight=nothing,
init_state=zeros32)Simple gated recurrent network.
Equations
\[\begin{aligned} \mathbf{f}(t) &= \sigma\left( \mathbf{W}_{ih} \mathbf{x}(t) + \mathbf{b}_{ih} + \mathbf{W}_{hh} \mathbf{h}(t-1) + \mathbf{b}_{hh} \right), \\ \mathbf{i}(t) &= 1 - \mathbf{f}(t), \\ \mathbf{h}(t) &= \tanh\left( \mathbf{i}(t) \circ \left( \mathbf{W}_{ih} \mathbf{x}(t) + \mathbf{b}_{ih} \right) + \mathbf{f}(t) \circ \mathbf{h}(t-1) \right) \end{aligned}\]
Arguments
in_dims: Input Dimensionout_dims: Output (Hidden State & Memory) Dimension
Keyword Arguments
use_bias: Flag to use bias $\mathbf{b}_{ih}$ in the computation. Default set totrue.use_recurrent_bias: Flag to use recurrent bias $\mathbf{b}_{hh}$ in the computation. Default set totrue.train_state: Flag to set the initial hidden state as trainable. Default set tofalse.init_bias: Initializer for input-to-hidden bias $\mathbf{b}_{ih}$. Must be a single function. If set tonothing, bias is initialized from a uniform distribution within[-bound, bound], wherebound = inv(sqrt(out_dims)). Default set tonothing.init_recurrent_bias: Initializer for hidden-to-hidden bias $\mathbf{b}_{hh}$. Must be a single function. If set tonothing, bias is initialized from a uniform distribution within[-bound, bound], wherebound = inv(sqrt(out_dims)). Default set tonothing.init_weight: Initializer for input-to-hidden weight $\mathbf{W}_{ih}$. Must be a single function. If set tonothing, weight is initialized from a uniform distribution within[-bound, bound], wherebound = inv(sqrt(out_dims)). Default set tonothing.init_recurrent_weight: Initializer for hidden-to-hidden weight $\mathbf{W}_{hh}$. Must be a single function. If set tonothing, weight is initialized from a uniform distribution within[-bound, bound], wherebound = inv(sqrt(out_dims)). Default set tonothing.init_state: Initializer for hidden state. Default set tozeros32.
Inputs
- Case 1a: Only a single input
xof shape(in_dims, batch_size),train_stateis set tofalse- Creates a hidden state usinginit_stateand proceeds to Case 2. - Case 1b: Only a single input
xof shape(in_dims, batch_size),train_stateis set totrue- Repeatshidden_statefrom parameters to match the shape ofxand proceeds to Case 2. - Case 2: Tuple
(x, (h, ))is provided, then the output and a tuple containing the updated hidden state is returned.
Returns
Tuple containing
- Output $h_{new}$ of shape
(out_dims, batch_size) - Tuple containing new hidden state $h_{new}$
- Output $h_{new}$ of shape
Updated model state
Parameters
weight_ih: Input-to-hidden weight $\{ \mathbf{W} \}$weight_hh: Hidden-to-hidden weight $\{ \mathbf{U} \}$bias_ih: Input-to-hidden bias (not present ifuse_bias=false) $\{ \mathbf{b} \}$bias_hh: Hidden-to-hidden bias (not present ifuse_bias=false) $\{ \mathbf{b}_{hh} \}$hidden_state: Initial hidden state vector (not present iftrain_state=false)
States
rng: Controls the randomness (if any) in the initial state generation