MetaLearningTask<T, TInput, TOutput>

Models & Types · AiDotNet.Data.Structures

Represents a single meta-learning task for few-shot learning, containing support and query sets.

Implements: IMetaLearningTask<T, TInput, TOutput>

For Beginners

Meta-learning is about “learning to learn” - training a model to quickly adapt to new tasks with only a few examples. Think of it like learning a language:

  • Traditional learning: Learn one specific language from thousands of examples
  • Meta-learning: Learn the general skill of language acquisition so you can learn new languages faster

A MetaLearningTask represents one mini-problem in this process:

  • Support Set: A few labeled examples the model can study (like a mini training set)
  • Query Set: Examples to test how well the model adapted (like a mini test set)

For example, in 5-way 3-shot classification:

  • The support set has 5 classes with 3 examples each (15 total examples)
  • The query set has examples from those same 5 classes to test performance

The model learns from many such tasks, developing the ability to quickly adapt to new tasks.

How It Works

In meta-learning, particularly few-shot learning, a task is a small classification or regression problem sampled from a larger dataset. Each task contains a support set (for adapting/learning) and a query set (for evaluating the adaptation).

Thread Safety: This class is not thread-safe. Create separate instances for concurrent access.

Performance: This is a lightweight container class with O(1) property access. Memory usage depends on the size of the tensors stored.

Example

// Create a 5-way 3-shot task
// Support set: 5 classes × 3 shots = 15 examples
// Query set: 5 classes × 10 queries = 50 examples
            
var supportX = new Matrix<double>(15, 784);  // 15 images, 784 pixels each
var supportY = new Vector<double>(15);       // one label per support example
var queryX = new Matrix<double>(50, 784);    // 50 query images
var queryY = new Vector<double>(50);         // one label per query example
            
var task = new MetaLearningTask<double, Matrix<double>, Vector<double>>
{
    SupportSetX = supportX,
    SupportSetY = supportY,
    QuerySetX = queryX,
    QuerySetY = queryY
};
            
// Hand the task to MAML, Reptile or SEAL: each adapts on the support set and is scored on the
// query set, which is what makes the split meaningful.

Constructors

Constructor Summary
MetaLearningTask()

Properties

Property Summary
Dictionary<string, object> Metadata { get; set; } Gets or sets the additional metadata about the task.
TInput QueryInput { get; } Gets the input features for the query set (alias for QuerySetX).
TInput QuerySetX { get; set; } Gets or sets the input features for the query set.
TInput SupportInput { get; } Gets the input features for the support set (alias for SupportSetX).
TInput SupportSetX { get; set; } Gets or sets the input features for the support set.
TOutput QueryOutput { get; } Gets the target labels for the query set (alias for QuerySetY).
TOutput QuerySetY { get; set; } Gets or sets the target labels for the query set.
TOutput SupportOutput { get; } Gets the target labels for the support set (alias for SupportSetY).
TOutput SupportSetY { get; set; } Gets or sets the target labels for the support set.
int NumQueryPerClass { get; set; } Gets or sets the number of query examples per class.
int NumShots { get; set; } Gets or sets the number of shots (examples per class) in the support set.
int NumWays { get; set; } Gets or sets the number of ways (classes) in this task.
int? TaskId { get; set; } Gets or sets an optional task identifier.
string Name { get; set; } Gets or sets an optional name or identifier for the task.