The RNN class implements a multi-layer recurrent neural network (RNN). It supports stacked RNN layers, where each layer processes the input sequence and passes its output to the next layer. The class also provides methods for parameter retrieval and forward computation.
Value parameters
- activation
-
activation function to use: "tanh" (default) or "relu"
- hiddenSize
-
number of features in the hidden state
- inputSize
-
number of features in the input at each time step
- numLayers
-
number of stacked RNN layers (default: 1)
- ops
-
implicit autograd operations
Attributes
- See also
- Companion
- object
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Perform the forward pass through all layers of the RNN. Processes the input sequence through each layer, updating the hidden states at each time step. Optionally supports truncated backpropagation through time (TBPTT).
Perform the forward pass through all layers of the RNN. Processes the input sequence through each layer, updating the hidden states at each time step. Optionally supports truncated backpropagation through time (TBPTT).
Value parameters
- h0
-
optional initial hidden states for each layer (default: zero-initialized)
- inputSeq
-
the input sequence, where each element is a tensor of shape (batchSize, inputDim, 1)
- tbptt
-
the truncation interval for TBPTT (default: 0, meaning no truncation)
Attributes
- Returns
-
a tuple containing: - the output sequence from the top layer (one tensor per time step) - the final hidden states for all layers
- Throws
-
IllegalArgumentException
if the input sequence is empty
Retrieve a specific layer of the RNN.
Retrieve a specific layer of the RNN.
Value parameters
- i
-
index of the layer to retrieve
Attributes
- Returns
-
the
RNNBaseinstance representing the layer
Retrieve the parameters of all layers in the RNN.
Retrieve the parameters of all layers in the RNN.
Attributes
- Returns
-
an indexed sequence of
Variablobjects representing the parameters - Definition Classes
Inherited methods
Set the module to evaluation mode (and all submodules recursively).
Set the module to evaluation mode (and all submodules recursively).
Attributes
- Inherited from:
- BaseModule
Return the gradients of all parameters.
Replace the current parameters with new ones. Useful for weight updates, loading saved models, etc.
Replace the current parameters with new ones. Useful for weight updates, loading saved models, etc.
Value parameters
- newParams
-
The new parameter list to assign
Attributes
- Inherited from:
- BaseModule
Set the module to training mode (and all submodules recursively).
Set the module to training mode (and all submodules recursively).
Attributes
- Inherited from:
- BaseModule
Zero out all gradients (in-place).
Concrete fields
Inherited fields
Flag to control training or evaluation behavior.
Automatically detect submodules (other BaseModules) within this module.
Automatically detect submodules (other BaseModules) within this module.
Attributes
- Inherited from:
- BaseModule