trustbench 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. trustbench-0.2.0/PKG-INFO +296 -0
  2. trustbench-0.2.0/README.md +249 -0
  3. trustbench-0.2.0/pyproject.toml +82 -0
  4. trustbench-0.2.0/pyproject.toml.orig +105 -0
  5. trustbench-0.2.0/src/trustbench/__init__.py +121 -0
  6. trustbench-0.2.0/src/trustbench/api/__init__.py +5 -0
  7. trustbench-0.2.0/src/trustbench/api/app.py +45 -0
  8. trustbench-0.2.0/src/trustbench/api/routes/experiments.py +82 -0
  9. trustbench-0.2.0/src/trustbench/benchmark.py +264 -0
  10. trustbench-0.2.0/src/trustbench/cli/__init__.py +5 -0
  11. trustbench-0.2.0/src/trustbench/cli/main.py +303 -0
  12. trustbench-0.2.0/src/trustbench/config/__init__.py +22 -0
  13. trustbench-0.2.0/src/trustbench/config/loader.py +71 -0
  14. trustbench-0.2.0/src/trustbench/config/schema.py +149 -0
  15. trustbench-0.2.0/src/trustbench/core/__init__.py +30 -0
  16. trustbench-0.2.0/src/trustbench/core/evaluator.py +163 -0
  17. trustbench-0.2.0/src/trustbench/core/exceptions.py +17 -0
  18. trustbench-0.2.0/src/trustbench/core/inference.py +137 -0
  19. trustbench-0.2.0/src/trustbench/core/protocols.py +57 -0
  20. trustbench-0.2.0/src/trustbench/core/reproducibility.py +74 -0
  21. trustbench-0.2.0/src/trustbench/core/results.py +56 -0
  22. trustbench-0.2.0/src/trustbench/datasets/__init__.py +23 -0
  23. trustbench-0.2.0/src/trustbench/datasets/base.py +31 -0
  24. trustbench-0.2.0/src/trustbench/datasets/cifar10.py +164 -0
  25. trustbench-0.2.0/src/trustbench/datasets/memory.py +49 -0
  26. trustbench-0.2.0/src/trustbench/datasets/torch_dataset.py +108 -0
  27. trustbench-0.2.0/src/trustbench/evaluation/__init__.py +164 -0
  28. trustbench-0.2.0/src/trustbench/evaluation/artifacts.py +13 -0
  29. trustbench-0.2.0/src/trustbench/evaluation/calibration.py +251 -0
  30. trustbench-0.2.0/src/trustbench/evaluation/classification.py +145 -0
  31. trustbench-0.2.0/src/trustbench/evaluation/distribution_shift.py +269 -0
  32. trustbench-0.2.0/src/trustbench/evaluation/error_detection.py +281 -0
  33. trustbench-0.2.0/src/trustbench/evaluation/fairness.py +103 -0
  34. trustbench-0.2.0/src/trustbench/evaluation/inference.py +16 -0
  35. trustbench-0.2.0/src/trustbench/evaluation/regression.py +119 -0
  36. trustbench-0.2.0/src/trustbench/evaluation/reproducibility.py +13 -0
  37. trustbench-0.2.0/src/trustbench/evaluation/retrieval.py +76 -0
  38. trustbench-0.2.0/src/trustbench/evaluation/runner.py +99 -0
  39. trustbench-0.2.0/src/trustbench/evaluation/segmentation.py +104 -0
  40. trustbench-0.2.0/src/trustbench/evaluation/selective.py +221 -0
  41. trustbench-0.2.0/src/trustbench/evaluation/streaming.py +237 -0
  42. trustbench-0.2.0/src/trustbench/evaluation/uncertainty.py +341 -0
  43. trustbench-0.2.0/src/trustbench/experiments/__init__.py +48 -0
  44. trustbench-0.2.0/src/trustbench/experiments/comparison.py +284 -0
  45. trustbench-0.2.0/src/trustbench/experiments/lineage.py +234 -0
  46. trustbench-0.2.0/src/trustbench/experiments/manager.py +387 -0
  47. trustbench-0.2.0/src/trustbench/experiments/registry.py +184 -0
  48. trustbench-0.2.0/src/trustbench/experiments/schemas.py +78 -0
  49. trustbench-0.2.0/src/trustbench/metrics/__init__.py +45 -0
  50. trustbench-0.2.0/src/trustbench/metrics/calibration.py +15 -0
  51. trustbench-0.2.0/src/trustbench/metrics/classification.py +11 -0
  52. trustbench-0.2.0/src/trustbench/metrics/error_detection.py +17 -0
  53. trustbench-0.2.0/src/trustbench/metrics/regression.py +96 -0
  54. trustbench-0.2.0/src/trustbench/metrics/retrieval.py +108 -0
  55. trustbench-0.2.0/src/trustbench/metrics/segmentation.py +116 -0
  56. trustbench-0.2.0/src/trustbench/metrics/selective.py +17 -0
  57. trustbench-0.2.0/src/trustbench/metrics/uncertainty.py +23 -0
  58. trustbench-0.2.0/src/trustbench/models/__init__.py +74 -0
  59. trustbench-0.2.0/src/trustbench/models/base.py +48 -0
  60. trustbench-0.2.0/src/trustbench/models/checkpoint.py +98 -0
  61. trustbench-0.2.0/src/trustbench/models/densenet.py +100 -0
  62. trustbench-0.2.0/src/trustbench/models/dla.py +124 -0
  63. trustbench-0.2.0/src/trustbench/models/dla_simple.py +117 -0
  64. trustbench-0.2.0/src/trustbench/models/dpn.py +90 -0
  65. trustbench-0.2.0/src/trustbench/models/efficientnet.py +165 -0
  66. trustbench-0.2.0/src/trustbench/models/googlenet.py +98 -0
  67. trustbench-0.2.0/src/trustbench/models/jax.py +95 -0
  68. trustbench-0.2.0/src/trustbench/models/keras.py +105 -0
  69. trustbench-0.2.0/src/trustbench/models/lenet.py +24 -0
  70. trustbench-0.2.0/src/trustbench/models/mobilenet.py +53 -0
  71. trustbench-0.2.0/src/trustbench/models/mobilenetv2.py +79 -0
  72. trustbench-0.2.0/src/trustbench/models/onnx.py +134 -0
  73. trustbench-0.2.0/src/trustbench/models/pnasnet.py +118 -0
  74. trustbench-0.2.0/src/trustbench/models/preact_resnet.py +110 -0
  75. trustbench-0.2.0/src/trustbench/models/pytorch.py +208 -0
  76. trustbench-0.2.0/src/trustbench/models/regnet.py +143 -0
  77. trustbench-0.2.0/src/trustbench/models/resnet.py +124 -0
  78. trustbench-0.2.0/src/trustbench/models/resnext.py +95 -0
  79. trustbench-0.2.0/src/trustbench/models/senet.py +113 -0
  80. trustbench-0.2.0/src/trustbench/models/shufflenet.py +101 -0
  81. trustbench-0.2.0/src/trustbench/models/shufflenetv2.py +153 -0
  82. trustbench-0.2.0/src/trustbench/models/sklearn.py +141 -0
  83. trustbench-0.2.0/src/trustbench/models/vgg.py +37 -0
  84. trustbench-0.2.0/src/trustbench/registry/__init__.py +77 -0
  85. trustbench-0.2.0/src/trustbench/registry/corruptions.py +181 -0
  86. trustbench-0.2.0/src/trustbench/registry/datasets.py +192 -0
  87. trustbench-0.2.0/src/trustbench/registry/metrics.py +244 -0
  88. trustbench-0.2.0/src/trustbench/registry/models.py +212 -0
  89. trustbench-0.2.0/src/trustbench/registry/plugins.py +222 -0
  90. trustbench-0.2.0/src/trustbench/reporting/__init__.py +57 -0
  91. trustbench-0.2.0/src/trustbench/reporting/artifacts.py +131 -0
  92. trustbench-0.2.0/src/trustbench/reporting/hashing.py +21 -0
  93. trustbench-0.2.0/src/trustbench/reporting/html_report.py +717 -0
  94. trustbench-0.2.0/src/trustbench/reporting/plots.py +549 -0
  95. trustbench-0.2.0/src/trustbench/reporting/result_io.py +109 -0
  96. trustbench-0.2.0/src/trustbench/reporting/schema.py +195 -0
  97. trustbench-0.2.0/src/trustbench/reporting/tables.py +64 -0
  98. trustbench-0.2.0/src/trustbench/robustness/__init__.py +70 -0
  99. trustbench-0.2.0/src/trustbench/robustness/aggregation.py +159 -0
  100. trustbench-0.2.0/src/trustbench/robustness/corruptions.py +426 -0
  101. trustbench-0.2.0/src/trustbench/robustness/evaluator.py +313 -0
  102. trustbench-0.2.0/src/trustbench/robustness/report.py +11 -0
  103. trustbench-0.2.0/src/trustbench/robustness/severity.py +525 -0
  104. trustbench-0.2.0/src/trustbench/storage/__init__.py +66 -0
  105. trustbench-0.2.0/src/trustbench/storage/base.py +171 -0
  106. trustbench-0.2.0/src/trustbench/storage/database.py +67 -0
  107. trustbench-0.2.0/src/trustbench/storage/filesystem.py +489 -0
  108. trustbench-0.2.0/src/trustbench/storage/models.py +55 -0
  109. trustbench-0.2.0/src/trustbench/storage/repositories.py +168 -0
  110. trustbench-0.2.0/src/trustbench/storage/sqlite.py +470 -0
