Skip to content
cosmic-cortex edited this page Dec 15, 2017 · 28 revisions

modAL

Modular Active Learning framework for Python3

Introduction

ModAL is an active learning framework for Python3, designed with modularity, flexibility and extensibility in mind. Built on top of scikit-learn, it allows you to rapidly create active learning workflows with nearly complete freedom. What is more, you can easily replace parts with your custom built solutions, allowing you to design novel algorithms with ease.

Active learning from bird's-eye view

Let's take a look at a general active learning workflow!

The key components of any workflow are the model you choose, the uncertainty measure you use and the query strategy you apply to request labels. With modAL, instead of choosing from a small set of built-in components, you have the freedom to seamlessly integrate scikit-learn or Keras models into your algorithm and you can easily tailor your custom query strategies and uncertainty measures.

modAL in action

Active learning with a scikit-learn classifier, for instance RandomForestClassifier, can be as simple as the following.

from modAL.models import ActiveLearner
from sklearn.ensemble import RandomForestClassifier

# initializing the learner
learner = ActiveLearner(
    predictor=RandomForestClassifier(),
    X_initial=X_train, y_initial=y_train
)

# the active learning loop
n_loops = 50
for loop_idx in range(n_loops):
    # query for labels
    query_idx, query_inst = learner.query(X_pool)

    # supply label for queried instance
    learner.teach(X_pool[query_idx], y_pool[query_idx])

If you would like to use different uncertainty measures and query strategies than the default uncertainty sampling, you can either replace them with several built-in strategies or you can design your own by following a few very simple design principles. For instance, replacing the default uncertainty measure to classification entropy looks the following.

from modAL.models import ActiveLearner
from modAL.uncertainty import classifier_entropy
from sklearn.ensemble import RandomForestClassifier

learner = ActiveLearner(
    predictor=RandomForestClassifier(),
    uncertainty_measure=classifier_uncertainty,
    X_initial=X_train, y_initial=y_train
)

To see how to implement your custom strategies, visit the page Extending modAL!

Clone this wiki locally