Download example.py from Tabloop/tabloop-block-sweep-small: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/Tabloop/tabloop-block-sweep-small/resolve/main/example.py
- Command line
-
hf download hf://Tabloop/tabloop-block-sweep-small/example.py
-
curl -L -o example.py https://huggingface.co/Tabloop/tabloop-block-sweep-small/resolve/main/example.py
1.78 kB
| """Load a block-sweep checkpoint and classify a table with TabLoop's scikit-learn wrapper. | |
| git clone https://github.com/tejasvaidhyadev/Tabloop && git -C Tabloop checkout 8830f27 | |
| PYTHONPATH=Tabloop python example.py --run loop_4x3 --loops 3 | |
| PYTHONPATH=Tabloop python example.py --run base_12x1 # untied models: loops = 1 | |
| PYTHONPATH=Tabloop python example.py --run loop_4x6 --loops 8 --step 100000 | |
| Looped n x k models can be read at any depth k (applications = n * k); untied models run once (k = 1). | |
| """ | |
| import argparse | |
| from huggingface_hub import hf_hub_download | |
| from sklearn.datasets import load_breast_cancer | |
| from sklearn.metrics import accuracy_score, roc_auc_score | |
| from sklearn.model_selection import train_test_split | |
| from tabloop.evaluation.classifier import TabLoopClassifier | |
| FINAL = {"ctrl_1x1": 311100, "ctrl_2x1": 296200, "ctrl_3x1": 282600, "ctrl_4x1": 270200, "ctrl_6x1": 248400} | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--run", default="loop_4x3") | |
| ap.add_argument("--step", type=int, default=None, help="default: the run's final step") | |
| ap.add_argument("--loops", type=int, default=None, help="test-time depth k (default: the run's training-mean k)") | |
| ap.add_argument("--repo", default="tejasvaidhya/tabloop-block-sweep-small") | |
| a = ap.parse_args() | |
| step = a.step or FINAL.get(a.run, 200000) | |
| path = hf_hub_download(a.repo, f"checkpoints/{a.run}/step-{step:06d}.ckpt") | |
| clf = TabLoopClassifier.from_checkpoint(path, loops=a.loops) | |
| X, y = load_breast_cancer(return_X_y=True) | |
| Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.3, random_state=0, stratify=y) | |
| p = clf.fit(Xtr, ytr).predict_proba(Xte)[:, 1] | |
| print(f"{a.run} step {step} k={clf.loops}: accuracy {accuracy_score(yte, p > 0.5):.4f} AUC {roc_auc_score(yte, p):.4f}") | |