CS58700 - Foundations of Deep Learning¶

Spring 2026¶

Instructor and Copyright: Bruno Ribeiro¶

Meta Learning: Learning to Learn (Part 2)¶

Defining a single negative log-likelihood objective over all tasks: $$\hat{\Gamma},\hat{g}^1,\ldots,\hat{g}^n = \arg\!\min_{\Gamma,g^1,\ldots,g^n} - \sum_{i=1}^m \sum_{k=1}^n \sum_{c_k \in C_k} (y^k_i)_{c_k} \log g^k(\Gamma(x_i))_{c_k}, $$ where $C_k$ is the set of classes in task $k = 1,\ldots,n$.

Example with 2 classes (img):

No description has been provided for this image
Figure 4

1. Meta-learning: Meta-learning invariances through gradient matching¶

If the inputs of the support sets $X^1,\ldots,X^n$ are not the same, we may allow different representations $\Gamma^k(X)$ for each of the $k$ tasks, with the following condition:

  • Let $k' \in \{1,\ldots,n\}$ be the task trained first.
  • Gradient matching for task $k \neq k'$ will force $\frac{\partial}{\partial x} \Gamma^k(x) = \frac{\partial}{\partial x} \Gamma^{k'}(x)$, $\forall x \in \text{supp}(X^{k'})$.
  • Goal: Lifelong learning. Learning to adapt to new tasks and observations without loosing sight of what was done in previous tasks.
    • Here, the tasks are given in sequence, hence, learning a common $\Gamma(\cdot)$ is not possible.
    • Transfer learning is also not ideal, since we want to adapt $\Gamma^k(\cdot)$ to the new task $k$.
      • Fine tuning $\Gamma(x)$ is not idea since it is unclear whether there is a good solution for the new task in the vicinity of the parameters of $\Gamma(\cdot)$.
      • A regularization procedure that pushes the new $\Gamma^k$ towards the representations of older tasks $\Gamma^{k'}$.
  • The above defines the invariance $\Gamma^k(x) = \Gamma^{k'}(x)+c$ inside the support $\forall x \in \text{supp}(X^k)$ of of task $k$, where $c$ is a constant that does not depend on $x$.
    • Outside the support $\text{supp}(X^k)$ of task $k$, the representation functions can be different, which can be an advantage in some tasks.
    • Another difference from traditional transfer learning (where $\Gamma^k = \Gamma^{k'}$) is that the invariance can only be enforced for the training data of task $k$, which means it is possible to have $\Gamma^k(x') \neq \Gamma^{k'}(x')+c$ for $x'$ outside the training data.
    • A further advantage is that the invariance is only suggested (via regularization) not strictly enforced, which gives further flexibility to practitioners to trade-off training loss and representation invariance.
  • For learning a function $g^n$, the training data is divided into two parts
    • For the inputs in $X^n$, we give the label $Y^n_i$ and the input $X^n_i$, for which we will define a negative log-likelihood loss, $i=1,\ldots,m^n$.
    • For the inputs in $X^k$, $k=1,\ldots,n-1$, we give $X^k_i$ and the derivative $\frac{\partial}{\partial x} \Gamma^k(x^k_i)$.
    • The goal of $\Gamma^n(x)$ is to match the derivative of $\Gamma^k(x^k_i)$ at $x^k_i$.
The above procedure, however, is hard to learn and requires continous inputs.
Common approaches use Tangent-prop like procedure: (Simard et al., 1998) as an approximation.

Learning a hypothesis space: A Bayesian procedure¶

Let's go back to our original invariant representation: A common hypothesis space $H$, such that $H = \{(g^1,g^2,\Gamma)\}$: $$f^1(x) = P(Y^1|X=x) = g^1(\Gamma(x)),$$ while $$f^2(x) = P(Y^2|X=x) = g^2(\Gamma(x)),$$ with $g^1$ and $g^2$ as reasonably simple functions.

  • Consider the dataset $X^k$ of task k.
  • Suppose we could learn the probability distribution $P(\Gamma | X^1,\ldots,X^n)$.
    • That would define a good hypothesis space for $F$. How can we implement it?
  • Start assuming we have $P(\Gamma | X^1)$
  • Note that when it comes to learning $\Gamma^2$ for task 2, we could simply optimize, using the prior $P(\Gamma | X^1)$ as regularization: $$ \Gamma^2_\text{opt}, g^2_\text{opt} = \arg\!\max_{\Gamma,g^2} \: \log \left( P(X^2 |g^2, \Gamma) P(\Gamma | X^1) \right). $$

Q: But why?

(Conditional) Bayes rule to obtain the posterior: $$ P(\Gamma, g^2 | X^2 , X^1) = \frac{P(X^2 |g^2, \Gamma) P(\Gamma | X^1) P(g^2 | X^1) }{P(X^2 | X^1)} $$

The MAP optimization is $$ \Gamma^2_\text{opt}, g^2_\text{opt} = \arg\!\max_{\Gamma, g^2} P(X^2 |g^2, \Gamma) P(\Gamma | X^1) P(g^2), $$ since

  1. The most likely posterior of $\Gamma$ and $g^2$ converges to the maximum likelihood estimate (as we have seen earlier in the course).
  2. We can assume $P(g^2 | X^1) = P(g^2)$

1.1. Meta-learning via Bayesian Posterior Sampling¶

  • Note that we could also perform Posterior Sampling via Bayesian Deep Learning.
  • Actually, what we will see is not quite correct but that is what the literature uses.
  • It works because it can be a reasonable approximation if $m=1$ (defined later).
  • The following procedure is one approach (Finn et al., ICML 2017) of many possible similar approaches.
    1. Consider a meta-learned representation $\Gamma_{t-1}$ at step $t-1$. We will also have link functions $g^1_{t-1},\ldots,g^n_{t-1}$ to predict the outputs of the $n$ tasks.
    1. Define $\Gamma_{0}^k = \Gamma_{t-1}$ and $h^k_{0} = g^k_{t-1}$ of task $k=1,\ldots,n$, such that the initialization of the lower layers is the same as the jointly learned $\Gamma_{t-1}$.
    1. In parallel for each task $k=1,\ldots,n$:
    • For r := 1 to $m$ gradient steps for each task:
      • Perform a few gradient steps by minimizing the loss of the forward pass of $h_r^k(\Gamma_{r}^k(x))$ over distinct mini-batches of the training data, $r=0,\ldots,m-1$
      • Output: $\Gamma_{m}^k$ and $h_{m}^k$, with $m$ typically small (e.g., $m=1$).
    1. Update $\Gamma_{t-1}$ and $g^1_{t-1},\ldots,g^n_{t-1}$ via a stochastic gradient descent update
    • With a different mini-batch than originally used to obtain $\Gamma_{m}^k$, ideally we will use a validation dataset for these updates $$ \Gamma_{t} = \Gamma_{t-1} - \beta \frac{\partial}{\partial \Gamma} \sum_{i \in \text{validation data}} \sum_k \mathcal{L}(y^k_i, g^k_{t-1}(\Gamma_{m}^k(x_i))), $$ where $\mathcal{L}$ is the Negative Log-Likelihood loss (NLLL) and $\beta$ is the learning rate
    • Definition of $\frac{\partial}{\partial \Gamma} \Gamma_{m}^k(x_i)$: Let ${\bf W}_\Gamma$ be the neural network parameters of $$\Gamma_{m}^k(x_i) = \text{NN}(x_i ; {\bf W}^{(m,k)}_\Gamma),$$ where NN is a neural network architecture, we define: $$ \frac{\partial}{\partial \Gamma} \Gamma_{m}^k(x_i) := \frac{\partial}{\partial {\bf W}_\Gamma} \text{NN}(x_i ; {\bf W}^{(m,k)}_\Gamma).$$
    1. Finally, we will update $g^k_{t-1}$ with a simple gradient update: $$ g^k_{t} = g^k_{t-1} - \beta \frac{\partial}{\partial g^k} \sum_i \sum_k \mathcal{L}(y^k_i, g^k_{t-1}(\Gamma_{m}^k(x_i))). $$

Understanding Bayesian Meta-Learning Derivatives¶

Note that we could approach the gradient update of $\Gamma_{t}$, $$ \frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_i, g^k_{t-1}(\Gamma_{m}^k(x_i))), $$ as:

  • A gradient update assuming $G^k_{m,i} = \Gamma_{m}^k(x_i)$ is a constant input that does not depend on $\Gamma$: $$ \sum_{k=1}^n \sum_{i \in \text{validation data}} \frac{\partial}{\partial g^k} \mathcal{L}(y^k_i, g^k_{t-1}(G^k_{m,i})) , $$
  • A gradient update where $G^k_{m,i} = \Gamma_{m}^k(x_i)$ is a learnable function but $g^k$ is a fixed function gives: $$ \sum_{k=1}^n \sum_{i \in \text{validation data}} \frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_i, g^k_{t-1}(\Gamma_{m}^k(x_i))) = \sum_{k=1}^n \sum_{i \in \text{validation data}} \frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_i, g^k_{t-1}(G^k_{m,i})) \frac{\partial}{\partial \Gamma} \Gamma_{m}^k(x_i). $$
The Meta-Learning Derivatives: Understanding the gradient:¶

Let $\alpha^k$ be the learning rate of task $k = 1,\ldots,n$.

The $m$ gradient updates to task $k$ at step $t$ are:

  • $\Gamma_{0}^k = \Gamma_{t-1}$
  • $\Gamma_{1}^k = \Gamma_{0}^{k} - \alpha^k \sum_{j \in \text{train data}} \frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_j, h^k_{0}(\Gamma_{0}^k(x_j)))$
  • $\ldots$
  • $\Gamma_{m}^k = \Gamma_{m-1}^{k} - \alpha^k \sum_{j \in \text{train data}} \frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_j, h^k_{m-1}(\Gamma_{m-1}^k(x_j)))$

