GithubHelp home page GithubHelp logo

isabella232 / metalearn-leap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amzn/metalearn-leap

0.0 0.0 0.0 44 KB

Original PyTorch implementation of the Leap meta-learner (https://arxiv.org/abs/1812.01054) along with code for running the Omniglot experiment presented in the paper.

License: Apache License 2.0

Shell 2.27% Python 97.73%

metalearn-leap's Introduction

Transferring Knowledge across Learning Processes

[Blog post] [Paper]

Original PyTorch implementation of the Leap meta-learner (https://arxiv.org/abs/1812.01054) along with code for running the Omniglot experiment presented in the paper.

License

This library is licensed under the Apache 2.0 License.

Authors

Sebastian Flennerhag

Install

This repository was developed against PyTorch v0.4 on Ubuntu 16.04 using Python 3.6. To install Leap, clone the repo and install the source code:

git clone https://github.com/amazon/pytorch-leap
cd pytorch-leap/src/leap
pip install -e .

This installs the leap package and the Leap meta-learner class. The meta-learner can be used with any torch.nn.Module class as follows:

Require: criterion, model, tasks, opt_cls, meta_opt_cls, opt_kwargs, meta_opt_kwargs

leap = Leap(model)
mopt = meta_opt_cls(leap.parameters(), **meta_opt_kwargs)
for meta_steps:
    meta_batch = tasks.sample()
    for task in meta_batch:
        leap.init_task()
        leap.to(model)
        opt = opt_cls(model.parameters(), **opt_kwargs)

        for x, y in task:
            loss = criterion(model(x), y)
            loss.backward()

            leap.update(loss, model)

            opt.step()
            opt.zero_grad()  # MUST come after leap.update
    ###
    leap.normalize()
    meta_optimizer.step()
    meta_optimizer.zero_grad()

Omniglot

To run the Omniglot experiment, first prepare the dataset using the make_omniglot.sh script in the root directory. The p flag downloads the dataset, d installs dependencies and l creates log directories.

bash make_omniglot.sh -pdl

To train a meta-learner, use the main.py script. To replicate experiments in the paper select a meta learner and number of pretraining tasks. For instance, to train Leap using 20 meta-training tasks, execute

python main.py --meta_model leap --num_pretrain 20 --suffix myrun

Logged results can be inspected and visualised using the monitor.FileHandler class. For all runtime options see

python main.py -h

Meta-learners available:

  • leap (requires the src/leap package)
  • reptile
  • fomaml
  • maml (requires the src/maml package)
  • ft (multi-headed finetuning)
  • no (no meta-training)

metalearn-leap's People

Contributors

flennerhag avatar hyandell avatar pgmoren avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.