InContextLearning<T>

Models & Types · AiDotNet.NeuralNetworks.Tabular

Helper class for in-context learning in tabular foundation models like TabPFN.

For Beginners

Think of in-context learning like this:

  • Traditional ML: Train a model, then use it to predict
  • In-context learning: Give the model examples AND the test data together

The model “learns” from the examples in real-time through attention mechanisms.

How It Works

In-context learning allows models to learn from examples provided at inference time without updating model parameters. The model conditions on training examples to make predictions on new data.

Constructors

Constructor Summary
InContextLearning()

Properties

Property Summary
bool HasContext { get; } Gets whether context has been set.
int NumContextSamples { get; } Gets the number of samples in the current context.

Methods

Method Summary
Tensor<T> CreateInContextInput(Tensor<T> queryFeatures) Creates the combined input for in-context learning by concatenating context samples with query samples.
Tensor<T> ExtractQueryOutput(Tensor<T> combinedOutput, int outputDim) Extracts query predictions from combined output.
Tensor<T> GetContextLabels() Gets the context labels for use in attention mechanisms.
bool[] CreateContextMask(int querySize) Creates a mask indicating which positions are context vs query.
void ClearContext() Clears the current context.
void SetClassificationContext(Tensor<T> features, Vector<int> labels, int numClasses, int maxContextSamples) Sets the context for classification tasks with integer labels.
void SetContext(Tensor<T> features, Tensor<T> labels, int maxContextSamples) Sets the context (training) data for in-context learning.