Few-Shot Learning with Foundation Models

#few-shot learning #foundation models #meta-learning #prompt engineering #data augmentation #nlp #computer vision #machine learning #deep learning

1. Definition and Key Concepts

1.1 Definition and Key Concepts

Few-shot learning (FSL) refers to the ability of a machine learning model to generalize from a minimal number of labeled examples, typically ranging from one to a few dozen samples per class. Foundation models, such as large-scale pretrained transformers (e.g., GPT, CLIP, DALL-E), have revolutionized FSL by leveraging their broad pretraining on massive datasets to enable rapid adaptation to new tasks with limited supervision.

Core Principles of Few-Shot Learning

The effectiveness of few-shot learning with foundation models stems from three key principles:

$$ p(\theta|\mathcal{D}_{meta}) = \int p(\theta|\mathcal{D}_{task})p(\mathcal{D}_{task}|\mathcal{D}_{meta})d\mathcal{D}_{task} $$

where θ represents model parameters, 𝒟meta is the meta-training data, and 𝒟task are individual tasks.

Mathematical Formulation

Given a support set S = {(xi, yi)}i=1N with N examples (N typically ≤ 100) and a query x, few-shot learning aims to predict the corresponding y. The prediction can be framed as:

$$ p(y|x, S) = \int p(y|x, \theta)p(\theta|S)d\theta $$

where θ represents the model parameters. Foundation models approximate this through either:

Key Architectural Components

Modern few-shot learning systems with foundation models typically employ:

Performance Metrics

Few-shot learning performance is typically evaluated through:

$$ \text{Accuracy} = \frac{1}{N_{test}} \sum_{i=1}^{N_{test}} \mathbb{I}(\hat{y}_i = y_i) $$

where Ntest is the number of test examples and 𝕀 is the indicator function. More sophisticated evaluations may measure:

Practical Considerations

Effective deployment requires addressing several challenges:

Challenges in Traditional Machine Learning

Traditional machine learning models rely heavily on large-scale labeled datasets for training, a requirement that becomes problematic in scenarios where labeled data is scarce or expensive to acquire. The core assumption of independent and identically distributed (i.i.d.) data between training and test sets often fails in real-world applications, leading to poor generalization. Additionally, these models typically require task-specific architectures and extensive hyperparameter tuning, making them inflexible for rapid adaptation to new tasks.

Data Dependency and Generalization

Supervised learning frameworks optimize a loss function L(θ) over a dataset D = {(xi, yi)}i=1N, where θ represents model parameters. The empirical risk minimization (ERM) principle:

$$ \hat{\theta} = \argmin_{\theta} \frac{1}{N} \sum_{i=1}^{N} L(f_{\theta}(x_i), y_i) $$

fails when N is small, as the model overfits to the limited training samples. The generalization error ϵ can be quantified using the Rademacher complexity N(ℱ) of the hypothesis class :

$$ \epsilon \leq 2\mathfrak{R}_N(\mathcal{F}) + \sqrt{\frac{\log(1/\delta)}{2N}} $$

This bound becomes vacuous when N is small, exposing the fundamental limitation of data-hungry algorithms.

Task-Specific Architecture Limitations

Conventional pipelines require manual feature engineering and architecture design for each new task. For instance, a ResNet-50 model pretrained on ImageNet cannot directly process natural language inputs without structural modifications. The lack of cross-modal adaptability forces practitioners to:

Catastrophic Forgetting in Sequential Learning

When fine-tuned on new tasks, neural networks exhibit catastrophic forgetting—previously learned knowledge is overwritten by new training signals. The phenomenon stems from the plasticity-stability dilemma in gradient-based optimization. Consider a model with parameters θ initially trained on task A. Upon fine-tuning for task B, the parameter update:

$$ \theta_{t+1} = \theta_t - \eta \nabla_{\theta} L_B(\theta_t) $$

causes abrupt drift in directions critical for task A, as evidenced by the Fisher Information Matrix FA of the original task:

$$ \Delta \theta^T F_A \Delta \theta > \epsilon $$

where Δθ represents the parameter change during fine-tuning.

Computational and Environmental Costs

Training modern architectures like Vision Transformers (ViTs) from scratch requires massive computational resources. The energy consumption E for training a single model scales with:

$$ E \propto \text{FLOPs} \times \text{Training Steps} \times PUE $$

