NeuralTuringMachine<T>
Models & Types · AiDotNet.NeuralNetworks
Represents a Neural Turing Machine, which is a neural network architecture that combines a neural network with external memory.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → SequenceModelLayoutBase<T> → NeuralTuringMachine<T>
Implements: IAuxiliaryLossLayer<T>, IGeneratedParameterRegistrar<T>
For Beginners
A Neural Turing Machine is like a neural network with a “notebook” that it can write to and read from.
Think of it like a student solving a math problem:
- The student (neural network) can process information directly
- But for complex problems, the student needs to write down intermediate steps in a notebook (external memory)
- The student can later refer back to these notes when needed
This memory capability helps the network:
- Remember information over long periods
- Store and retrieve specific pieces of data
- Learn more complex patterns that require step-by-step reasoning
For example, a standard neural network might struggle to add two long numbers, but an NTM can learn to write down partial results and carry digits, similar to how humans solve addition problems.
How It Works
A Neural Turing Machine (NTM) extends traditional neural networks by adding an external memory component that the network can read from and write to. This allows the network to store and retrieve information over long sequences, making it particularly effective for tasks requiring complex memory operations.
Example
var input = Tensor<float>.CreateRandom(new[] { 1, 10, 8 });
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 NeuralTuringMachine<float>())
.Build(trainX, trainY);
var output = result.Predict(input);
Constructors
| Constructor | Summary |
|---|---|
NeuralTuringMachine() |
Initializes a new instance of the NeuralTuringMachine class. |
NeuralTuringMachine(NeuralNetworkArchitecture<T> architecture, int memorySize, int memoryVectorSize, int controllerSize, ILossFunction<T> lossFunction, IActivationFunction<T> contentAddressingActivation, IActivationFunction<T> gateActivation, IActivationFunction<T> outputActivation, NeuralTuringMachineOptions options) |
Initializes a new instance of the NeuralTuringMachine class. |
NeuralTuringMachine(NeuralNetworkArchitecture<T> architecture, int memorySize, int memoryVectorSize, int controllerSize, ILossFunction<T> lossFunction, IVectorActivationFunction<T> contentAddressingActivation, IVectorActivationFunction<T> gateActivation, IVectorActivationFunction<T> outputActivation, NeuralTuringMachineOptions options) |
Initializes a new instance of the NeuralTuringMachine class. |
Properties
| Property | Summary |
|---|---|
IActivationFunction<T> ContentAddressingActivation { get; } |
The activation function to apply to content-based addressing similarity scores. |
IActivationFunction<T> GateActivation { get; } |
The activation function to apply to interpolation gates. |
IActivationFunction<T> OutputActivation { get; } |
The activation function to apply to the final output. |
IVectorActivationFunction<T> ContentAddressingVectorActivation { get; } |
The activation function to apply to content-based addressing similarity scores. |
IVectorActivationFunction<T> GateVectorActivation { get; } |
The activation function to apply to interpolation gates. |
IVectorActivationFunction<T> OutputVectorActivation { get; } |
The activation function to apply to the final output. |
T AuxiliaryLossWeight { get; set; } |
Gets or sets the weight for the memory usage auxiliary loss. |
bool UseAuxiliaryLoss { get; set; } |
Gets or sets whether auxiliary loss (memory usage regularization) should be used during training. |
double MaxGradNormValue { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetAuxiliaryLossDiagnostics() |
Gets diagnostic information about the memory usage auxiliary loss. |
Dictionary<string, string> GetDiagnostics() |
Gets diagnostic information about this component’s state and behavior. |
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the Neural Turing Machine model. |
T ComputeAuxiliaryLoss() |
Computes the auxiliary loss for memory usage regularization. |
Tensor<T> ForwardForTraining(Tensor<T> input) |
Forward path used by the training tape — routes directly through the NTM-specific tape-aware ForwardTape memory pipeline (controller → read/write addressing → output), the SAME function Predict evaluates. |
void ResetState() |
Serializes NTM-specific data to a binary writer. |
void SetTrainingMode(bool isTraining) |
Sets the layer to training or evaluation mode. |