Meta-learning is the process of learning how to learn. A meta-learning algorithm takes in a distribution of tasks, where each task is a learning problem, and it produces a quick learner—a learner that can generalize from a small number of examples. One well-studied meta-learning problem is few-shot classification, where each task is a classification problem where the learner only sees 1–5 input-output examples from each class, and then it must classify new inputs. Below, you can try out our interactive demo of 1-shot classification, which uses Reptile.
How Reptile works
Like MAML, Reptile seeks an initialization for the parameters of a neural network, such that the network can be fine-tuned using a small amount of data from a new task. But while MAML unrolls and differentiates through the computation graph of the gradient descent algorithm, Reptile simply performs stochastic gradient descent (SGD) on each task in a standard way—it does not unroll a computation graph or calculate any second derivatives. This makes Reptile take less computation and memory than MAML. The pseudocode is as follows:
Initialize , the initial parameter vector for iteration do Randomly sample a task $T$ Perform steps of SGD on task $T$, starting with parameters , resulting in parameters Update: end for Return
As an alternative to the last step, we can treat as a gradient and plug it into a more sophisticated optimizer like Adam.
It is at first surprising that this method works at all. If , this algorithm would correspond to “joint training”—performing SGD on the mixture of all tasks. While joint training can learn a useful initialization in some cases, it learns very little when zero-shot learning is not possible (e.g. when the output labels are randomly permuted). Reptile requires Error in LaTeX ' k>1 ': KaTeX parse error: Expected 'EOF', got '&' at position 3: k&̲gt;1 , where the update depends on the higher-order derivatives of the loss function; as we show in the paper, this behaves very differently from (joint training).
To analyze why Reptile works, we approximate the update using a Taylor series. We show that the Reptile update maximizes the inner product between gradients of different minibatches from the same task, corresponding to improved generalization. This finding may have implications outside of the meta-learning setting for explaining the generalization properties of SGD. Our analysis suggests that Reptile and MAML perform a very similar update, including the same two terms with different weights.
In our experiments, we show that Reptile and MAML yield similar performance on the Omniglot and Mini-ImageNet benchmarks for few-shot classification. Reptile also converges to the solution faster, since the update has lower variance.
Our analysis of Reptile suggests a plethora of different algorithms that we can obtain using different combinations of the SGD gradients. In the figure below, assume that we perform k steps of SGD on each task using different minibatches, yielding gradients . The figure below shows the learning curves on Omniglot obtained by using each sum as the meta-gradient. corresponds to first-order MAML, an algorithm proposed in the original MAML paper. Including more gradients yields faster learning, due to variance reduction. Note that simply using (which corresponds to ) yields no progress as predicted for this task since zero-shot performance cannot be improved.
Finally, here’s a minimal example of few-shot regression, predicting a random sine wave from 10 pairs. This one uses PyTorch and fits in a gist:
Several people have pointed out to us that first-order MAML and Reptile are more closely related than MAML and Reptile. These algorithms take different perspectives on the problem, but end up computing similar updates—and specifically, Reptile’s contribution builds on the history of both Shortest Descent and avoiding second derivatives in meta-learning. We’ve since updated the first paragraph to reflect this.