Gradient Agreement as an Optimization Objective for Meta-Learning

This paper presents a novel optimization method for maximizing generalization over tasks in meta-learning. The goal of meta-learning is to learn a model for an agent adapting rapidly when presented with previously unseen tasks. Tasks are sampled from a specific distribution which is assumed to be similar for both seen and unseen tasks. We focus on a family of meta-learning methods learning initial parameters of a base model which can be fine-tuned quickly on a new task, by few gradient steps (MAML). Our approach is based on pushing the parameters of the model to a direction in which tasks have more agreement upon. If the gradients of a task agree with the parameters update vector, then their inner product will be a large positive value. As a result, given a batch of tasks to be optimized for, we associate a positive (negative) weight to the loss function of a task, if the inner product between its gradients and the average of the gradients of all tasks in the batch is a positive (negative) value. Therefore, the degree of the contribution of a task to the parameter updates is controlled by introducing a set of weights on the loss function of the tasks. Our method can be easily integrated with the current meta-learning algorithms for neural networks. Our experiments demonstrate that it yields models with better generalization compared to MAML and Reptile.


page 1

page 2

page 3

page 4


Towards Understanding Generalization in Gradient-Based Meta-Learning

In this work we study generalization of neural networks in gradient-base...

Reptile: a Scalable Metalearning Algorithm

This paper considers metalearning problems, where there is a distributio...

Large-Scale Meta-Learning with Continual Trajectory Shifting

Meta-learning of shared initialization parameters has shown to be highly...

Meta Learning by the Baldwin Effect

The scope of the Baldwin effect was recently called into question by two...

Multi-Domain Learning by Meta-Learning: Taking Optimal Steps in Multi-Domain Loss Landscapes by Inner-Loop Learning

We consider a model-agnostic solution to the problem of Multi-Domain Lea...

Dynamic Kernel Selection for Improved Generalization and Memory Efficiency in Meta-learning

Gradient based meta-learning methods are prone to overfit on the meta-tr...

Model-Agnostic Learning to Meta-Learn

In this paper, we propose a learning algorithm that enables a model to q...

1 Introduction

Many successes of deep learning today rely on enormous amounts of labeled data, which is not practical for problems with small data, in which acquiring enough labeled data is expensive and laborious. Moreover, in many mission critical applications, such autonomous vehicles and drones, an agent needs to adapt rapidly to unseen environments. The ability to learn rapidly is a key characteristic of humans that distinguishes them from artificial agents. Humans leverage prior knowledge learned earlier when adapting to a changing task, an ability that can be explained as Bayesian inference (

Brenden M Lake and Tenenbaum (2015)). Pioneered by (Schmidhuber (1987)), meta-learning has emerged recently as a novel field of study for learning from small amounts of data. Meta-learning algorithms learn their base models by sampling many different smaller tasks from a large data source instead trying to emulate a computationally intractable Bayesian inference. As a result, one might expect that the meta-learned model is capable of generalizing well to new unseen tasks because of task-agnostic way of training.

In this paper, we focus on a family of meta-learning algorithms that aim to learn the initialization of a network, which is then fine-tuned at test time on the new task by few steps of gradient descent. The most prominent work in this family is MAML (Finn et al. (2017)). MAML directly optimizes the performance of the model with respect to the test time fine-tuning procedure leading to a better initialization point.

In the parallel or batched version of MAML style algorithms (e.g. Reptile (Nichol et al. (2018)), at each iteration we optimize on tasks. However, the contribution of each task to the model parameter updates is assumed to be the same, i.e., the update rule is merely the average of the tasks losses. As an example, suppose a scenario in which a batch of tasks is sampled and tasks have strong agreement on the gradient direction but one task has a large disagreeing gradient. In this case, the disagreeing task can adversely affect the next model parameter update.

The contribution of this paper is introducing an optimization objective, i.e., gradient agreement by which a model can generalize better across tasks. The proposed algorithm and its mathematical analysis are illustrated in Sections 2 and 3, respectively. In Section 4, we provide some empirical insights by evaluations on miniImageNet (Vinyals et al. (2016)) and Omniglot (Lake et al. (2011)) classification tasks, and a toy example regression task.

2 Gradient Agreement

In this work, we consider the optimization problem of MAML which is finding a good initial set of parameters, . The goal is that for a randomly sampled task with corresponding loss , the model converges to a low loss point after number of gradient steps. This objective can be presented as , where is a function performing gradient steps that updates by samples drawn from task . Minimizing this objective function, requires two steps in MAML style works: 1) Adapting to a new task in which the model parameters become by steps of gradient descent on task , referred to as inner-loop optimization, 2) Updating the model parameters by optimizing for the performance of with respect to across all sampled tasks performed as follows: , and referred to as outer-loop optimization.

1:Initialize model parameters,
2:for iteration = 1,2,... do
3:     Sample a batch of tasks p()
4:     for all  do
5:         Split the examples of the task into sub-batches
6:          = - for steps
7:          = -      
8:      for all i
9:      = - (MAML)
10:      = + ( - ) (Reptile)
Algorithm 1 Gradient Agreement Algorithm

