Pool-based active learning in Python
Authors: Yao-Yuan Yang, Shao-Chuan Lee, Yu-An Chung, Tung-En Wu, Si-An Chen, Hsuan-Tien Lin
Contributors: Zheng-Yu (Josh) Huang, Po-Yi Lu
libact is a Python package designed to make active learning easier for
real-world users. The package not only implements several popular active learning strategies, but also features the active-learning-by-learning
meta-algorithm that assists the users to automatically select the best strategy
on the fly. Furthermore, the package provides a unified interface for implementing more strategies, models and application-specific labelers. The package is open-source along with issue trackers on github, and can be easily installed from Python Package Index repository.
The technical report associated with the package is on arXiv, and the documentation for the latest release is available on readthedocs.
Comments and questions on the package is welcomed at [email protected]. All contributions to the documentation are greatly appreciated!
Python 3.9, 3.10, 3.11, 3.12
Python dependencies (automatically installed with pip):
sudo apt-get install build-essential gfortran libatlas-base-dev liblapacke-dev python3-devsudo pacman -S lapackebrew install openblaspip install libactNote: For Windows users, it is recommended to use Windows Subsystem for Linux (WSL) as the primary environment for installing and running
libact.
pip install git+https://github.com/ntucllab/libact.gitThis package supports the following build options:
blas: BLAS library to use (default='auto'). Options: auto, openblas, Accelerate, mkl, lapack, blis.lapack: LAPACK library to use (default=auto). Options: auto, openblas, Accelerate, mkl, lapack, blis.variance_reduction: Build variance reduction module (default: true)hintsvm: Build hintsvm module (default: true)To install libact with the default configuration, run:
pip install libactInstall without optional modules:
pip install libact --config-settings=setup-args="-Dvariance_reduction=false" \
--config-settings=setup-args="-Dhintsvm=false"This project utilizes meson and meson-python as the build backend. To build from source, ensure you have the aforementioned dependencies installed on your system. The building procedure additionally requires the following dependencies:
meson-pythonninjacythonnumpyTo simplify the environment setup, we provide a pre-configured environment.yml located at the root directory of the project. Install with conda/mamba to get a head start.
# Clone the repository
git clone https://github.com/ntucllab/libact.git
cd libact
# Create and activate conda environment
conda env create -f environment.yml
conda activate libact
# Install in development mode
pip install --no-build-isolation -e .
# Or build and install
pip install --no-build-isolation .For regular usage (not development), simply install from PyPI or from a local clone:
# From PyPI
pip install libact
# From local clone
pip install .Regular installs do not require build tools at runtime and will work without any additional dependencies.
Editable installs with meson-python automatically rebuild compiled components when you import the package. To ensure build tools are available, use --no-build-isolation:
# First install build dependencies in your environment
pip install meson-python meson ninja cython numpy
# Then install in editable mode without build isolation
pip install --no-build-isolation -e .This ensures that ninja, meson, and other build tools remain available in your environment for rebuilds.
Troubleshooting: If you get errors about missing ninja or build tools when importing libact:
pip install .| Strategy | Type | Description |
|---|---|---|
UncertaintySampling |
Exploitation | Selects samples where the model is least confident |
EpsilonUncertaintySampling |
Exploration + Exploitation | ε-greedy: random with prob ε, uncertainty sampling otherwise |
CoreSet |
Diversity | k-Center Greedy, selects the point farthest from labeled set |
BALD |
Epistemic Uncertainty | Bayesian Active Learning by Disagreement via ensemble (mutual information) |
InformationDensity |
Representativeness | Density-weighted uncertainty — avoids querying outliers |
QueryByCommittee |
Disagreement | Committee of models votes on most informative samples |
QUIRE |
Informativeness + Representativeness | Combines uncertainty and density |
RandomSampling |
Baseline | Uniform random selection |
ActiveLearningByLearning |
Meta-algorithm | Multi-armed bandit that selects the best strategy on the fly |
VarianceReduction |
Variance | Minimizes output variance (requires C extension) |
HintSVM |
SVM-based | SVM-guided active learning (requires C extension) |
DensityWeightedMeta |
Density | Weights informativeness by density |
DWUS |
Density + Uncertainty | Density-weighted uncertainty sampling |
| Model | Description |
|---|---|
LogisticRegression |
Logistic regression with probability output |
SVM |
Support Vector Machine classifier |
Perceptron |
Perceptron classifier |
SklearnAdapter / SklearnProbaAdapter |
Wraps any scikit-learn estimator for use with libact |
The main usage of libact is as follows:
qs = UncertaintySampling(trn_ds, method='lc') # query strategy instance
ask_id = qs.make_query() # let the specified query strategy suggest a data to query
X, y = zip(*trn_ds.data)
lb = lbr.label(X[ask_id]) # query the label of unlabeled data from labeler instance
trn_ds.update(ask_id, lb) # update the dataset with newly queried data…Some examples are available under the examples directory. Before running, use
examples/get_dataset.py to retrieve the dataset used by the examples.
Available examples:
To run the test suite:
python -m unittest -vTo run pylint, install pylint through pip install pylint and run the following command in root directory:
pylint libactTo measure the test code coverage, install coverage through pip install coverage and run the following commands in root directory:
python -m coverage run --source libact --omit */tests/* -m unittest
python -m coverage reportIf you find this package useful, please cite the original works (see Reference of each strategy) as well as the following
@techreport{YY2017,
author = {Yao-Yuan Yang and Shao-Chuan Lee and Yu-An Chung and Tung-En Wu and Si-An Chen and Hsuan-Tien Lin},
title = {libact: Pool-based Active Learning in Python},
institution = {National Taiwan University},
url = {https://github.com/ntucllab/libact},
note = {available as arXiv preprint \\url{https://arxiv.org/abs/1710.00379}},
month = oct,
year = 2017
}The authors thank Chih-Wei Chang and other members of the Computational Learning Lab at National Taiwan University for valuable discussions and various contributions to making this package better.
No open issues yet, or sync has not completed.