Skip to main content

fewlabels

CI Docs PyPI Python License: MPL 2.0

Design and robustness for inference with AI predictions.

Prediction-powered inference (PPI) combines a small set of gold-standard human labels with many AI predictions and still gives valid confidence intervals. The core estimator already exists in ppi_py. fewlabels answers the questions that decide whether a PPI study works in practice:

  • How many labels do I need? Sample size, power and cost-optimal allocation between human labelling and model predictions, planned from a small pilot with conservative assumptions.
  • What if the labels were not chosen at random? Inverse probability weighted PPI for known selection probabilities (stratified or active labelling), and a sensitivity analysis with a tipping point for unknown selection.
  • What if I have several AI annotators? Optimal combination that accounts for correlated errors, plus a diagnostic report.
  • What if my data are clustered? Cluster-robust variances for patients with several images, documents from the same site, and so on.

In short: not how to compute PPI, but how to plan it and when to trust it.

Installation

pip install fewlabels

Python 3.10 or newer is required. The only runtime dependency is NumPy.

Quick start

Plan the label budget

A classifier with sensitivity 0.90 and specificity 0.95 will be used to estimate a prevalence of about 20 % in 50 000 records. How many records must be labelled by hand for a margin of error of 2 percentage points?

import fewlabels as fl

params = fl.DesignParameters.from_proportion(prevalence=0.2, sensitivity=0.9, specificity=0.95)
fl.required_labels(0.02, params, n_unlabeled=50_000)  # 512 labels with PPI
fl.required_labels(0.02, fl.DesignParameters(params.sd_y, r2=0.0))  # 1537 labels without

With a pilot sample, plan with pessimistic parameters:

params = fl.DesignParameters.from_pilot(y_pilot, preds_pilot, conservative=True, seed=0)

Estimate

result = fl.ppi_mean(y, preds_labeled, preds_unlabeled, alpha=0.05)
print(result.estimate, result.ci, result.effective_labels)

preds_labeled and preds_unlabeled may have several columns, one per AI annotator. Pass clusters_labeled and clusters_unlabeled for clustered data.

Labels chosen with known probabilities

pi = fl.inclusion_probabilities(uncertainty, budget=500, floor=0.01)
labeled = fl.poisson_sample(pi, seed=0)
# ... send the selected cases for labelling ...
result = fl.ipw_ppi_mean(y_all, preds_all, labeled, pi)

Check robustness

fl.selection_sensitivity(y, preds_labeled, preds_unlabeled, gamma=[1, 1.5, 2])
fl.tipping_point(y, preds_labeled, preds_unlabeled, null=0.25)
print(
    fl.annotator_report(y, preds_labeled_matrix, names=["model_a", "model_b", "model_c"]).summary()
)

Already using ppi_py?

from fewlabels.compat import ppi_mean_ci  # same signature and numbers as ppi_py

What is inside

Module Purpose Main objects
fewlabels.design Sample size, power and budget allocation DesignParameters, required_labels, required_labels_for_power, cost_optimal_allocation, design_effect
fewlabels.estimation PPI++ for one or several annotators, clusters, known selection probabilities ppi_mean, ipw_ppi_mean, classical_mean, inclusion_probabilities
fewlabels.robustness Non-random labelling and correlated annotators selection_sensitivity, tipping_point, annotator_report
fewlabels.compat The mean estimation interface of ppi_py ppi_mean_ci, ppi_mean_pointestimate, ppi_mean_pval, classical_mean_ci
fewlabels.datasets Synthetic data for examples and simulations make_ppi_data, make_annotator_data, make_clustered_data

Command line

fewlabels plan --prevalence 0.2 --sensitivity 0.9 --specificity 0.95 \
    --half-width 0.02 --unlabeled 50000

fewlabels plan --sd-y 0.4 --r2 0.7 --budget 10000 --cost-label 20 --cost-prediction 0.05

Documentation

The user guide, the theory behind each method and the API reference are at https://yunusimanov.github.io/fewlabels.

fewlabels is the second library in a series on statistically sound use of AI systems. Its sibling anywatch provides anytime-valid post-market monitoring of deployed models.

Citing

If you use fewlabels in academic work, please cite it using the metadata in CITATION.cff or the "Cite this repository" button on GitHub, together with the original PPI and PPI++ papers listed in the documentation.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md and the Code of Conduct.

License

fewlabels is distributed under the Mozilla Public License 2.0.

Author

Yunus Imanov, Researcher, Department of Engineering Mathematics and Artificial Intelligence, Azerbaijan Technical University, Baku, Azerbaijan. Contact: yunus.imanov.fz@student.aztu.edu.az

Metadata

Release files for fewlabels 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fewlabels 0.1.0
File Size Uploaded Provenance Actions
fewlabels-0.1.0.tar.gz 41.1 kB With provenance Details for fewlabels-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fewlabels 0.1.0
File Interpreter ABI Platform Actions
fewlabels-0.1.0-py3-none-any.whl Python 3 none any Details for fewlabels-0.1.0-py3-none-any.whl

Total release size: 82.4 kB

Release files / fewlabels-0.1.0.tar.gz

Download URL fewlabels-0.1.0.tar.gz
Size 41.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9b7cb1888b186d27bba31d5007795abef4108aa1f23999991e36839c7d63af7f
BLAKE2b-256 checksum
How to use checksums
4ce4739e7a2ca047517ef88c3c93a179c7e59a8b0877a47386af5b2f68391a89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / fewlabels-0.1.0-py3-none-any.whl

Download URL fewlabels-0.1.0-py3-none-any.whl
Size 41.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf0054220f0e6f217d16419084d1d3fc938ae729d5dc383b8bd43119f680cf45
BLAKE2b-256 checksum
How to use checksums
0733244d92fcb36b3658740e2401a5707b23d766e4eea66dee2877252a8189eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Security for fewlabels 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fewlabels-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page