Skip to main content

Monte Carlo Dropout-based uncertainty estimation for Transformers

Project description

Dropwise

Dropwise is a lightweight PyTorch/HuggingFace wrapper for performing Monte Carlo Dropout–based uncertainty estimation in Transformers. It enables confidence-aware decision making by revealing how certain a model is about its predictions — all with just a few lines of code.


🚀 Features

  • ✅ Enable dropout during inference for Bayesian-like uncertainty estimation
  • ✅ Compute predictive entropy, confidence, and per-class standard deviation
  • ✅ Works seamlessly with Hugging Face Transformers and PyTorch
  • ✅ Supports batch inference, CPU/GPU, and customizable num_passes
  • ✅ Cleanly packaged and extensible for research or production

🤖 Supported Models

Dropwise works with any AutoModelForSequenceClassification compatible model including:

  • bert-base-uncased, bert-large-uncased
  • roberta-base, roberta-large
  • deberta-v3-base, deberta-v2-xlarge
  • albert-base-v2, distilbert-base-uncased
  • Any custom fine-tuned Hugging Face model for classification

⚠️ Note: The model must contain dropout layers (most pretrained transformers do).


📦 Installation

pip install dropwise  

Or install locally for development:

git clone https://github.com/aryanator01/dropwise.git
cd dropwise
pip install -e .

🧠 Example Usage

from transformers import AutoTokenizer, AutoModelForSequenceClassification
from dropwise import DropwisePredictor

model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")

predictor = DropwisePredictor(model, tokenizer, num_passes=30)
result = predictor.predict("The performance was unexpectedly good!")

print("Predicted class:", result['predicted_class'].item())
print("Entropy:", result['entropy'].item())
print("Confidence:", result['probs'].max().item())
print("Per-class std dev:", result['std_dev'])

📊 Output Dictionary

  • predicted_class: index of most probable class
  • entropy: predictive entropy (higher = less confident)
  • std_dev: standard deviation across MC passes for each class
  • mean_logits: average logits before softmax
  • probs: softmax probabilities

🧠 Why Dropwise?

Unlike deterministic predictions, Dropwise estimates uncertainty via stochastic forward passes — enabling confidence-aware applications.

Use cases include:

  • Filtering low-confidence predictions
  • Active learning and semi-supervised setups
  • Detecting ambiguous, adversarial, or out-of-distribution inputs
  • Enhancing interpretability and robustness in real-world deployment

📂 Folder Structure

dropwise/
├── dropwise/
│   ├── __init__.py
│   └── predictor.py
├── tests/
│   ├── __init__.py
│   └── test_predictor.py
├── setup.py
├── README.md
├── LICENSE

🧪 Running Tests

python tests/test_predictor.py

📝 License

MIT License


Made with ❤️ for uncertainty-aware, explainable AI. [Coming soon to PyPI.]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dropwise-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dropwise-0.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file dropwise-0.1.1.tar.gz.

File metadata

  • Download URL: dropwise-0.1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for dropwise-0.1.1.tar.gz
Algorithm Hash digest
SHA256 32950b622eba9aebaf6f1e8f561c8ca30e5c65601c1f5f4d949094fa4452ec1f
MD5 8d2608837a1e01abf3fa0a983c8d2c66
BLAKE2b-256 14d955b0d8de668af148a927abf013289dbe4ca7e0f2b9ea0aab2dd80054847e

See more details on using hashes here.

File details

Details for the file dropwise-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dropwise-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for dropwise-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cdb2252917467ef4153aec63e2602978d2f1488d2dbf2e31b1f3d3635e4086c7
MD5 f075da462c6b848c0138b4ce5bec4642
BLAKE2b-256 87e0f702c2c226f3384a306334f7c8286c88a8935be315a007082e909e4212d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page