where PUE (Power Usage Effectiveness) accounts for data center overhead. For reference, training GPT-3 emitted approximately 552 metric tons of CO2 equivalent—highlighting the unsustainable nature of repeatedly training specialized models.

1.3 Role of Foundation Models

Foundation models, such as GPT-3, BERT, and CLIP, serve as the backbone for few-shot learning by leveraging their pre-trained knowledge from vast datasets. These models are trained on diverse tasks, enabling them to generalize across domains with minimal task-specific data. The key mechanism lies in their ability to encode rich, transferable representations that capture high-level semantic features, reducing the need for extensive fine-tuning.

Representation Learning and Transferability

The effectiveness of foundation models in few-shot learning stems from their hierarchical representation learning. During pre-training, these models develop multi-scale feature extractors, where lower layers capture generic patterns (e.g., edges in images or syntactic structures in text) and higher layers encode task-specific semantics. Mathematically, this can be expressed as a nested function composition:

$$ f(x) = f_L(f_{L-1}(\dots f_1(x))) $$

Here, each fi represents a layer transforming input x into progressively abstract representations. The pre-trained weights serve as an initialization point, allowing adaptation to new tasks with limited labeled examples via techniques like:

Scaling Laws and Emergent Abilities

Empirical studies reveal that foundation models exhibit emergent few-shot capabilities as their parameter count (N) and training data (D) scale. The performance P often follows a power-law relationship:

$$ P \propto N^\alpha D^\beta $$

where α and β are scaling exponents typically between 0.07–0.1. This scaling enables models to perform competitively with only k-shot examples, where k can be as low as 1–5 for well-structured tasks.

Case Study: CLIP for Visual Few-Shot Learning

Contrastive Language-Image Pre-training (CLIP) demonstrates how foundation models bridge modalities. By aligning image and text embeddings during pre-training, CLIP achieves few-shot classification by comparing test images to textual class descriptors (e.g., "a photo of a dog"). The similarity score S between an image embedding v and text embedding t is computed as:

$$ S(v, t) = \frac{v \cdot t}{\|v\| \|t\|} $$

This zero-shot transfer capability can be further refined with few-shot examples through linear probing on the frozen embeddings.

Role of Foundation Models – Few-Shot Learning with Foundation Models – Tutorial Diagram
Diagram Description: The diagram would show the hierarchical representation learning process in foundation models, illustrating how input data transforms through successive layers to produce abstract representations.

2. Meta-Learning Approaches

Meta-Learning Approaches

Meta-learning, or learning-to-learn, enables models to rapidly adapt to new tasks with minimal data by leveraging prior experience. In few-shot learning with foundation models, meta-learning approaches optimize for task-agnostic representations and adaptation strategies. Three dominant paradigms exist: metric-based, model-based, and optimization-based methods.

Metric-Based Meta-Learning

Metric-based approaches learn an embedding space where similarity metrics (e.g., Euclidean or cosine distance) determine classification. Prototypical Networks exemplify this by computing class prototypes as the mean embedding of support examples:

$$ \mathbf{c}_k = \frac{1}{|S_k|} \sum_{(\mathbf{x}_i, y_i) \in S_k} f_\theta(\mathbf{x}_i) $$

where \( S_k \) is the support set for class \( k \), and \( f_\theta \) is the embedding function. Query samples are classified via softmax over distances to prototypes:

$$ p_\theta(y = k | \mathbf{x}) = \frac{\exp(-d(f_\theta(\mathbf{x}), \mathbf{c}_k))}{\sum_{k'} \exp(-d(f_\theta(\mathbf{x}), \mathbf{c}_{k'}))} $$

Modern variants like Relation Networks replace fixed metrics with learnable comparators, while Matching Networks employ attention over the support set for adaptive embeddings.

Model-Based Meta-Learning

These methods use architectures with internal memory or fast parameter adaptation. Memory-Augmented Neural Networks (MANNs), such as Neural Turing Machines, store and retrieve task-specific information via attention mechanisms. For a support set \( S \), the read operation computes:

$$ \mathbf{r}_t = \sum_{i=1}^{|S|} w_t(i) \mathbf{M}_t(i) $$

where \( \mathbf{M}_t \) is the memory matrix at step \( t \), and weights \( w_t(i) \) attend to relevant memories. Meta Networks extend this with fast parameter generation via a meta-learner network.

Optimization-Based Meta-Learning

