Class GRU

All Implemented Interfaces:
AutoCloseable

public final class GRU extends Module
A stack of GRU layers over [T, B, I] sequences (time first), optionally bidirectional, PyTorch's nn.GRU equations, gate order, parameter order and initialisation: every weight and bias uniform in [-1/sqrt(H), 1/sqrt(H)). Parameters per layer and direction (forward, then reverse): W_ih [3H, in], W_hh [3H, H], b_ih, b_hh [3H]. Padded batches pass their sequence lengths: outputs past a length are 0 and the final states are each sequence's last.
  • Constructor Details

    • GRU

      public GRU(int input, int hidden, int layers, long seed)
      layers unidirectional GRU layers from input to hidden features, initialised from seed.
    • GRU

      public GRU(int input, int hidden, int layers, boolean bidirectional, long seed)
      layers GRU layers from input to hidden features, optionally bidirectional, initialised from seed.
  • Method Details

    • hidden

      public int hidden()
      The hidden size per direction.
    • forward

      public Tensor forward(Tensor x)
      Output sequence of the last layer, from zero initial states.
      Specified by:
      forward in class Module
    • forward

      public GRU.Output forward(Tensor x, Tensor h0, int[] lengths)
      From initial states [layers directions, B, H] (null: zeros), for sequences of lengths (null: all T).