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 Tasks
| Task Type | Example Model |
|---|---|
sequence-classification |
distilbert-base-uncased-finetuned-sst-2-english |
token-classification |
dslim/bert-base-NER |
question-answering |
deepset/bert-base-cased-squad2 |
regression |
roberta-base (custom heads) |
⚠️ Your model must contain dropout layers for MC sampling to work (most HF models do).
🤖 Supported Models
Dropwise works with any AutoModelForSequenceClassification compatible model including:
bert-base-uncased,bert-large-uncasedroberta-base,roberta-largedeberta-v3-base,deberta-v2-xlargealbert-base-v2,distilbert-base-uncased- Any custom fine-tuned Hugging Face model for classification
⚠️ 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 classentropy: predictive entropy (higher = less confident)std_dev: standard deviation across MC passes for each classmean_logits: average logits before softmaxprobs: 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
│ └── tasks/
│ ├── __init__.py
│ ├── sequence_classification.py
│ ├── token_classification.py
│ ├── question_answering.py
│ └── regression.py
├── tests/
│ └── 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dropwise-0.2.0.tar.gz.
File metadata
- Download URL: dropwise-0.2.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9d41d16e5f4833858f727517f06a2ada4e8a04b8545ad4e0ad5cfb1dd443e59
|
|
| MD5 |
d681478d6491084fa4b414825d0003bf
|
|
| BLAKE2b-256 |
30ae7a6bed66fc03c1283af14a73aca30592df8093258099e628978b3991213f
|
File details
Details for the file dropwise-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dropwise-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6db786a3159386a726582fffd3b75ea9adc68045330b714cdd4c6bc917a5fb4
|
|
| MD5 |
a35cbf50d2800d36ad8dbfea90d89ef6
|
|
| BLAKE2b-256 |
df0d557b6698e15ebb19931e787dc8d26c0ef29fa4650d367f46ef9a207ca6d3
|