Optimization methods explicitly learn initialization parameters or update rules for rapid fine-tuning. Model-Agnostic Meta-Learning (MAML) finds initial parameters \( \theta \) that adapt efficiently to new tasks via few gradient steps:

$$ \theta' = \theta - \alpha abla_\theta \mathcal{L}_T(\theta) $$

The meta-objective minimizes loss across tasks after adaptation:

$$ \min_\theta \sum_{T \sim p(T)} \mathcal{L}_T(\theta') $$

First-order approximations (FOMAML) and Reptile simplify Hessian computations, while LEO introduces latent embeddings for parameter optimization. Recent work integrates these with transformer-based foundation models via adapter layers or prompt tuning.

Practical Considerations

Meta-Learning Approaches – Few-Shot Learning with Foundation Models – Tutorial Diagram
Diagram Description: The diagram would show the comparative architectures of metric-based, model-based, and optimization-based meta-learning methods, highlighting their distinct components and workflows.

Prompt Engineering for Few-Shot Tasks

Few-shot learning with foundation models relies heavily on the structure and content of the input prompt to guide the model's behavior. Unlike traditional supervised learning, where the model learns from a large labeled dataset, few-shot learning provides only a handful of examples within the prompt itself. The quality of these examples and their presentation significantly impacts model performance.

Key Components of Effective Few-Shot Prompts

An optimal few-shot prompt consists of three critical elements:

The prompt construction follows this general template:

Task: [description of task]
Input: [example input 1] → Output: [example output 1]
Input: [example input 2] → Output: [example output 2]
...
Input: [query input] → Output:

Mathematical Formulation of Prompt Effectiveness

The effectiveness of a prompt can be quantified by measuring the model's conditional probability of generating correct outputs given the prompt structure. For a prompt P containing k examples, the likelihood of correct prediction for query x is:

$$ P(y|x, P) = \prod_{t=1}^{T} P(y_t | y_{<t}, x, P) $$

where T is the length of the output sequence and y<t represents all tokens generated before step t. The prompt's quality directly influences this probability distribution.

Advanced Prompt Engineering Techniques

Example Selection Strategies

Not all examples equally improve model performance. Optimal example selection considers:

The similarity between examples ei and query x can be measured using embedding space distance:

$$ s(e_i, x) = 1 - \frac{d(\phi(e_i), \phi(x))}{\max_{j}d(\phi(e_j), \phi(x))} $$

where φ represents the model's embedding function and d is a distance metric (typically cosine distance).

Prompt Format Optimization

The surface form of the prompt significantly affects model performance. Key formatting considerations include:

Experimental results show that formatting improvements alone can yield accuracy gains of 5-15% on benchmark tasks.

Practical Considerations for Real-World Deployment

When implementing few-shot prompts in production systems, several practical factors must be addressed:

The optimal number of examples k follows a logarithmic relationship with model size:

$$ k_{opt} = \alpha \log_2(N) + \beta $$

where N is the model parameter count, and α, β are task-specific constants determined empirically.

2.3 Data Augmentation and Synthetic Examples

Few-shot learning scenarios often suffer from limited labeled data, making data augmentation and synthetic example generation critical for improving model generalization. Traditional augmentation techniques like rotation, flipping, and color jittering remain useful but are insufficient for complex domains. Instead, modern approaches leverage foundation models to generate semantically meaningful variations.

Foundation Model-Based Augmentation

Large language models (LLMs) and diffusion models can synthesize high-quality training examples conditioned on few-shot prompts. Given a seed example x and label y, a foundation model G generates new samples x' preserving the semantic content of y while introducing controlled variations. The generation process can be formalized as:

$$ x' = G(x, y, z), \quad z \sim \mathcal{N}(0, \sigma^2I) $$

where z represents latent noise controlling the variation strength. For vision tasks, diffusion models like Stable Diffusion can generate photorealistic images when provided with text prompts derived from the original labels. In NLP, LLMs can produce diverse paraphrases or style-transferred text while maintaining original semantics.

Controlled Semantic Perturbation

Effective augmentation requires maintaining label consistency while maximizing diversity. This is achieved through:

The perturbation bounds can be derived from the model's sensitivity analysis. For a classifier f with Lipschitz constant L, the maximum allowable perturbation ε that preserves the original prediction is:

$$ \epsilon < \frac{\min_{y' \neq y} (f_y(x) - f_{y'}(x))}{L} $$

