Download .deploy-test-pytorch.py from sitcod3/modul-x: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/sitcod3/modul-x/resolve/main/.deploy-test-pytorch.py
- Command line
-
hf download hf://spaces/sitcod3/modul-x/.deploy-test-pytorch.py
-
curl -L -o .deploy-test-pytorch.py https://huggingface.co/spaces/sitcod3/modul-x/resolve/main/.deploy-test-pytorch.py
1.24 kB
| """Disambiguate: is the fine-tuned PyTorch model good, and only the ONNX | |
| export broken? Run the checkpoint directly through transformers.""" | |
| import sys | |
| from pathlib import Path | |
| CKPT = Path(__file__).resolve().parent / "app" / "ml" / "runs" / "checkpoint-172" | |
| from transformers import AutoTokenizer, pipeline # noqa: E402 | |
| tok = AutoTokenizer.from_pretrained("distilbert-base-uncased") | |
| clf = pipeline("text-classification", model=str(CKPT), tokenizer=tok, | |
| device="cpu", truncation=True, max_length=64) | |
| CASES = [ | |
| ("user [SEP] mailinator.com", "DISPOSABLE"), | |
| ("someone [SEP] 10minutemail.com", "DISPOSABLE"), | |
| ("someone [SEP] temp-mail-pro.xyz", "DISPOSABLE", ), | |
| ("someone [SEP] disposable-inbox-2024.top", "DISPOSABLE"), | |
| ("john.smith [SEP] gmail.com", "NORMAL"), | |
| ("maria.garcia [SEP] harborview-law.test", "NORMAL"), | |
| ("info [SEP] acme-corp.com", "ROLE"), | |
| ] | |
| wrong = 0 | |
| for text, expected in CASES: | |
| r = clf(text)[0] | |
| label, score = r["label"], r["score"] | |
| ok = label == expected | |
| wrong += 0 if ok else 1 | |
| print(f"{'OK ' if ok else 'WRONG'} {text:52} -> {label:10} {score:.3f}") | |
| print(f"\n{len(CASES)-wrong}/{len(CASES)} correct (PyTorch checkpoint)") | |
| sys.exit(1 if wrong else 0) |