MbPAAdaptedModel<T, TInput, TOutput>
Models & Types · AiDotNet.MetaLearning.Algorithms
The model MbPA hands back from adaptation: it re-runs the local adaptation on EVERY prediction and discards the adapted parameters immediately afterwards.
Inheritance: ModelWrapperBase<T, TInput, TOutput> → MetaLearningModelBase<T, TInput, TOutput> → MbPAAdaptedModel<T, TInput, TOutput>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
Every time you ask this model a question it briefly looks up similar remembered cases, nudges its last layer to agree with them, answers, and then undoes the nudge. The next question starts from the same clean slate.
How It Works
This is where MbPA actually happens, and the per-prediction recomputation is not an implementation detail — it is the method. The adapted parameters theta_x are a function of the query’s own embedding, because that embedding is what selects the neighbours to fit. Computing them once at adaptation time and reusing them for every input would collapse MbPA into ordinary fine-tuning on the support set, which is the thing the paper is arguing against.
Equally load-bearing: nothing is retained. Sprechmann et al.: “These adapted parameters are used for output computation but discarded thereafter.” Retaining them across calls would accumulate drift and reintroduce exactly the catastrophic forgetting the memory exists to avoid.
Example
// Produced by MbPAAlgorithm.Adapt rather than constructed directly: the returned model
// carries the episodic memory and the locally adapted output head for one task.
var metaModel = new NeuralNetwork<double>(
new NeuralNetworkArchitecture<double>(inputFeatures: 8, outputSize: 4));
var options = new MbPAOptions<double, Tensor<double>, Tensor<double>>(metaModel);
var mbpa = new MbPAAlgorithm<double, Tensor<double>, Tensor<double>>(options);
var task = new MetaLearningTask<double, Tensor<double>, Tensor<double>>();
var taskBatch = new TaskBatch<double, Tensor<double>, Tensor<double>>(
new IMetaLearningTask<double, Tensor<double>, Tensor<double>>[] { task });
mbpa.MetaTrain(taskBatch);
var adapted = mbpa.Adapt(task); // an MbPAAdaptedModel
var prediction = adapted.Predict(task.QueryInput);
Constructors
| Constructor | Summary |
|---|---|
MbPAAdaptedModel(IFullModel<T, TInput, TOutput> embeddingNetwork, MbPAEpisodicMemory<T> memory, Vector<T> trainedOutputParams, MbPAOptions<T, TInput, TOutput> options, Vector<T> keyEmbeddingParameters) |
Initializes the adapting model. |
Properties
| Property | Summary |
|---|---|
int LocalAdaptationSteps { get; } |
Gets the number of local gradient steps taken per prediction (T). |
int MemoryCount { get; } |
Gets the number of (embedding, target) pairs available to retrieve from. |
Methods
| Method | Summary |
|---|---|
IFullModel<T, TInput, TOutput> WithParameters(Vector<T> parameters) |
|
TOutput Predict(TInput input) |