RNNCell

scalation.modeling.autograd.RNNCell
See theRNNCell companion object
class RNNCell(inputSize: Int, hiddenSize: Int, activation: String = ...)(using ops: AutogradOps)

The RNNCell class supports a simple RNN cell that updates the hidden state: h' = activation(W_ih * x + b_ih + W_hh * h + b_hh) using two biases instead of one.

Value parameters

activation

activation function to use: "tanh" (default) or "relu"

hiddenSize

number of hidden units

inputSize

number of input features

Attributes

See also
Companion
object
Graph
Supertypes
class SeqModule
class BaseModule
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def forward(inputs: IndexedSeq[Variabl]): IndexedSeq[Variabl]

Perform the forward pass for the RNN cell using fused operations. Computes the next hidden state based on the input and the previous hidden state.

Perform the forward pass for the RNN cell using fused operations. Computes the next hidden state based on the input and the previous hidden state.

Value parameters

inputs

an indexed sequence containing: - input: the input tensor at the current time step - hPrev: the hidden state tensor from the previous time step

Attributes

Returns

an indexed sequence containing the next hidden state tensor

Throws
IllegalArgumentException

if the number of inputs is not exactly 2

Definition Classes
def forwardUnfused(inputs: IndexedSeq[Variabl]): IndexedSeq[Variabl]

Perform the forward pass for the RNN cell without using fused operations. Computes the next hidden state based on the input and the previous hidden state.

Perform the forward pass for the RNN cell without using fused operations. Computes the next hidden state based on the input and the previous hidden state.

Value parameters

inputs

an indexed sequence containing: - input: the input tensor at the current time step - hPrev: the hidden state tensor from the previous time step

Attributes

Returns

an indexed sequence containing the next hidden state tensor

Throws
IllegalArgumentException

if the number of inputs is not exactly 2

override def numTrackingStates: Int

Number of state tensors tracked by the cell (e.g., 1 for RNN/GRU, 2 for LSTM).

Number of state tensors tracked by the cell (e.g., 1 for RNN/GRU, 2 for LSTM).

Attributes

Definition Classes
RNNCellBase
override def parameters: IndexedSeq[Variabl]

Return the parameters of the cell.

Return the parameters of the cell.

Attributes

Returns

sequence of parameters

Definition Classes
RNNCellBase -> BaseModule

Inherited methods

def apply(inputs: IndexedSeq[Variabl]): IndexedSeq[Variabl]

Alias for forward, allows calling the module as a function: module(xs).

Alias for forward, allows calling the module as a function: module(xs).

Attributes

Inherited from:
SeqModule
def eval(): Unit

Set the module to evaluation mode (and all submodules recursively).

Set the module to evaluation mode (and all submodules recursively).

Attributes

Inherited from:
BaseModule
def gradients: IndexedSeq[TensorD]

Return the gradients of all parameters.

Return the gradients of all parameters.

Attributes

Inherited from:
BaseModule
def initialTrackingStates(batchSize: Int): IndexedSeq[Variabl]

Create a batch of zero-initialized tracking states. You pass in the batch size to get properly shaped tensors: (batchSize, hiddenSize, 1)

Create a batch of zero-initialized tracking states. You pass in the batch size to get properly shaped tensors: (batchSize, hiddenSize, 1)

Attributes

Inherited from:
RNNCellBase (hidden)
def setParameters(newParams: IndexedSeq[Variabl]): Unit

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
def train(mode: Boolean = ...): Unit

Set the module to training mode (and all submodules recursively).

Set the module to training mode (and all submodules recursively).

Attributes

Inherited from:
BaseModule
def zeroGrad()(using ops: AutogradOps): Unit

Zero out all gradients (in-place).

Zero out all gradients (in-place).

Attributes

Inherited from:
BaseModule

Concrete fields

val W_hh: Variabl
val W_ih: Variabl
val activationFun: String
val b_hh: Variabl
val b_ih: Variabl

Inherited fields

var inTrainingMode: Boolean

Flag to control training or evaluation behavior.

Flag to control training or evaluation behavior.

Attributes

Inherited from:
BaseModule
lazy val subModules: IndexedSeq[BaseModule]

Automatically detect submodules (other BaseModules) within this module.

Automatically detect submodules (other BaseModules) within this module.

Attributes

Inherited from:
BaseModule