GRUNeuralNetwork<T>

Models & Types · AiDotNet.NeuralNetworks

Represents a Gated Recurrent Unit (GRU) Neural Network for processing sequential data.

Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → SequenceModelLayoutBase<T> → GRUNeuralNetwork<T>

For Beginners

A GRU Neural Network is a special type of neural network that’s good at processing data that comes in sequences.

Think of it like reading a book:

  • A regular neural network would look at each word in isolation
  • A GRU network remembers what it read earlier and uses that context to understand each new word

GRU networks have special “gates” that control what information to remember and what to forget:

  • This helps them understand patterns that stretch over long sequences
  • For example, in a sentence like “John went to the store because he needed milk,” a GRU can connect “he” with “John”

GRU networks are useful for:

  • Text processing and generation
  • Time series prediction (like stock prices or weather)
  • Speech recognition
  • Any task where the order and context of data matters

How It Works

A GRU Neural Network is a type of recurrent neural network designed to effectively model sequential data. GRU networks use gating mechanisms to control information flow through the network, allowing them to capture long-term dependencies in sequence data while avoiding the vanishing gradient problem that affects simple recurrent networks.

Reference: Cho et al., “Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation” (EMNLP 2014). https://arxiv.org/abs/1406.1078

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 GRUNeuralNetwork<float>())
    .Build(trainX, trainY);
var output = result.Predict(input);

Constructors

Constructor Summary
GRUNeuralNetwork() Initializes a new instance of the GRUNeuralNetwork class with the specified architecture.
GRUNeuralNetwork(NeuralNetworkArchitecture<T> architecture, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, GRUOptions options)

Properties

Property Summary
bool SupportsTraining { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata() Gets metadata about this GRU Neural Network model.
Tensor<T> ForwardWithMemory(Tensor<T> input) Performs a forward pass while storing intermediate values for backpropagation.