GRU

scalation.modeling.autograd.GRU
See theGRU companion object
class GRU(inputSize: Int, hiddenSize: Int, val numLayers: Int = ...) extends BaseModule

The GRU class implements a multi-layer gated recurrent unit (GRU) network. It supports stacked GRU 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

hiddenSize

number of features in the hidden state

inputSize

number of features in the input at each time step

numLayers

number of stacked GRU layers (default: 1)

Attributes

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

Members list

Value members

Concrete methods

def forward(inputSeq: IndexedSeq[Variabl], h0: Option[IndexedSeq[Variabl]] = ..., tbptt: Int = ...): (IndexedSeq[Variabl], IndexedSeq[Variabl])

Perform the forward pass through all layers of the GRU. 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 GRU. 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

def layer(i: Int): RNNBase

Retrieve a specific layer of the GRU.

Retrieve a specific layer of the GRU.

Value parameters

i

index of the layer to retrieve

Attributes

Returns

the RNNBase instance representing the layer

override def parameters: IndexedSeq[Variabl]

Retrieve the parameters of all layers in the GRU.

Retrieve the parameters of all layers in the GRU.

Attributes

Returns

an indexed sequence of Variabl objects representing the parameters

Definition Classes

Inherited methods

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 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 numLayers: Int

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