Cross-Modal Augmentation

Multimodal foundation models enable knowledge transfer between modalities. For instance, CLIP can generate textual descriptions of visual concepts which are then used to create new training images. The alignment score between modalities provides a natural quality control metric:

$$ s(x,t) = \frac{\exp(\text{sim}(E_v(x), E_t(t))/ au)}{\sum_{t' \in T} \exp(\text{sim}(E_v(x), E_t(t'))/ au)} $$

where Ev and Et are vision and text encoders, and T is the set of possible textual descriptions.

Practical Considerations

When implementing these techniques:

Recent benchmarks show that properly implemented foundation model augmentation can improve few-shot accuracy by 15-30% across vision and language tasks, while reducing the required labeled examples by an order of magnitude.

Data Augmentation and Synthetic Examples – Few-Shot Learning with Foundation Models – Tutorial Diagram
Diagram Description: The diagram would show the process flow of foundation model-based augmentation, illustrating how seed examples are transformed into synthetic samples through latent space operations and attention-guided modifications.

3. Natural Language Processing Examples

3.1 Natural Language Processing Examples

Few-shot learning in natural language processing (NLP) leverages foundation models like GPT-3, T5, and BERT to generalize from minimal labeled examples. These models, pre-trained on vast corpora, exhibit remarkable meta-learning capabilities by conditioning on a small set of demonstrations (k-shot examples) before inferring on new tasks.

Prompt Engineering for Few-Shot NLP

The effectiveness of few-shot learning hinges on prompt design. Given a task like sentiment analysis, the model is conditioned with k labeled examples formatted as:

$$ \mathcal{D}_{\text{prompt}} = \{(x_1, y_1), (x_2, y_2), ..., (x_k, y_k)\} $$

where x represents input text and y the label. The model then predicts for a new input xtest via:

$$ P(y|x_{\text{test}}, \mathcal{D}_{\text{prompt}}) = \prod_{t=1}^{T} P(w_t | w_{<t}, x_{\text{test}}, \mathcal{D}_{\text{prompt}}) $$

Optimal performance requires:

Architectural Adaptations

While vanilla transformer models can perform few-shot learning, specialized architectures enhance sample efficiency:

Case Study: Few-Shot Named Entity Recognition

For entity recognition with limited labeled examples, a hybrid approach combines:

$$ \mathcal{L} = \mathcal{L}_{\text{LM}} + \lambda \mathcal{L}_{\text{span}}} $$

where LM is the standard language modeling loss and span optimizes for boundary detection. The model first processes demonstrations like:

[Text] "Apple unveiled the M2 chip at WWDC 2022"
[Labels] Apple:ORG, M2:PRODUCT, WWDC 2022:EVENT

then generalizes to unseen entities through attention mechanisms that focus on similar contextual patterns.

Calibration Techniques

Few-shot predictions often require calibration to address overconfidence:

$$ \hat{P}(y|x) = \frac{\exp(s(y|x)/T)}{\sum_{y'} \exp(s(y'|x)/T)} $$

where T is a learned temperature parameter that sharpens (T < 1) or smoothes (T > 1) the output distribution. Contextual calibration further adjusts scores by comparing to a null input baseline.

Cross-Lingual Transfer

Multilingual foundation models enable few-shot learning across languages by:

For low-resource languages, this approach achieves within 5% of fully supervised performance using just 32 examples per class.

3.2 Computer Vision Use Cases

Few-shot learning with foundation models has revolutionized computer vision by enabling rapid adaptation to new tasks with minimal labeled examples. Pre-trained models like CLIP, DALL·E, and Vision Transformers (ViTs) exhibit strong generalization capabilities, making them ideal for scenarios where labeled data is scarce.

Key Architectures and Methodologies

Contrastive Language-Image Pretraining (CLIP) aligns visual and textual embeddings in a shared latent space, allowing zero-shot transfer to downstream tasks. Given an image x and a text prompt t, CLIP computes their similarity using a cosine distance metric:

$$ \text{sim}(x, t) = \frac{f_\theta(x) \cdot g_\phi(t)}{||f_\theta(x)|| \cdot ||g_\phi(t)||} $$

where fθ and gφ are the image and text encoders, respectively. For few-shot adaptation, a linear probe is trained on top of frozen CLIP embeddings using limited labeled examples.

Practical Applications

Medical Imaging

