Digits certified robustness #
Certified accuracy for a linear classifier on sklearn's digits dataset.
Workflow:
- Train a small linear classifier on sklearn's digits (8x8) in Python and export:
- weights JSON (
digits_linear_weights.json) - test dataset JSON (
digits_test.json)
- weights JSON (
- In Lean, load the weights + dataset and compute certified accuracy under an
ℓ∞input box using:- IBP (
runIBP) - a simple CROWN/affine pass (
runAffine+AffineVec.eval_on_box)
- IBP (
Run:
lake exe verify -- digits
lake exe verify -- digits --eps=0.02 --max=360
lake exe verify -- digits --float32-mode ieee754exec --eps=0.02
lake exe verify -- digits-train-certify --epochs=50 --eps=0.02 --max=100
Regenerate assets:
python3 scripts/verification/robustness/train_digits_linear.py
Flattened input dimension for sklearn digits (8×8).
Instances For
Weight shape for a linear classifier y = Wx + b (10×64).
Instances For
Bias shape for a linear classifier (10).
Instances For
Parameter shapes list used by the compiled TorchLean program ([W, b]).
Instances For
Bundled sklearn-digits linear classifier weights.
Instances For
Bundled sklearn-digits test set.
Instances For
Python exporter used by the train-then-certify command.
Instances For
Instances For
Options for the train → compile → certify report command.
- certify : DigitsOpts
Lean-side certification options after Python exports the model and dataset.
- script : String
Python trainer script path.
- seed : ℕ
Reproducibility seed forwarded to the trainer.
- epochs : ℕ
Number of Python training epochs.
- batch : ℕ
Python trainer batch size.
- lr : Float
Python trainer learning rate.
- testSize : Float
Test split fraction used by the trainer.
- maxTest : ℕ
Number of test examples exported by the trainer.
Instances For
Instances For
Usage string printed on --help / -h.
Instances For
Parse CLI args into DigitsOpts (returns usage as the error message on --help).
Instances For
Parse the combined trainer/certifier CLI for digits-train-certify.
Instances For
Trainer command-line arguments generated from TrainCertifyOpts.
Instances For
TorchLean program for the linear classifier y = Wx + b.
Instances For
Load linear classifier weights exported from PyTorch into a typed LinearSpec.
Instances For
Load the digits test dataset exported from Python (JSON).
Instances For
Running counters for the digits certified-accuracy workflow.
- total : ℕ
Number of examples checked.
- nominalOk : ℕ
Number of clean examples classified correctly by the exported model.
- ibpOk : ℕ
Number of examples certified by interval bound propagation.
- crownOk : ℕ
Number of examples certified by the affine CROWN pass.
Instances For
Instances For
Run the certified-accuracy evaluation once, under a chosen scalar backend α.
This compiles the linear classifier to the verifier IR, then checks each example's L∞ box using
IBP and a simple affine pass.
Instances For
Train a fresh digits classifier, compile it through the TorchLean verifier path, and certify it.
The Python trainer is an artifact producer only. Lean still parses the exported JSON, compiles the TorchLean program to verifier IR, runs IBP and affine CROWN bounds, and prints the certification report from the checked artifacts.