MemoryNetwork<T>
Models & Types · AiDotNet.NeuralNetworks
Represents a Memory Network, a neural network architecture designed with explicit memory components for improved reasoning and question answering capabilities.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → SequenceModelLayoutBase<T> → MemoryNetwork<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
A Memory Network is a special type of neural network that has its own “memory storage” component.
Think of it like a person who has:
- A notebook (the memory) where they can write down important facts
- The ability to read specific information from their notebook when needed
- The ability to add new information to their notebook as they learn
For example, if you provided a Memory Network with several facts about a topic:
- It would store these facts in its memory matrix
- When asked a question, it would search its memory for relevant information
- It would use this retrieved information to formulate an answer
Memory Networks are particularly good at:
- Question answering based on a given context
- Reasoning tasks that require remembering multiple facts
- Dialog systems that need to maintain conversation history
- Tasks where information needs to be remembered and used later
How It Works
Memory Networks combine neural network components with a long-term memory matrix that can be read from and written to. This architecture allows the network to store information persistently and access it selectively when needed, making it particularly effective for tasks requiring reasoning over facts or answering questions based on provided context.
Example
var input = Tensor<float>.CreateRandom(new[] { 1, 50 });
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 MemoryNetwork<float>())
.Build(trainX, trainY);
var output = result.Predict(input);
Constructors
| Constructor | Summary |
|---|---|
MemoryNetwork() |
Initializes a new instance of the MemoryNetwork class with the specified architecture and memory parameters. |
MemoryNetwork(NeuralNetworkArchitecture<T> architecture, int memorySize, int embeddingSize, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, MemoryNetworkOptions options) |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
Methods
| Method | Summary |
|---|---|
ModelInputShapeConstraint GetInputShapeConstraint() |
Generated from [ModelInputShapeConstraint]. |
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the memory network model. |
Tensor<T> AnswerQuestion(Tensor<T> question) |
Queries the memory network with a question and returns the answer. |
Tensor<T> ForwardForTraining(Tensor<T> input) |
|
void StoreFact(Tensor<T> fact) |
Serializes memory network-specific data to a binary writer. |