Package: meta-blocks
A Modular Toolbox for Accelerating Meta-Learning Research :rocket:MetaBlocksis a modular toolbox for research, experimentation, and reproducible benchmarking of learning-to-learn algorithms.
The toolbox provides a flexible API for working withMetaDatasets,TaskDistributions, andMetaLearners.
The API fully decouples data processing, construction of learning tasks (and their distributions), adaptation algorithms, and model architectures, and makes it easy to experiment with different combinations of these basic building blocks as well as add new components to the growing ecosystem.
Additionally, the library features asuite of benchmarksthat enable reproducibility.
Everything is highly configurable throughhydra.The library isunder active development.
The latest documentation is available at:https://meta-blocks.readthedocs.io/.InstallationMetaBlocks requires Python 3.5+ and TensorFlow 2.2+.For typical useWe recommend usingpipfor installing the latest release of the library:$pipinstallmeta-blocks# normal install$pipinstall--upgrademeta-blocks# or update if needed$pipinstall--premeta-blocks# or include pre-release version for new featuresAlternatively, to install the latest version from themasterbranch:$gitclonehttps://github.com/alshedivat/meta-blocks.git
$pipinstallmeta-blocksNote:to be able to access and run benchmarks, you will need to clone the repository.For development and contributionsYou can install additional development requirements as follows:$pipinstall-rrequirements/dev.txtAlso, please make sure to install pre-commit hooks to ensure proper code style and formatting:$pipinstallpre-commit# install pre-commit$pre-commitinstall# install git hooks$pre-commitrun--all-files# run pre-commit on all the filesGetting started & use casesYou can use the library as (1) a modular benchmarking suite or (2) a scaffold API for new learning-to-learn algorithms.BenchmarkingTo enable reproducible research, we maintain a suite ofbenchmarks/.
To run a benchmark, simply clone the repo, change your working directory to the corresponding benchmark, and execute a run script.
For example:$gitclonehttps://github.com/alshedivat/meta-blocks.git
$cdmeta-blocks/benchmarks/omniglot
$./fetch_data# fetches data for the benchmark$./run_classic_supervised.sh# runs an experiment (train and eval routines in parallel)For more details, please refer tobenchmarks/README.md.MetaBlocks APIMetaBlocksprovides multiple layers of API implemented as a hierarchy of Python classes.
The three major main components areMetaDataset,TaskDistribution, andMetaLearner:MetaDatasetprovides access toDatasetinstances constructed from an underlyingDataSource.Datasetrepresents a collection of data tensors (e.g., in case of multi-class classification, it is a collection of input tensors, one for each class).TaskDistributionfurther builds on top ofMetaDatasetand provides access toTaskinstances that specify the semantics of a learning task.
E.g., a few-shot classification task provides access to non-overlapping support and query subsets of aDataset.
Task distributions determine how tasks are sampled and constructed.
Currently, we supportsupervisedandself-supervisedtasks for few-shot classification.MetaLearnerencapsulates a parametric model (your favorite neural net) and an adaptation algorithm used for adapting the model to new tasks.
Adaptation algorithms must use the API exposed by theTask.Note:decoupling tasks from datasets and (meta-)learning methods is one of the core advantages of meta-blocks over other libraries.Below are the components currently supported by the library:ComponentSupported InstancesMetaDatasetOmniglotMiniImageNet...TaskDistributionClassic supervisedLimited supervisedSelf-supervised...MetaLearnerMAML [1]Reptile [2]Prototypical Networks [3]...Adding your own meta-datasetsTo add your own meta-datasets, you need to subclassMetaDatasetand implement a few methods.[TODO: provide a detailed walk-through example.]If the full data used to construct the meta-dataset is light and easily fits in the memory, you can followthe implementation of Omniglot.
If the dataset is too large or requires some heavy preprocessing, the best way is to usetf.data.DatasetAPI.
As a starting point, you can follow theminiImageNet implementation.Adding your own meta-learnersTo add your own meta-learning algorithms, you need to subclassMetaLearnerand implement two methods:_get_adapted_model(must return an adapted model instance) and_build_adaptation(must build a part of the computation graph that adapts the model).
Example:prototype-based adaptationbuilds prototypes from the support set inside_build_adaptationmethod and returns a model with the corresponding prototypes when_get_adapted_modelis called.[TODO: provide a detailed walk-through example.]CitationIf you use meta-blocks for research, please cite it as follows.@misc{metablocks,
  title={MetaBlocks: A modular toolbox for meta-learning research with a focus on speed and reproducibility.},
  year={2020},
  publisher={GitHub},
  journal={GitHub repository},
  howpublished={\url{https://github.com/alshedivat/meta-blocks}},
}Related projectsA few notable related projects:ProjectDescriptionTorchmetaA PyTorch library that implements multiple few-shot learning methods.learn2learnA PyTorch library that supports meta-RL.References[1] Finn, C., Abbeel, P. and Levine, S. Model-agnostic meta-learning for fast adaptation of deep networks. ICML 2017.[2] Nichol, A., Achiam, J. and Schulman, J. On first-order meta-learning algorithms. arXiv preprint arXiv:1803.02999.[3] Snell, J., Swersky, K. and Zemel, R. Prototypical networks for few-shot learning. NeurIPS 2017.