Skip to content
PyTorch Meta-learning Framework for Researchers
Python Makefile
Branch: master
Clone or download
Latest commit b511af1 Aug 22, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets Clean up repo. Aug 13, 2019
examples Made changes to style of news_text_classification Aug 22, 2019
learn2learn Made changes to style of news_text_classification Aug 22, 2019
.gitignore added init file to text Aug 9, 2019
Makefile Clean up repo. Aug 13, 2019
README.md Fixes, cleanups, and API changes. Aug 16, 2019
setup.cfg Clean up repo. Aug 13, 2019
setup.py Fixes, cleanups, and API changes. Aug 16, 2019

README.md


learn2learn is a PyTorch library for meta-learning implementations. It was developed during the first PyTorch Hackathon. Edit: L2L was lucky to win the hackathon!

Note learn2learn is under active development and many things are breaking.

Installation

pip install learn2learn

API Demo

import learn2learn as l2l

mnist = torchvision.datasets.MNIST(root="/tmp/mnist", train=True)

task_generator = l2l.data.TaskGenerator(mnist, ways=3)
model = Net()
maml = l2l.MAML(model, lr=1e-3, first_order=False)
opt = optim.Adam(maml.parameters(), lr=4e-3)

for iteration in range(num_iterations):
    learner = maml.clone()  # Creates a clone of model
    task = task_generator.sample(shots=1)

    # Fast adapt
    for step in range(adaptation_steps):
        error = compute_loss(task)
        learner.adapt(error)

    # Compute validation loss
    valid_task = task_generator.sample(shots=1, classes_to_sample=task.sampled_classes)
    valid_error = compute_loss(valid_task)

    # Take the meta-learning step
    opt.zero_grad()
    valid_error.backward()
    opt.step()

Changelog

The following changelog is mostly for the hackathon period.

August 15, 2019

  • Algorithm cleanup.
  • Added BaseLearner with unified API.
  • Support for vectorized environments.

August 12, 2019

  • Basic implementation of MAML, FOMAML, Meta-SGD.
  • TaskGenerator code for classification tasks.
  • Environments for RL.
  • Small scale examples of MAML-A2C and MAML-PPO.

Acknowledgements

  1. The RL environments are copied from: https://github.com/tristandeleu/pytorch-maml-rl
You can’t perform that action at this time.