MGUCell

LuxRecurrentLayers.MGUCellType
MGUCell(in_dims => out_dims;
    use_bias=true, train_state=false,
    init_bias=nothing, init_recurrent_bias=nothing,
    init_weight=nothing, init_recurrent_weight=nothing,
    init_state=zeros32)

Minimal gated unit.

Equations

\[\begin{aligned} \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} \right), \\ \tilde{\mathbf{h}}(t) &= \tanh\left( \mathbf{W}_{ih}^{h} \mathbf{x}(t) + \mathbf{b}_{ih}^{h} + \mathbf{W}_{hh}^{h} \left( \mathbf{f}(t) \circ \mathbf{h}(t-1) \right) + \mathbf{b}_{hh}^{h} \right), \\ \mathbf{h}(t) &= \left(1 - \mathbf{f}(t)\right) \circ \mathbf{h}(t-1) + \mathbf{f}(t) \circ \tilde{\mathbf{h}}(t) \end{aligned}\]

Arguments

  • in_dims: Input Dimension
  • out_dims: Output (Hidden State & Memory) Dimension

Keyword Arguments

  • use_bias: Flag to use bias in the computation. Default set to true.
  • train_state: Flag to set the initial hidden state as trainable. Default set to false.
  • init_bias: Initializer for input-to-hidden biases $\mathbf{b}_{ih}^{f}, \mathbf{b}_{ih}^{h}$. Must be a tuple of 2 functions. If a single function is provided, it is expanded to 2 copies. If set to nothing, biases are initialized from a uniform distribution in [-bound, bound] where bound = inv(sqrt(out_dims)). Default is nothing.
  • init_recurrent_bias: Initializer for hidden-to-hidden biases $\mathbf{b}_{hh}^{f}, \mathbf{b}_{hh}^{h}$. Must be a tuple of 2 functions. If a single function is provided, it is expanded to 2 copies. If set to nothing, biases are initialized from a uniform distribution in [-bound, bound] where bound = inv(sqrt(out_dims)). Default is nothing.
  • init_weight: Initializer for input-to-hidden weights $\mathbf{W}_{ih}^{f}, \mathbf{W}_{ih}^{h}$. Must be a tuple of 2 functions. If a single function is provided, it is expanded to 2 copies. If set to nothing, weights are initialized from a uniform distribution in [-bound, bound] where bound = inv(sqrt(out_dims)). Default is nothing.
  • init_recurrent_weight: Initializer for hidden-to-hidden weights $\mathbf{W}_{hh}^{f}, \mathbf{W}_{hh}^{h}$. Must be a tuple of 2 functions. If a single function is provided, it is expanded to 2 copies. If set to nothing, weights are initialized from a uniform distribution in [-bound, bound] where bound = inv(sqrt(out_dims)). Default is nothing.
  • init_state: Initializer for hidden state. Default set to zeros32.

Inputs

  • Case 1a: Only a single input x of shape (in_dims, batch_size), train_state is set to false - Creates a hidden state using init_state and proceeds to Case 2.
  • Case 1b: Only a single input x of shape (in_dims, batch_size), train_state is set to true - Repeats hidden_state from parameters to match the shape of x and 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}$
  • Updated model state

Parameters

  • weight_ih: Input-to-hidden weights $\{ \mathbf{W}_{ih}^{f}, \mathbf{W}_{ih}^{h} \}$ The functions from init_weight are applied in order: the first initializes $\mathbf{W}_{ih}^{f}$, the second $\mathbf{W}_{ih}^{h}$.
  • weight_hh: Hidden-to-hidden weights $\{ \mathbf{W}_{hh}^{f}, \mathbf{W}_{hh}^{h} \}$ The functions from init_recurrent_weight are applied in order: the first initializes $\mathbf{W}_{hh}^{f}$, the second $\mathbf{W}_{hh}^{h}$.
  • bias_ih: Input-to-hidden biases (if use_bias=true) $\{ \mathbf{b}_{ih}^{f}, \mathbf{b}_{ih}^{h} \}$ The functions from init_bias are applied in order: the first initializes $\mathbf{b}_{ih}^{f}$, the second $\mathbf{b}_{ih}^{h}$.
  • bias_hh: Hidden-to-hidden biases (if use_bias=true) $\{ \mathbf{b}_{hh}^{f}, \mathbf{b}_{hh}^{h} \}$ The functions from init_recurrent_bias are applied in order: the first initializes $\mathbf{b}_{hh}^{f}$, the second $\mathbf{b}_{hh}^{h}$.
  • hidden_state: Initial hidden state vector (not present if train_state=false)

States

  • rng: Controls the randomness (if any) in the initial state generation
source