In histopathology, foundation models pretrained on large-scale datasets like ImageNet can be fine-tuned with just 5–10 labeled examples per class to achieve competitive performance in tumor detection. Prototypical networks leverage class prototypes computed as the mean embedding of support examples:

$$ \mathbf{c}_k = \frac{1}{|S_k|} \sum_{(\mathbf{x}_i, y_i) \in S_k} f_\theta(\mathbf{x}_i) $$

where Sk is the support set for class k. Query samples are classified based on their Euclidean distance to these prototypes.

Industrial Quality Inspection

Meta-learning frameworks like Model-Agnostic Meta-Learning (MAML) enable rapid adaptation to new defect types in manufacturing. The outer-loop optimization objective is:

$$ \min_\theta \sum_{\mathcal{T}_i \sim p(\mathcal{T})} \mathcal{L}_{\mathcal{T}_i}(f_{\theta_i'}) $$

where θ′i = θ − α∇θ𝒯i(fθ) represents task-specific adaptation via gradient descent.

Advanced Techniques

Recent work in prompt tuning for vision transformers demonstrates that learned soft prompts can outperform linear probing in few-shot settings. Given a pretrained ViT, a set of continuous prompt vectors P ∈ ℝm×d is prepended to the input sequence:

$$ \mathbf{z}_0 = [\mathbf{p}_1, \mathbf{p}_2, ..., \mathbf{p}_m, \mathbf{x}\mathbf{E}] $$

where E is the patch embedding matrix. These prompts are optimized while keeping the base model frozen, achieving state-of-the-art results on benchmarks like Meta-Dataset.

Performance Considerations

When deploying few-shot vision models, the choice of backbone architecture significantly impacts performance. Empirical studies show that larger models (e.g., ViT-L/16) exhibit better transfer capabilities but require careful regularization to prevent overfitting on small support sets. Data augmentation techniques like RandAugment and MixUp are particularly effective in low-data regimes.

Computer Vision Use Cases – Few-Shot Learning with Foundation Models – Tutorial Diagram
Diagram Description: The diagram would show the alignment of visual and textual embeddings in CLIP's shared latent space, illustrating the cosine similarity calculation between image and text features.

3.3 Cross-Domain Adaptation

Cross-domain adaptation in few-shot learning addresses the challenge of transferring knowledge from a source domain, where abundant labeled data exists, to a target domain with limited labeled examples but potentially different data distributions. Foundation models, pretrained on large-scale datasets, provide a robust starting point for such adaptation due to their generalized feature representations.

Domain Shift and Feature Alignment

The core issue in cross-domain adaptation is domain shift, where the joint distribution of inputs and labels differs between source and target domains: PS(X,Y) ≠ PT(X,Y). To mitigate this, feature alignment techniques project both domains into a shared latent space where their distributions are similar. A common approach minimizes the Maximum Mean Discrepancy (MMD) between domains:

$$ \text{MMD}(P_S, P_T) = \left\| \frac{1}{n_S} \sum_{i=1}^{n_S} \phi(x_i^S) - \frac{1}{n_T} \sum_{j=1}^{n_T} \phi(x_j^T) \right\|_{\mathcal{H}} $$

where φ(·) is a feature mapping in reproducing kernel Hilbert space H, and nS, nT are sample sizes for source and target domains respectively. For foundation models, this often involves fine-tuning only the final layers while keeping early layers frozen to preserve general features.

Adversarial Domain Adaptation

Adversarial methods train a domain discriminator D to distinguish between source and target features, while the feature extractor G attempts to fool D. The minimax objective is:

$$ \min_G \max_D \mathbb{E}_{x\sim P_S}[\log D(G(x))] + \mathbb{E}_{x\sim P_T}[\log(1 - D(G(x)))] $$

Recent work combines this with foundation models by using the pretrained model as G and adding lightweight adaptation modules. For example, Domain-Specific Prompt Tuning (DSPT) learns domain-specific prompts while keeping the base model fixed, enabling efficient adaptation with few target examples.

Meta-Learning for Cross-Domain Adaptation

Model-Agnostic Meta-Learning (MAML) frameworks have been extended to cross-domain scenarios by simulating domain shifts during meta-training. The objective becomes:

$$ \min_\theta \sum_{\mathcal{T}_i \sim p(\mathcal{T})} \mathcal{L}_{\mathcal{T}_i}(U_\theta(\mathcal{D}_{\mathcal{T}_i}^{tr})) $$

where Uθ is the adaptation operator, and p(T) samples tasks from multiple source domains. When applied to foundation models, this approach meta-learns initialization parameters that facilitate rapid adaptation to novel domains with minimal target data.

Practical Considerations

In real-world applications, cross-domain adaptation enables foundation models to work in specialized areas like medical imaging with only a handful of annotated examples, by transferring knowledge from natural image datasets. The key is balancing adaptation to the target domain while preventing catastrophic forgetting of general knowledge encoded in the foundation model.

Cross-Domain Adaptation – Few-Shot Learning with Foundation Models – Tutorial Diagram
Diagram Description: The diagram would show the adversarial domain adaptation process with feature extractor and discriminator networks, illustrating the minimax objective flow.

4. Standard Few-Shot Learning Datasets

4.1 Standard Few-Shot Learning Datasets

Few-shot learning benchmarks are critical for evaluating the generalization capabilities of foundation models under limited supervision. These datasets are carefully designed to simulate real-world scenarios where labeled examples are scarce, enabling rigorous assessment of meta-learning, transfer learning, and prompt-based adaptation techniques.

Omniglot

Omniglot is a widely adopted benchmark for few-shot classification, consisting of 1,623 handwritten characters from 50 alphabets. Each character has 20 instances drawn by different individuals, making it ideal for testing model robustness to intra-class variation. The dataset is structured for N-way-K-shot evaluation, where models must classify novel characters using only K examples per class. Omniglot's hierarchical structure (alphabets → characters → instances) enables cross-alphabet generalization tests that probe compositional learning abilities.

$$ \text{Accuracy} = \frac{1}{N}\sum_{i=1}^{N} \mathbb{I}(\hat{y}_i = y_i) $$

Mini-ImageNet and Tiered-ImageNet

Mini-ImageNet contains 100 classes from ImageNet, with 600 images per class (84×84 pixels). Its split of 64/16/20 classes for train/validation/test ensures evaluation on truly novel categories. Tiered-ImageNet improves upon this with 608 classes grouped into 34 higher-level categories, enforcing stricter separation between training and testing superclasses to prevent information leakage. Both datasets challenge models to handle natural image complexity with minimal supervision.

Meta-Dataset

Meta-Dataset amalgamates 10 diverse image sources including ILSVRC-2012, Omniglot, Aircraft, and Quick Draw. With over 1.7 million images across 1,100 classes, it provides the most comprehensive few-shot benchmark. Key innovations include:

FewRel for Relation Extraction

FewRel adapts few-shot learning to NLP by providing 100 relations from Wikipedia with 700 instances each. The dataset evaluates a model's ability to recognize semantic relationships (e.g., capital of, employer) given just 5-10 annotated examples. Its sentence-level annotations require joint understanding of syntax and semantics, making it particularly challenging for foundation models.

Cross-Domain Considerations

Recent benchmarks like Meta-Album (60 image classification datasets across 10 domains) and VTAB+ (19 vision tasks) explicitly test cross-domain generalization. Performance metrics must account for:

$$ \Delta = \frac{1}{D}\sum_{d=1}^{D} \left( \text{Acc}_d - \text{Baseline}_d \right) $$

where D is the number of domains and Baselined is the performance of a naive prototypical network on domain d.

4.2 Metrics for Performance Assessment

Classification Metrics

In few-shot classification tasks, accuracy alone is insufficient due to small support sets. The N-way K-shot evaluation protocol demands metrics robust to class imbalance and stochasticity. Top-1 accuracy is commonly reported but should be accompanied by:

$$ \text{Balanced Accuracy} = \frac{1}{N}\sum_{i=1}^{N} \frac{\text{TP}_i}{\text{TP}_i + \text{FN}_i} $$

where TPi and FNi are true positives and false negatives for class i. For probabilistic models, the negative log-likelihood (NLL) captures calibration:

$$ \text{NLL} = -\frac{1}{M}\sum_{j=1}^{M} \log p(y_j^* | x_j^*, \mathcal{D}_{\text{support}}) $$

Regression and Structured Prediction

For continuous outputs, normalized mean squared error (NMSE) scales errors by dataset variance:

$$ \text{NMSE} = \frac{\mathbb{E}[(y - \hat{y})^2]}{\text{Var}(y)} $$

In few-shot object detection, mean Average Precision (mAP) is adapted by computing AP per novel class and averaging over shots. The intersection-over-union (IoU) threshold is typically relaxed to 0.5 for low-data regimes.

Cross-Domain Generalization

When evaluating foundation models across domains, H-score disentangles transferability from task-specific learning:

$$ \mathcal{H} = \text{tr}(\text{cov}(Y)^{-1}\text{cov}(\hat{Y})) $$

where cov(Y) and cov(Ŷ) are covariance matrices of true and predicted features. For language tasks, perplexity is normalized by out-of-domain baseline performance.

Bayesian Few-Shot Metrics

Probabilistic few-shot methods require metrics evaluating both prediction quality and uncertainty calibration. The expected calibration error (ECE) discretizes confidence bins:

$$ \text{ECE} = \sum_{m=1}^{M} \frac{|B_m|}{n} |\text{acc}(B_m) - \text{conf}(B_m)| $$

where Bm contains samples with predicted confidence in interval m. The Brier score combines calibration and refinement:

$$ \text{BS} = \frac{1}{N}\sum_{i=1}^{N} (f_i - o_i)^2 $$

with fi as predicted probability and oi as one-hot true label.

Meta-Learning Specific Metrics

For optimization-based meta-learners, task-averaged gradient alignment measures adaptation efficiency:

$$ \rho = \mathbb{E}_{\tau_i} \left[ \frac{\langle \nabla_{\theta}\mathcal{L}_{\tau_i}, \nabla_{\theta}\mathcal{L}_{\tau_j} \rangle}{\|\nabla_{\theta}\mathcal{L}_{\tau_i}\| \|\nabla_{\theta}\mathcal{L}_{\tau_j}\|} \right] $$

where τi, τj are sampled tasks. High ρ indicates reusable learning dynamics across tasks.

4.3 Comparing Foundation Models

Foundation models exhibit distinct architectural and performance characteristics that influence their suitability for few-shot learning tasks. Key differentiating factors include model scale, pretraining objectives, and adaptability mechanisms. The most prominent models—GPT-3, T5, and CLIP—leverage transformer architectures but optimize for different modalities and downstream applications.

Architectural and Pretraining Differences

GPT-3 employs a decoder-only transformer pretrained on autoregressive language modeling, enabling strong few-shot generalization through in-context learning. Its performance scales predictably with parameter count, following the power-law relationship:

$$ \mathcal{L}(N) = \alpha N^{-\beta} + \mathcal{L}_\infty $$

where N represents model parameters, α and β are scaling coefficients, and L denotes the irreducible loss floor. In contrast, T5 uses an encoder-decoder architecture with span corruption pretraining, achieving superior performance on structured prediction tasks but requiring more fine-tuning for optimal few-shot adaptation.

Modality-Specific Adaptations

CLIP introduces a dual-encoder design pretrained on 400 million image-text pairs, optimizing for cross-modal alignment through contrastive learning. Its few-shot capabilities emerge from the joint embedding space, where linear probes achieve 96.3% of fully supervised performance on ImageNet with just 8 examples per class. The alignment objective minimizes:

$$ \mathcal{L}_{\text{contrastive}} = -\mathbb{E}_{(x,y)\sim\mathcal{D}}\left[\log\frac{\exp(f(x)^T g(y)/\tau)}{\sum_{y'\in\mathcal{B}}\exp(f(x)^T g(y')/\tau)}\right] $$

where f and g are image and text encoders, τ is a temperature parameter, and B represents the batch of negative samples.

Computational Tradeoffs

Model selection depends critically on computational constraints and task requirements. GPT-3-175B achieves state-of-the-art few-shot performance but requires 3.14E23 FLOPs per forward pass. Smaller variants like T5-Base (220M parameters) offer viable alternatives when fine-tuning is permitted, with a 47× reduction in inference cost. The optimal choice follows a Pareto frontier balancing:

Empirical Performance Benchmarks

Standardized evaluation on the RAFT benchmark reveals stark differences in few-shot capabilities. GPT-3 achieves 72.3% accuracy on 16-shot classification versus T5's 68.1%, while CLIP attains 85.4% on vision tasks with equivalent supervision. These disparities stem from pretraining data diversity—CLIP's multimodal exposure yields better visual concept grounding, whereas GPT-3's broader textual corpus enhances linguistic versatility.

5. Key Research Papers

5.1 Key Research Papers

5.2 Open-Source Implementations

5.3 Recommended Courses and Books