The assumption in the prior arts (Finn et al. (2017); Nichol et al. (2018)) is that each task should contribute equally for the direction of the outer-loop optimization step. However, in our approach, we associate a weight to the loss of each task, and the meta-optimization rule will become: . Assuming that the gradient update vector for each task is presented by , we define as:


The proposed is proportional to the inner product of the gradient of a task and the average of the gradients of all tasks in a batch. Therefore, if the gradient of a task is aligned with the average of the gradients of all tasks, it contributes more than other tasks to the next parameter update. With this insight, the proposed optimization method, pushes the model parameters towards initial parameters that more tasks agree upon. The full procedure of the proposed optimization is illustrated in Algorithm 1.

3 Analysis

In this section, inspired by (Jenni and Favaro (2018)), we provide a mathematical analysis for the proposed method. Denoting a batch of sampled tasks as , the outer-loop update in batched version of MAML with current parameters will be:


Instead, in gradient agreement approach, we look for a linear combination of task losses that lead to a better approximation of the tasks errors. We use

per each task which is estimated at each iteration. Therefore, the goal is to find parameters

and coefficients so that the model performs well on the sampled batch of tasks. We thus aim to optimize the following objective function:


where, w is the vector of all weights, and , associated with each task, and is a regularization parameter for the distribution of weights. In this section we show that the introduced inner product metric in 1 is corresponding to minimizing the objective function of Equation 3. Note that the solution of Equation 3 does not change if we multiply all the weights, , by the same positive constant. As a result, we normalize the magnitude of w to one. A typical method to solve the above optimization is the so-called implicit differentiation (Domke (2012)) method to solve a linear system in the second order derivatives of loss functions, which leads to solving a very high-dimensional linear system. To avoid computational complexities of the aforementioned method, we apply proximal approximation using Taylor series.

The loss function of -th task at can be approximated using Taylor series as:


where is the update vector obtained in the inner-loop optimization for -th task. By plugging in the first order approximation of (5) to (3) and (4), we obtain the following objective function:


The closed-form solution to the quadratic problem in (7) is a classical SGD update rule of:


Now, we plug in the solution in (8) to (6):


We compute the derivative of (9) with respect to for all and set it to zero, temporarily ignoring the normalization constraint on w:


Therefore, will be:


Now, by applying the constraint on the norm of w, we obtain as:


As a result, will be:


4 Experiments and Results

4.1 One-Dimensional Sine Wave Regression

As a simple case study, consider the 1D sine wave regression problem. A task is defined by the amplitude and phase of a sine wave function , and are sampled from and , respectively. The average of loss over 1000 unseen sine wave tasks is 0.13 and 0.08 for Reptile and gradient agreement method, respectively.

Figure 1: Demonstration of Reptile and our method on a toy few-shot regression problem, where we train on 10 sampled points of a sine wave, performing 5 gradient steps on a MLP with layers 1 64 64 1. left: before training, middle: after Reptile training, right: after gradient agreement based training.

4.2 Few-shot Classification

We evaluate our method on two popular few-shot classification tasks, miniImageNet (Vinyals et al. (2016)) and Omniglot (Lake et al. (2011)). The Omniglot dataset consists of 20 instances of 1623 characters from 50 different alphabets. The miniImagenet dataset includes 64 training classes, 12 validation classes, and 24 test classes, each class contains 600 examples. The problem of N-way classification is set up as follows: we sample N classes from the total C classes in the dataset and then selecting K examples for each class. For our experiments, we use the same CNN architectures and data pre-processing as (Finn et al. (2017)) and (Nichol et al. (2018)). The results for miniImageNet and Omniglot are presented in Tables 1 and  2, respectively. The models learned by our approach compares well to the state-of-the-art results on these two tasks. It substantially outperforms the prior methods on the challenging task of miniImageNet.

Algorithm 5way 1shot 5way 5shot
MAML (Finn et al. (2017)) 48.701.84% 63.110.92%
Reptile (Nichol et al. (2018)) 49.970.32% 65.990.58%
Gradient Agreement 54.801.19% 73.270.62%
Table 1: Accuracy results on miniImageNet.
Algorithm 5way 1shot 5way 5shot 20way 1shot 20way 5shot
MAML (Finn et al. (2017)) 98.70.4% 99.90.1% 95.80.3% 98.90.2%
Reptile (Nichol et al. (2018)) 97.680.04% 99.480.06% 89.430.14% 97.120.32%
Gradient Agreement 98.60.63% 99.80.12% 94.250.51% 98.991.34%
Table 2: Accuracy results on Omniglot.

5 Conclusion and Future Works

In this work, we presented a generalization method for meta-learning algorithms that adjusts the model parameters by introducing a set of weights over the loss functions of tasks in a batch in order to maximize the dot products between the gradients of different tasks. The higher the inner products between the gradients of different tasks, the more agreement they have upon the model parameters update. We also presented the objective function of this optimization method by a theoretical analysis using first order Taylor series approximation. This geometrical interpretation of optimization in meta-learning studies can be an interesting future direction.