RecurrentLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Represents a recurrent neural network layer that processes sequential data by maintaining a hidden state.
Inheritance: LayerBase<T> → RecurrentLayer<T>
Implements: IShapeContract
For Beginners
This layer is designed to work with data that comes in sequences.
Think of the RecurrentLayer as having a memory that helps it understand sequences:
- When reading a sentence word by word, it remembers previous words to understand context
- When analyzing time series data, it remembers past values to predict future trends
- When processing video frames, it remembers earlier frames to track movement
Unlike regular layers that process each input independently, this layer:
- Takes both the current input and its own memory (hidden state) to make decisions
- Updates its memory after seeing each item in the sequence
- Passes this updated memory forward to the next time step
For example, when processing the sentence “The cat sat on the mat”:
- At the word “cat”, it remembers “The” came before
- At the word “sat”, it remembers both “The” and “cat” came before
- This context helps it understand the full meaning of the sentence
This ability to maintain information across a sequence makes recurrent layers powerful for tasks involving text, time series, audio, and other sequential data.
How It Works
The RecurrentLayer implements a basic recurrent neural network (RNN) that processes sequence data by maintaining and updating a hidden state over time steps. For each element in the sequence, the layer computes a new hidden state based on the current input and the previous hidden state. This allows the network to capture temporal dependencies and patterns in sequential data.
Constructors
| Constructor | Summary |
|---|---|
RecurrentLayer(int hiddenSize, IActivationFunction<T> activationFunction) |
Lazy ctor with vector activation. |
RecurrentLayer(int hiddenSize, IVectorActivationFunction<T> vectorActivationFunction) |
Lazy ctor with vector activation. |
Properties
| Property | Summary |
|---|---|
bool SupportsGpuTraining { get; } |
Gets a value indicating whether this layer supports GPU-resident training. |
bool SupportsTraining { get; } |
The computation engine (CPU or GPU) for vectorized operations. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetParameterRoles() |
Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases). |
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
IReadOnlyList<ValueTuple<string, Tensor<T>>> GetRegisteredBuffers() |
|
void ClearGradients() |
Resets the internal state of the recurrent layer. |
void ResetState() |
|
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void UpdateParameters(T learningRate) |
Updates the parameters of the recurrent layer using the calculated gradients. |
void UpdateParametersGpu(IGpuOptimizerConfig config) |
Updates parameters on GPU using the configured optimizer. |
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |