Text Classification
Transformers
Safetensors
PyTorch
ml-lab
spam-detection
distilbert
Eval Results (legacy)
Instructions to use shalev396/email-spam-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shalev396/email-spam-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="shalev396/email-spam-classifier")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shalev396/email-spam-classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from shalev396/email-spam-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/shalev396/email-spam-classifier/resolve/main/handler.py
- Command line
-
hf download hf://shalev396/email-spam-classifier/handler.py
-
curl -L -o handler.py https://huggingface.co/shalev396/email-spam-classifier/resolve/main/handler.py
1.07 kB
| """Hugging Face Inference Endpoints entry point — deploy this repo as a CPU/GPU API. | |
| Request: {"inputs": "Subject: <subject>\n\n<body>"} -> {"spam": p, "ham": 1 - p} | |
| {"inputs": ["Subject: ...", "Subject: ..."]} -> [{"spam": p, "ham": 1 - p}, ...] | |
| """ | |
| import sys | |
| from pathlib import Path | |
| HERE = Path(__file__).resolve().parent | |
| sys.path.insert(0, str(HERE)) | |
| import model as M # noqa: E402 | |
| class EndpointHandler: | |
| def __init__(self, path: str = ""): | |
| self.predictor = M.load(path or HERE, "cuda" if M.cuda_available() else "cpu") | |
| def __call__(self, data: dict): | |
| inputs = data.pop("inputs", data) | |
| if isinstance(inputs, dict): # {"subject": ..., "body": ...} | |
| inputs = M.compose_email(inputs.get("subject", ""), inputs.get("body", inputs.get("text", ""))) | |
| if isinstance(inputs, (list, tuple)): | |
| probs = self.predictor.predict_proba([str(t) for t in inputs]) | |
| return [{"spam": p, "ham": 1.0 - p} for p in probs] | |
| return self.predictor.predict(str(inputs)) | |