RecurrentNeuralNetwork<T>
Models & Types · AiDotNet.NeuralNetworks
Represents a Recurrent Neural Network, which is a type of neural network designed to process sequential data by maintaining an internal state.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → SequenceModelLayoutBase<T> → RecurrentNeuralNetwork<T>
For Beginners
A Recurrent Neural Network is a type of neural network that has memory.
Think of it like reading a book:
- A standard neural network looks at each word in isolation
- An RNN remembers what it read earlier to understand the current word
For example, in the sentence “The clouds were dark, so I took my umbrella,” an RNN understands that “I took my umbrella” is related to “The clouds were dark” because it remembers the earlier part of the sentence.
This memory makes RNNs good at:
- Processing sequences like sentences, time series, or music
- Understanding context and relationships over time
- Predicting what comes next in a sequence
Common applications include text generation, translation, speech recognition, and stock price prediction - all tasks where what happened before affects how you interpret what’s happening now.
How It Works
A Recurrent Neural Network (RNN) is a class of neural networks that can process sequential data by maintaining an internal state (memory) that captures information about previous inputs. Unlike traditional feedforward neural networks, RNNs have connections that form directed cycles, allowing information to persist from one step to the next. This architectural feature makes RNNs particularly well-suited for tasks involving sequential data, such as time series prediction, natural language processing, and speech recognition.
Reference: Elman, J.L. (1990). “Finding structure in time.” Cognitive Science, 14(2), 179-211.
https://doi.org/10.1016/0364-0213(90)90002-E
Example
var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var input = Tensor<float>.CreateRandom(new[] { 1, 20, 10 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
.ConfigureModel(new RecurrentNeuralNetwork<float>(architecture))
.Build(trainX, trainY);
var output = result.Predict(input);
Constructors
| Constructor | Summary |
|---|---|
RecurrentNeuralNetwork() |
Initializes a new instance of the RecurrentNeuralNetwork class with the specified architecture. |
RecurrentNeuralNetwork(NeuralNetworkArchitecture<T> architecture, ILossFunction<T> lossFunction, RecurrentNeuralNetworkOptions options) |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |
Updates the parameters of all layers in the network based on computed gradients. |