LSTMNeuralNetwork<T>
Models & Types · AiDotNet.NeuralNetworks
Represents a Long Short-Term Memory (LSTM) Neural Network, which is specialized for processing sequential data like text, time series, or audio.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → SequenceModelLayoutBase<T> → LSTMNeuralNetwork<T>
For Beginners
An LSTM Neural Network is a special type of neural network designed for understanding sequences and patterns that unfold over time.
Think of an LSTM like a smart notepad that can:
- Remember important information for long periods
- Forget irrelevant details
- Update its notes with new information
- Decide what parts of its memory to use for making predictions
For example, when processing a sentence like “The clouds are in the sky”, an LSTM can:
- Remember “The clouds” as the subject even after seeing several more words
- Understand that “are” should agree with the plural “clouds”
- Predict that “sky” might come after “in the” because clouds are typically in the sky
LSTMs are particularly good at:
- Text generation and language modeling
- Speech recognition
- Time series prediction (like stock prices or weather)
- Translation between languages
- Any task where the order of data matters and patterns may span across long sequences
How It Works
Long Short-Term Memory networks are a special kind of recurrent neural network designed to overcome the vanishing gradient problem that traditional RNNs face. LSTMs have a complex internal structure with specialized “gates” that regulate the flow of information, allowing them to remember patterns over long sequences and selectively forget irrelevant information.
Example
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 LSTMNeuralNetwork<float>())
.Build(trainX, trainY);
var output = result.Predict(input);
Constructors
| Constructor | Summary |
|---|---|
LSTMNeuralNetwork() |
Creates a new LSTM Neural Network with customizable loss and activation functions, using scalar activation functions. |
LSTMNeuralNetwork(NeuralNetworkArchitecture<T> architecture, ILossFunction<T> lossFunction, IActivationFunction<T> outputActivation, IActivationFunction<T> forgetGateActivation, IActivationFunction<T> inputGateActivation, IActivationFunction<T> cellGateActivation, IActivationFunction<T> outputGateActivation, LSTMOptions options) |
Creates a new LSTM Neural Network with customizable loss and activation functions, using vector activation functions. |
LSTMNeuralNetwork(NeuralNetworkArchitecture<T> architecture, ILossFunction<T> lossFunction, IVectorActivationFunction<T> outputVectorActivation, IVectorActivationFunction<T> forgetGateVectorActivation, IVectorActivationFunction<T> inputGateVectorActivation, IVectorActivationFunction<T> cellGateVectorActivation, IVectorActivationFunction<T> outputGateVectorActivation, LSTMOptions options) |
Creates a new LSTM Neural Network with customizable loss and activation functions, using vector activation functions. |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the LSTM model. |