LSTMLayer class

A Long Short-Term Memory (LSTM) layer.

An LSTMLayer is an advanced recurrent layer designed to overcome the short-term memory limitations of a simple RNN. It excels at learning long-term dependencies in sequential data.

It achieves this by using a dedicated cell state (c) for long-term memory, which acts like a conveyor belt where information can travel across many timesteps without being significantly altered.

A series of gates (Forget, Input, and Output) intelligently control the flow of information into and out of this cell state.

  • Input: A Tensor<Matrix> representing the sequence, with a shape of [sequence_length, input_size].
  • Output: A Tensor<Vector> representing the final hidden state after processing the entire sequence, with a shape of [hidden_size].

Example

// An LSTM layer with 32 memory units.
Layer lstm = LSTMLayer(32);

// An input sequence with 10 timesteps and 5 features each.
Tensor<Matrix> sequence = Tensor<Matrix>(...);

// The output is the final hidden state vector of length 32.
Tensor<Vector> finalState = lstm.call(sequence) as Tensor<Vector>;
Inheritance

Constructors

LSTMLayer(int hiddenSize)

Properties

b_c Tensor<Vector>
getter/setter pair
b_f Tensor<Vector>
getter/setter pair
b_i Tensor<Vector>
getter/setter pair
b_o Tensor<Vector>
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hiddenSize int
The number of units in the hidden state and cell state.
getter/setter pair
name String
A user-friendly name for the layer (e.g., 'dense', 'lstm').
getter/setter pairoverride-getter
parameters List<Tensor>
Provides all 8 trainable parameter tensors to the optimizer.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
W_c Tensor<Matrix>
Weights and biases for the Candidate Cell State.
getter/setter pair
W_f Tensor<Matrix>
Weights and biases for the Forget Gate.
getter/setter pair
W_i Tensor<Matrix>
Weights and biases for the Input Gate.
getter/setter pair
W_o Tensor<Matrix>
Weights and biases for the Output Gate.
getter/setter pair

Methods

build(Tensor input) → void
Initializes all parameter tensors for the four gates.
override
call(Tensor input) Tensor
The public, callable interface for the layer.
inherited
forward(Tensor input) Tensor<Vector>
Performs the forward pass for the LSTM layer.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited