MbPAAlgorithm<T, TInput, TOutput>

Models & Types · AiDotNet.MetaLearning.Algorithms

Memory-based Parameter Adaptation (MbPA): an episodic memory of (embedding, target) pairs whose nearest neighbours are used to locally, transiently re-fit the output network before each prediction.

Inheritance: ModelBase<T, TInput, TOutput> → MetaLearnerBase<T, TInput, TOutput> → MbPAAlgorithm<T, TInput, TOutput>

Implements: IGeneratedParameterRegistrar<T>

For Beginners

Imagine a doctor who has read every textbook but is now seeing a rare condition. Rather than re-reading the textbooks, they pull the few most similar cases from their notes, think about those for a moment, make the call, and then go back to being their normal self. The notes are the episodic memory; the moment of thinking is the local adaptation; going back to normal is what stops one rare case from distorting everything else they know.

How It Works

Sprechmann, Jayakumar, Rae, Pritzel, Puigdomènech Badia, Uria, Vinyals, Hassabis, Pascanu and Blundell, “Memory-based Parameter Adaptation” (ICLR 2018, arXiv:1802.10542). The problem it addresses: “Neural networks very gradually incorporate information into weights as they process data, requiring very low learning rates. If the training distribution shifts, the network is slow to adapt, and when it does adapt, it typically performs badly on the training distribution before the shift.”

The remedy is to stop trying to fix that with the weights at all. The network keeps an episodic memory and, at prediction time, uses a context-based lookup to modify its weights DIRECTLY, for that one prediction:

Three properties do the work, and all three are implemented rather than described.

MbPA is not a bi-level meta-learner. Unlike MAML and its relatives there is no inner/outer loop and no meta-gradient: MetaTrain is ordinary parametric training that also writes observed examples into memory. What makes MbPA a meta-algorithm lives entirely in Adapt, and specifically in the model it returns, which re-adapts per input.

Structure. Following this library’s ANIL convention, the configured meta-model is the embedding network f_gamma and the algorithm owns the output network g_theta as an explicit linear head. That is exactly the split MbPA requires.

Constructors

Constructor Summary
MbPAAlgorithm(MbPAOptions<T, TInput, TOutput> options) Initializes MbPA over an embedding network.

Properties

Property Summary
MetaLearningAlgorithmType AlgorithmType { get; }
Vector<T> OutputParameters { get; } Gets the trained output-network parameters, before any local adaptation.
int MemoryCount { get; } Gets the number of (embedding, target) pairs currently held in memory.

Methods

Method Summary
IModel<TInput, TOutput, ModelMetadata<T>> Adapt(IMetaLearningTask<T, TInput, TOutput> task)
T MetaTrain(TaskBatch<T, TInput, TOutput> taskBatch)
void ClearMemory() Clears the episodic memory.
void WriteToMemory(TInput inputs, TOutput targets) Embeds each example of a batch and stores (h_i, v_i).