@@ -0,0 +1,296 @@
1
+ Metadata-Version: 2.4
2
+ Name: trustbench
3
+ Version: 0.2.0
4
+ Summary: TrustBench: Evaluation framework for ML model reliability, robustness, and uncertainty.
5
+ Keywords: machine-learning,evaluation,reliability,robustness,uncertainty,calibration,ood-detection,fairness
6
+ Author: Uni-Creator
7
+ Author-email: Uni-Creator <abhayr24564@gmail.com>
8
+ License-Expression: Apache-2.0
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Requires-Dist: numpy>=1.24.0
17
+ Requires-Dist: scipy>=1.10.0
18
+ Requires-Dist: scikit-learn>=1.3.0
19
+ Requires-Dist: pydantic>=2.0.0
20
+ Requires-Dist: pyyaml>=6.0
21
+ Requires-Dist: click>=8.1.0
22
+ Requires-Dist: jinja2>=3.1.6
23
+ Requires-Dist: pillow>=10.0.0
24
+ Requires-Dist: trustbench[torch,storage,api,reporting,onnx] ; extra == 'all'
25
+ Requires-Dist: fastapi>=0.100.0 ; extra == 'api'
26
+ Requires-Dist: uvicorn[standard]>=0.20.0 ; extra == 'api'
27
+ Requires-Dist: jax>=0.4.20 ; extra == 'jax'
28
+ Requires-Dist: onnxruntime>=1.16.0 ; extra == 'onnx'
29
+ Requires-Dist: torch>=2.0.0 ; extra == 'pytorch'
30
+ Requires-Dist: torchvision>=0.15.0 ; extra == 'pytorch'
31
+ Requires-Dist: plotly>=5.0.0 ; extra == 'reporting'
32
+ Requires-Dist: sqlalchemy>=2.0.0 ; extra == 'storage'
33
+ Requires-Dist: tensorflow>=2.15.0 ; extra == 'tensorflow'
34
+ Requires-Dist: torch>=2.0.0 ; extra == 'torch'
35
+ Requires-Dist: torchvision>=0.15.0 ; extra == 'torch'
36
+ Requires-Python: >=3.11
37
+ Provides-Extra: all
38
+ Provides-Extra: api
39
+ Provides-Extra: jax
40
+ Provides-Extra: onnx
41
+ Provides-Extra: pytorch
42
+ Provides-Extra: reporting
43
+ Provides-Extra: storage
44
+ Provides-Extra: tensorflow
45
+ Provides-Extra: torch
46
+ Description-Content-Type: text/markdown
47
+
48
+ <div align="center">
49
+
50
+ # TrustBench
51
+
52
+ **ML Reliability, Robustness, Uncertainty & Fairness Evaluation Framework**
53
+
54
+ [![PyPI version](https://img.shields.io/badge/pypi-v0.2.0-blue.svg)](https://pypi.org/project/trustbench/)
55
+ [![Python Versions](https://img.shields.io/badge/python-3.11%20%7C%203.12-blue.svg)](https://pypi.org/project/trustbench/)
56
+ [![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)](LICENSE)
57
+ [![CI Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](.github/workflows/ci.yml)
58
+ [![Tests](https://img.shields.io/badge/tests-194%20passed-success.svg)](tests/)
59
+
60
+ </div>
61
+
62
+ ---
63
+
64
+ TrustBench is a framework-independent machine learning evaluation library designed to measure how reliable models remain under distribution shifts, input corruptions, calibration failures, and algorithmic bias.
65
+
66
+ Traditional model evaluation focuses almost exclusively on accuracy. TrustBench investigates whether models remain reliable in deployment:
67
+ - **Calibration**: Does predicted confidence reflect the true probability of correctness?
68
+ - **Robustness**: How gracefully does performance degrade under physical, digital, and environmental corruptions?
69
+ - **Uncertainty & Error Detection**: Can predictive entropy and free energy identify incorrect predictions before downstream failures occur?
70
+ - **Selective Prediction**: What error rate is achieved when models defer low-confidence decisions?
71
+ - **Multi-Framework**: Evaluate PyTorch, Scikit-learn, ONNX Runtime, TensorFlow/Keras, and JAX models using identical contracts.
72
+ - **Multi-Task**: Native evaluators for Classification, Regression, Information Retrieval, and Semantic Segmentation.
73
+
74
+ ---
75
+
76
+ ## Architecture Overview
77
+
78
+ ```mermaid
79
+ flowchart TD
80
+ UserConfig["trustbench.yaml / Python API"] --> TB["TrustBench Orchestrator"]
81
+
82
+ subgraph FrameworkAdapters ["Framework Adapters (Optional)"]
83
+ Torch["PyTorch (nn.Module)"]
84
+ SKLearn["Scikit-learn (Estimators)"]
85
+ ONNX["ONNX Runtime (.onnx)"]
86
+ Keras["TensorFlow / Keras"]
87
+ JAX["JAX / Flax"]
88
+ end
89
+
90
+ subgraph TaskPipelines ["Task-Specific Evaluators"]
91
+ Cls["Classification\n(Accuracy, Macro-F1, Confusion Matrix)"]
92
+ Calib["Calibration & Reliability\n(ECE, AdaECE, Brier, Temperature)"]
93
+ Unc["Uncertainty & Detection\n(Entropy, Energy, AUROC, AUPRC)"]
94
+ Sel["Selective Prediction\n(Risk-Coverage, AURC)"]
95
+ Rob["Robustness Suite\n(Noise, Blur, Brightness 1-5)"]
96
+ Reg["Regression Suite\n(MAE, RMSE, R², 95% PICP)"]
97
+ Ret["Retrieval Suite\n(Recall@K, MRR, nDCG@K)"]
98
+ Seg["Segmentation Suite\n(mIoU, Dice, Pixel Acc)"]
99
+ Fair["Fairness Suite\n(Demographic Parity, Disparate Impact)"]
100
+ end
101
+
102
+ subgraph StorageReporting ["Storage & Reporting"]
103
+ FSStore["Filesystem Store\n(Atomic Writes & Checksums)"]
104
+ SQLiteStore["SQLite & SQLAlchemy\n(Queryable Registry)"]
105
+ HTMLRep["Interactive HTML Report\n(Zero-Dependency Plotly)"]
106
+ JSONRep["Versioned JSON Schema\n(v1.0 Lineage)"]
107
+ end
108
+
109
+ FrameworkAdapters --> TB
110
+ TB --> TaskPipelines
111
+ TaskPipelines --> StorageReporting
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Installation
117
+
118
+ TrustBench features a lightweight core with optional framework groups:
119
+
120
+ ```bash
121
+ # Core installation (NumPy, SciPy, Scikit-learn, Click, Pydantic)
122
+ pip install trustbench
123
+
124
+ # For PyTorch model evaluation
125
+ pip install "trustbench[pytorch]"
126
+
127
+ # For ONNX Runtime inference
128
+ pip install "trustbench[onnx]"
129
+
130
+ # Full installation (all frameworks, storage, and visualization)
131
+ pip install "trustbench[all]"
132
+ ```
133
+
134
+ See the [Installation Guide](docs/installation.md) for detailed platform requirements.
135
+
136
+ ---
137
+
138
+ ## 5-Minute Quickstart
139
+
140
+ ### 1. Command Line Interface (CLI)
141
+
142
+ ```bash
143
+ # Initialize a starter configuration
144
+ trustbench init
145
+
146
+ # Validate configuration paths and settings
147
+ trustbench validate trustbench.yaml
148
+
149
+ # Run evaluation and generate reports
150
+ trustbench evaluate trustbench.yaml
151
+ ```
152
+
153
+ ### 2. Python API
154
+
155
+ ```python
156
+ import numpy as np
157
+ from sklearn.linear_model import LogisticRegression
158
+ from trustbench import TrustBench, InMemoryDatasetAdapter
159
+
160
+ # 1. Train or load your model
161
+ X_train = np.random.randn(200, 4)
162
+ y_train = np.random.randint(0, 2, size=200)
163
+ clf = LogisticRegression().fit(X_train, y_train)
164
+
165
+ # 2. Prepare test dataset
166
+ X_test = np.random.randn(50, 4)
167
+ y_test = np.random.randint(0, 2, size=50)
168
+ dataset = InMemoryDatasetAdapter(inputs=X_test, labels=y_test)
169
+
170
+ # 3. Evaluate reliability
171
+ bench = TrustBench(model=clf, dataset=dataset)
172
+ result = bench.evaluate()
173
+
174
+ print(f"Accuracy: {result.metrics['classification']['accuracy']:.2%}")
175
+ print(f"Brier Score: {result.metrics['calibration']['brier_score']:.4f}")
176
+ print(f"ECE: {result.metrics['calibration']['ece']:.4f}")
177
+ ```
178
+
179
+ ---
180
+
181
+ ## Multi-Task Evaluation
182
+
183
+ ### Continuous Regression Evaluation
184
+ ```python
185
+ from trustbench import evaluate_regression, InMemoryDatasetAdapter
186
+ from sklearn.linear_model import Ridge
187
+ import numpy as np
188
+
189
+ model = Ridge().fit(X_train, y_train)
190
+ dataset = InMemoryDatasetAdapter(inputs=X_test, labels=y_test)
191
+
192
+ result = evaluate_regression(model, dataset)
193
+ print(f"MAE: {result.metrics['mae']:.3f}")
194
+ print(f"RMSE: {result.metrics['rmse']:.3f}")
195
+ print(f"R²: {result.metrics['r2']:.3f}")
196
+ ```
197
+
198
+ ### Information Retrieval Evaluation
199
+ ```python
200
+ from trustbench import evaluate_retrieval
201
+
202
+ ground_truth = {"q1": ["docA", "docB"], "q2": ["docC"]}
203
+ retrieved = {"q1": ["docA", "docX", "docB"], "q2": ["docY", "docC"]}
204
+
205
+ res = evaluate_retrieval(ground_truth, retrieved, k_list=(1, 3))
206
+ print(f"MRR: {res.metrics['mrr']:.3f}")
207
+ print(f"Recall@1: {res.metrics['recall@1']:.3f}")
208
+ print(f"nDCG@3: {res.metrics['ndcg@3']:.3f}")
209
+ ```
210
+
211
+ ### Semantic Segmentation Evaluation
212
+ ```python
213
+ from trustbench import evaluate_segmentation
214
+
215
+ result = evaluate_segmentation(segmentation_model, segmentation_dataset, num_classes=21)
216
+ print(f"Mean IoU: {result.metrics['miou']:.3f}")
217
+ print(f"Dice (F1): {result.metrics['dice']:.3f}")
218
+ print(f"Pixel Accuracy: {result.metrics['pixel_accuracy']:.2%}")
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Key Metrics Reference
224
+
225
+ | Category | Metrics Implemented |
226
+ |---|---|
227
+ | **Classification** | Accuracy, Balanced Accuracy, Precision, Recall, Macro-F1, Confusion Matrix |
228
+ | **Calibration** | Expected Calibration Error (ECE), Adaptive ECE, Maximum Calibration Error (MCE), Brier Score, NLL |
229
+ | **Uncertainty** | Predictive Shannon Entropy, Maximum Softmax Probability (MSP), Free Energy |
230
+ | **Error Detection** | AUROC, AUPRC, False Positive Rate at 95% TPR (FPR@95%TPR), Minimum Detection Error |
231
+ | **Selective Prediction** | Risk-Coverage Trade-off Curves, Area Under Risk-Coverage (AURC), Excess AURC |
232
+ | **Robustness** | Gaussian Noise, Blur, Brightness, Defocus, Contrast, Corrupted Accuracy Drop |
233
+ | **Regression** | MAE, MSE, RMSE, $R^2$, MedAE, MAPE, Max Error, 95% Interval Coverage (PICP, MPIW) |
234
+ | **Retrieval** | Mean Reciprocal Rank (MRR), Mean Average Precision (MAP), Recall@K, Precision@K, nDCG@K |
235
+ | **Segmentation** | Mean IoU (mIoU), Dice (F1), Pixel Accuracy, Frequency-Weighted IoU (FWIoU) |
236
+ | **Fairness** | Demographic Parity Difference, Disparate Impact Ratio, Equalized Odds Difference |
237
+
238
+ See [Metrics Documentation](docs/metrics.md) for mathematical derivations.
239
+
240
+ ---
241
+
242
+ ## Tutorials & Examples
243
+
244
+ Ready-to-run examples are available in the [`examples/`](examples/) directory:
245
+
246
+ 1. **[01_evaluate_pytorch_model.py](examples/01_evaluate_pytorch_model.py)**: Evaluate custom PyTorch `nn.Module`.
247
+ 2. **[02_evaluate_cifar10.py](examples/02_evaluate_cifar10.py)**: End-to-end CIFAR-10 ResNet evaluation via configuration.
248
+ 3. **[03_robustness_benchmark.py](examples/03_robustness_benchmark.py)**: Evaluate accuracy degradation across noise & corruptions.
249
+ 4. **[04_analyze_calibration.py](examples/04_analyze_calibration.py)**: Compute ECE and fit validation temperature scaling.
250
+ 5. **[05_evaluate_uncertainty.py](examples/05_evaluate_uncertainty.py)**: Predict error detection AUROC and risk-coverage curves.
251
+ 6. **[06_compare_checkpoints.py](examples/06_compare_checkpoints.py)**: Quantify statistical differentials between model checkpoints.
252
+ 7. **[07_save_and_reproduce_experiment.py](examples/07_save_and_reproduce_experiment.py)**: Atomic experiment persistence and checksum verification.
253
+ 8. **[08_create_custom_metric.py](examples/08_create_custom_metric.py)**: Register custom evaluation scoring functions.
254
+ 9. **[09_create_custom_model_adapter.py](examples/09_create_custom_model_adapter.py)**: Implement the runtime `ModelAdapter` protocol.
255
+
256
+ ---
257
+
258
+ ## Documentation
259
+
260
+ Full documentation is available in the [`docs/`](docs/) directory:
261
+ - [Installation Guide](docs/installation.md)
262
+ - [Quickstart Guide](docs/quickstart.md)
263
+ - [Python API Reference](docs/api.md)
264
+ - [CLI Reference](docs/cli.md)
265
+ - [Configuration Guide](docs/configuration.md)
266
+ - [Model Adapters](docs/model-adapters.md)
267
+ - [Dataset Adapters](docs/dataset-adapters.md)
268
+ - [Metrics Documentation](docs/metrics.md)
269
+ - [Robustness Testing](docs/robustness.md)
270
+ - [Experiment Tracking](docs/experiments.md)
271
+ - [Reporting & Visualization](docs/reporting.md)
272
+ - [Plugin Development](docs/plugins.md)
273
+ - [Troubleshooting & FAQ](docs/troubleshooting.md)
274
+
275
+ ---
276
+
277
+ ## Contributing
278
+
279
+ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) and our [Code of Conduct](CODE_OF_CONDUCT.md).
280
+
281
+ ```bash
282
+ # Run tests
283
+ pytest
284
+
285
+ # Check code style
286
+ ruff check .
287
+
288
+ # Static type analysis
289
+ mypy src/trustbench/core src/trustbench/reporting src/trustbench/metrics
290
+ ```
291
+
292
+ ---
293
+
294
+ ## License
295
+
296
+ TrustBench is open-source software licensed under the [Apache License, Version 2.0](LICENSE).
@@ -0,0 +1,249 @@
1
+ <div align="center">
2
+
3
+ # TrustBench
4
+
5
+ **ML Reliability, Robustness, Uncertainty & Fairness Evaluation Framework**
6
+
7
+ [![PyPI version](https://img.shields.io/badge/pypi-v0.2.0-blue.svg)](https://pypi.org/project/trustbench/)
8
+ [![Python Versions](https://img.shields.io/badge/python-3.11%20%7C%203.12-blue.svg)](https://pypi.org/project/trustbench/)
9
+ [![License](https://img.shields.io/badge/license-Apache%202.0-green.svg)](LICENSE)
10
+ [![CI Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](.github/workflows/ci.yml)
11
+ [![Tests](https://img.shields.io/badge/tests-194%20passed-success.svg)](tests/)
12
+
13
+ </div>
14
+
15
+ ---
16
+
17
+ TrustBench is a framework-independent machine learning evaluation library designed to measure how reliable models remain under distribution shifts, input corruptions, calibration failures, and algorithmic bias.
18
+
19
+ Traditional model evaluation focuses almost exclusively on accuracy. TrustBench investigates whether models remain reliable in deployment:
20
+ - **Calibration**: Does predicted confidence reflect the true probability of correctness?
21
+ - **Robustness**: How gracefully does performance degrade under physical, digital, and environmental corruptions?
22
+ - **Uncertainty & Error Detection**: Can predictive entropy and free energy identify incorrect predictions before downstream failures occur?
23
+ - **Selective Prediction**: What error rate is achieved when models defer low-confidence decisions?
24
+ - **Multi-Framework**: Evaluate PyTorch, Scikit-learn, ONNX Runtime, TensorFlow/Keras, and JAX models using identical contracts.
25
+ - **Multi-Task**: Native evaluators for Classification, Regression, Information Retrieval, and Semantic Segmentation.
26
+
27
+ ---
28
+
29
+ ## Architecture Overview
30
+
31
+ ```mermaid
32
+ flowchart TD
33
+ UserConfig["trustbench.yaml / Python API"] --> TB["TrustBench Orchestrator"]
34
+
35
+ subgraph FrameworkAdapters ["Framework Adapters (Optional)"]
36
+ Torch["PyTorch (nn.Module)"]
37
+ SKLearn["Scikit-learn (Estimators)"]
38
+ ONNX["ONNX Runtime (.onnx)"]
39
+ Keras["TensorFlow / Keras"]
40
+ JAX["JAX / Flax"]
41
+ end
42
+
43
+ subgraph TaskPipelines ["Task-Specific Evaluators"]
44
+ Cls["Classification\n(Accuracy, Macro-F1, Confusion Matrix)"]
45
+ Calib["Calibration & Reliability\n(ECE, AdaECE, Brier, Temperature)"]
46
+ Unc["Uncertainty & Detection\n(Entropy, Energy, AUROC, AUPRC)"]
47
+ Sel["Selective Prediction\n(Risk-Coverage, AURC)"]
48
+ Rob["Robustness Suite\n(Noise, Blur, Brightness 1-5)"]
49
+ Reg["Regression Suite\n(MAE, RMSE, R², 95% PICP)"]
50
+ Ret["Retrieval Suite\n(Recall@K, MRR, nDCG@K)"]
51
+ Seg["Segmentation Suite\n(mIoU, Dice, Pixel Acc)"]
52
+ Fair["Fairness Suite\n(Demographic Parity, Disparate Impact)"]
53
+ end
54
+
55
+ subgraph StorageReporting ["Storage & Reporting"]
56
+ FSStore["Filesystem Store\n(Atomic Writes & Checksums)"]
57
+ SQLiteStore["SQLite & SQLAlchemy\n(Queryable Registry)"]
58
+ HTMLRep["Interactive HTML Report\n(Zero-Dependency Plotly)"]
59
+ JSONRep["Versioned JSON Schema\n(v1.0 Lineage)"]
60
+ end
61
+
62
+ FrameworkAdapters --> TB
63
+ TB --> TaskPipelines
64
+ TaskPipelines --> StorageReporting
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Installation
70
+
71
+ TrustBench features a lightweight core with optional framework groups:
72
+
73
+ ```bash
74
+ # Core installation (NumPy, SciPy, Scikit-learn, Click, Pydantic)
75
+ pip install trustbench
76
+
77
+ # For PyTorch model evaluation
78
+ pip install "trustbench[pytorch]"
79
+
80
+ # For ONNX Runtime inference
81
+ pip install "trustbench[onnx]"
82
+
83
+ # Full installation (all frameworks, storage, and visualization)
84
+ pip install "trustbench[all]"
85
+ ```
86
+
87
+ See the [Installation Guide](docs/installation.md) for detailed platform requirements.
88
+
89
+ ---
90
+
91
+ ## 5-Minute Quickstart
92
+
93
+ ### 1. Command Line Interface (CLI)
94
+
95
+ ```bash
96
+ # Initialize a starter configuration
97
+ trustbench init
98
+
99
+ # Validate configuration paths and settings
100
+ trustbench validate trustbench.yaml
101
+
102
+ # Run evaluation and generate reports
103
+ trustbench evaluate trustbench.yaml
104
+ ```
105
+
106
+ ### 2. Python API
107
+
108
+ ```python
109
+ import numpy as np
110
+ from sklearn.linear_model import LogisticRegression
111
+ from trustbench import TrustBench, InMemoryDatasetAdapter
112
+
113
+ # 1. Train or load your model
114
+ X_train = np.random.randn(200, 4)
115
+ y_train = np.random.randint(0, 2, size=200)
116
+ clf = LogisticRegression().fit(X_train, y_train)
117
+
118
+ # 2. Prepare test dataset
119
+ X_test = np.random.randn(50, 4)
120
+ y_test = np.random.randint(0, 2, size=50)
121
+ dataset = InMemoryDatasetAdapter(inputs=X_test, labels=y_test)
122
+
123
+ # 3. Evaluate reliability
124
+ bench = TrustBench(model=clf, dataset=dataset)
125
+ result = bench.evaluate()
126
+
127
+ print(f"Accuracy: {result.metrics['classification']['accuracy']:.2%}")
128
+ print(f"Brier Score: {result.metrics['calibration']['brier_score']:.4f}")
129
+ print(f"ECE: {result.metrics['calibration']['ece']:.4f}")
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Multi-Task Evaluation
135
+
136
+ ### Continuous Regression Evaluation
137
+ ```python
138
+ from trustbench import evaluate_regression, InMemoryDatasetAdapter
139
+ from sklearn.linear_model import Ridge
140
+ import numpy as np
141
+
142
+ model = Ridge().fit(X_train, y_train)
143
+ dataset = InMemoryDatasetAdapter(inputs=X_test, labels=y_test)
144
+
145
+ result = evaluate_regression(model, dataset)
146
+ print(f"MAE: {result.metrics['mae']:.3f}")
147
+ print(f"RMSE: {result.metrics['rmse']:.3f}")
148
+ print(f"R²: {result.metrics['r2']:.3f}")
149
+ ```
150
+
151
+ ### Information Retrieval Evaluation
152
+ ```python
153
+ from trustbench import evaluate_retrieval
154
+
155
+ ground_truth = {"q1": ["docA", "docB"], "q2": ["docC"]}
156
+ retrieved = {"q1": ["docA", "docX", "docB"], "q2": ["docY", "docC"]}
157
+
158
+ res = evaluate_retrieval(ground_truth, retrieved, k_list=(1, 3))
159
+ print(f"MRR: {res.metrics['mrr']:.3f}")
160
+ print(f"Recall@1: {res.metrics['recall@1']:.3f}")
161
+ print(f"nDCG@3: {res.metrics['ndcg@3']:.3f}")
162
+ ```
163
+
164
+ ### Semantic Segmentation Evaluation
165
+ ```python
166
+ from trustbench import evaluate_segmentation
167
+
168
+ result = evaluate_segmentation(segmentation_model, segmentation_dataset, num_classes=21)
169
+ print(f"Mean IoU: {result.metrics['miou']:.3f}")
170
+ print(f"Dice (F1): {result.metrics['dice']:.3f}")
171
+ print(f"Pixel Accuracy: {result.metrics['pixel_accuracy']:.2%}")
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Key Metrics Reference
177
+
178
+ | Category | Metrics Implemented |
179
+ |---|---|
180
+ | **Classification** | Accuracy, Balanced Accuracy, Precision, Recall, Macro-F1, Confusion Matrix |
181
+ | **Calibration** | Expected Calibration Error (ECE), Adaptive ECE, Maximum Calibration Error (MCE), Brier Score, NLL |
182
+ | **Uncertainty** | Predictive Shannon Entropy, Maximum Softmax Probability (MSP), Free Energy |
183
+ | **Error Detection** | AUROC, AUPRC, False Positive Rate at 95% TPR (FPR@95%TPR), Minimum Detection Error |
184
+ | **Selective Prediction** | Risk-Coverage Trade-off Curves, Area Under Risk-Coverage (AURC), Excess AURC |
185
+ | **Robustness** | Gaussian Noise, Blur, Brightness, Defocus, Contrast, Corrupted Accuracy Drop |
186
+ | **Regression** | MAE, MSE, RMSE, $R^2$, MedAE, MAPE, Max Error, 95% Interval Coverage (PICP, MPIW) |
187
+ | **Retrieval** | Mean Reciprocal Rank (MRR), Mean Average Precision (MAP), Recall@K, Precision@K, nDCG@K |
188
+ | **Segmentation** | Mean IoU (mIoU), Dice (F1), Pixel Accuracy, Frequency-Weighted IoU (FWIoU) |
189
+ | **Fairness** | Demographic Parity Difference, Disparate Impact Ratio, Equalized Odds Difference |
190
+
191
+ See [Metrics Documentation](docs/metrics.md) for mathematical derivations.
192
+
193
+ ---
194
+
195
+ ## Tutorials & Examples
196
+
197
+ Ready-to-run examples are available in the [`examples/`](examples/) directory:
198
+
199
+ 1. **[01_evaluate_pytorch_model.py](examples/01_evaluate_pytorch_model.py)**: Evaluate custom PyTorch `nn.Module`.
200
+ 2. **[02_evaluate_cifar10.py](examples/02_evaluate_cifar10.py)**: End-to-end CIFAR-10 ResNet evaluation via configuration.
201
+ 3. **[03_robustness_benchmark.py](examples/03_robustness_benchmark.py)**: Evaluate accuracy degradation across noise & corruptions.
202
+ 4. **[04_analyze_calibration.py](examples/04_analyze_calibration.py)**: Compute ECE and fit validation temperature scaling.
203
+ 5. **[05_evaluate_uncertainty.py](examples/05_evaluate_uncertainty.py)**: Predict error detection AUROC and risk-coverage curves.
204
+ 6. **[06_compare_checkpoints.py](examples/06_compare_checkpoints.py)**: Quantify statistical differentials between model checkpoints.
205
+ 7. **[07_save_and_reproduce_experiment.py](examples/07_save_and_reproduce_experiment.py)**: Atomic experiment persistence and checksum verification.
206
+ 8. **[08_create_custom_metric.py](examples/08_create_custom_metric.py)**: Register custom evaluation scoring functions.
207
+ 9. **[09_create_custom_model_adapter.py](examples/09_create_custom_model_adapter.py)**: Implement the runtime `ModelAdapter` protocol.
208
+
209
+ ---
210
+
211
+ ## Documentation
212
+
213
+ Full documentation is available in the [`docs/`](docs/) directory:
214
+ - [Installation Guide](docs/installation.md)
215
+ - [Quickstart Guide](docs/quickstart.md)
216
+ - [Python API Reference](docs/api.md)
217
+ - [CLI Reference](docs/cli.md)
218
+ - [Configuration Guide](docs/configuration.md)
219
+ - [Model Adapters](docs/model-adapters.md)
220
+ - [Dataset Adapters](docs/dataset-adapters.md)
221
+ - [Metrics Documentation](docs/metrics.md)
222
+ - [Robustness Testing](docs/robustness.md)
223
+ - [Experiment Tracking](docs/experiments.md)
224
+ - [Reporting & Visualization](docs/reporting.md)
225
+ - [Plugin Development](docs/plugins.md)
226
+ - [Troubleshooting & FAQ](docs/troubleshooting.md)
227
+
228
+ ---
229
+
230
+ ## Contributing
231
+
232
+ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) and our [Code of Conduct](CODE_OF_CONDUCT.md).
233
+
234
+ ```bash
235
+ # Run tests
236
+ pytest
237
+
238
+ # Check code style
239
+ ruff check .
240
+
241
+ # Static type analysis
242
+ mypy src/trustbench/core src/trustbench/reporting src/trustbench/metrics
243
+ ```
244
+
245
+ ---
246
+
247
+ ## License
248
+
249
+ TrustBench is open-source software licensed under the [Apache License, Version 2.0](LICENSE).
@@ -0,0 +1,82 @@
1
+ [project]
2
+ name = "trustbench"
3
+ version = "0.2.0"
4
+ description = "TrustBench: Evaluation framework for ML model reliability, robustness, and uncertainty."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.11"
8
+ keywords = [
9
+ "machine-learning",
10
+ "evaluation",
11
+ "reliability",
12
+ "robustness",
13
+ "uncertainty",
14
+ "calibration",
15
+ "ood-detection",
16
+ "fairness",
17
+ ]
18
+ classifiers = [
19
+ "Development Status :: 4 - Beta",
20
+ "Intended Audience :: Developers",
21
+ "Intended Audience :: Science/Research",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
26
+ ]
27
+ dependencies = [
28
+ "numpy>=1.24.0",
29
+ "scipy>=1.10.0",
30
+ "scikit-learn>=1.3.0",
31
+ "pydantic>=2.0.0",
32
+ "pyyaml>=6.0",
33
+ "click>=8.1.0",
34
+ "jinja2>=3.1.6",
35
+ "pillow>=10.0.0",
36
+ ]
37
+
38
+ [[project.authors]]
39
+ name = "Uni-Creator"
40
+ email = "abhayr24564@gmail.com"
41
+
42
+ [project.optional-dependencies]
43
+ torch = [
44
+ "torch>=2.0.0",
45
+ "torchvision>=0.15.0",
46
+ ]
47
+ pytorch = [
48
+ "torch>=2.0.0",
49
+ "torchvision>=0.15.0",
50
+ ]
51
+ storage = ["sqlalchemy>=2.0.0"]
52
+ api = [
53
+ "fastapi>=0.100.0",
54
+ "uvicorn[standard]>=0.20.0",
55
+ ]
56
+ reporting = ["plotly>=5.0.0"]
57
+ onnx = ["onnxruntime>=1.16.0"]
58
+ tensorflow = ["tensorflow>=2.15.0"]
59
+ jax = ["jax>=0.4.20"]
60
+ all = ["trustbench[torch,storage,api,reporting,onnx]"]
61
+
62
+ [project.scripts]
63
+ trustbench = "trustbench.cli.main:app"
64
+
65
+ [build-system]
66
+ requires = ["uv_build>=0.12.15,<0.13.0"]
67
+ build-backend = "uv_build"
68
+
69
+ [dependency-groups]
70
+ dev = [
71
+ "httpx>=0.28.1",
72
+ "mypy>=2.4.0",
73
+ "pytest>=9.1.1",
74
+ "ruff>=0.17.2",
75
+ "fastapi>=0.100.0",
76
+ "sqlalchemy>=2.0.0",
77
+ "torch>=2.0.0",
78
+ "torchvision>=0.15.0",
79
+ ]
80
+
81
+ [tool.ruff.lint]
82
+ ignore = ["B008"]