And then the meta-learning gradient of $\Gamma_{t-1}$ is $$\sum_{k=1}^n \sum_{i \in \text{val. data}} \frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_i, g^k_{t-1}(\Gamma_{m}^k(x_i)))$$

Composing all the derivatives via chain rule gives us the meta-learning gradient: $$ \sum_{k=1}^n \sum_{i \in \text{validation data}} \frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_i, g^k_{t-1}(\Gamma_{m}^k(x_i))) $$ $$= \sum_{k=1}^n \left( \sum_{i\in \text{validation data}} \mathcal{L}(y^k_i, g^k_{t-1}(G^k_{m,i}))\right) \\ \times \left(\sum_{j \in \text{train data}} \prod_{r=1}^m \left(I - \alpha^k \frac{\partial}{\partial \Gamma}\left(\frac{\partial}{\partial \Gamma} \mathcal{L}(y^k_j, h^k_{0}(G^{\prime k}_{r,j}))\right) \right) \right), $$ where $G^k_{m,i} = \Gamma_{m}^k(x_i)$ and $G^{\prime k}_{r,j} = \Gamma_{r}^k(x_j)$ are constants that do not depend on $\Gamma$.

1.2. Some Meta-learning Matching Methods¶

Classical Metric-Based Methods¶

  • At its core, the idea behind metric-based meta-learning is akin to $k$-nearest neighbors algorithms and kernel density estimators.
  • The assumption is that the set of labels is the same over all tasks, but the input sizes are different in the different tasks.
  • The idea is to learn $\Gamma^k$ for each task, but then also learn how to combine them into a single representation $\Gamma$.
  • The prediction can be seen as learning a distance metric $\mathcal{K}$ that can predict: $$ P(Y=y|x) \propto \sum_{k=1}^n \sum_{(x^k_i,y^k_i) \in X^k} \mathcal{K}(x,x^k_i) {\bf 1}(y^k_i = y) $$
  • Siamese networks (Koch, Zemel & Salakhutdinov, 2015) (and related methods (Sung et al., 2018)): Two twin networks with outputs that are jointly trained and combined by a function $\mathcal{K}$.
    • $\mathcal{K}$ is assumed to be the L1 norm, and the resulting distance is converted into a probability by a MLP.
  • Matching networks (Vinyals et al., 2016): Defined $\mathcal{K}$ to be $$ \mathcal{K}(x,x_i)=\frac{\exp(\cos(\Gamma(x),\Gamma'(x_i))}{\sum_{\forall j} \exp(\cos(\Gamma(x),\Gamma'(x_j)))}. $$
  • Prototypical Networks (Snell, Swersky & Zemel, 2017): Uses a representation $\Gamma^k$ for each task. A prototype feature vector ${\bf v}_c$ of class $c\in C$, is the average embedding of the support data samples in class $c$. Then, $\mathcal{K}(x,v_c)$ of class $c$ is defined as a distance between the input $x$ and $v_c$, $\forall c \in C$.
  • Other Gradient-based methods:
    • LSTM Meta-Learner (Ravi & Larochelle, 2017): The goal of the meta-learner is to receive the gradients of the different $\Gamma^k$'s and learn to combine them inot a single update rule for $\Gamma$, using a small support set so that the learner can adapt to the new task quickly.
  • Architecture-based methods
    • Fast Weights (Munkhdalai & Yu, 2017): A model has a set of fast and slow weights, and a set of task-dependent ($\Gamma^k$) and meta ($\Gamma$) models.
    • Memory-Augmented Neural Networks (Santoro et al. (2016)): Part of a family of architectures that use external memory to facilitate the learning process of neural networks.

1.3 Optimization-Based Meta-Learning¶

Optimization-based approaches learn model parameters that can quickly adapt to new tasks with minimal updates. These techniques include:

MAML (Model-Agnostic Meta-Learning)¶

  • Reference: (Finn et al., 2017)
  • Optimizes model parameters for fast adaptation: $$ \min_{\theta} \sum_{i=1}^{N} \mathcal{L}_i(\theta - \alpha \nabla_{\theta} \sum_{j=1}^{N} \mathcal{L}_j(D_j, \theta), D_i) $$

Reptile¶

  • Reference: (Nichol et al., 2018)
  • A first-order approximation of MAML that avoids second derivatives: $$ \theta \leftarrow \theta + \alpha(W - \theta) $$ where $W = \frac{\lambda_j}{N} \sum_{j=0}^{N-1} \nabla_{\theta}l_j(B_j, \theta)$

Conclusions¶

  • Meta-learning is a fundamental concept in representation learning

  • In many ways, we identify some level of intelligence with meta-learning

    • Can a representation learn to distinguish object by their fundamental defining characteristics?
    • Current neural network architectures are not designed for meta-learning
      • A more fundamental view on meta-learning is still missing
In [ ]: