Text Classification
Transformers
Safetensors
distilbert
email
spam-detection
text-embeddings-inference
Instructions to use akumar0205/phishing_spam_jev_like_classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use akumar0205/phishing_spam_jev_like_classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="akumar0205/phishing_spam_jev_like_classifier")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("akumar0205/phishing_spam_jev_like_classifier") model = AutoModelForSequenceClassification.from_pretrained("akumar0205/phishing_spam_jev_like_classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download inference.py from akumar0205/phishing_spam_jev_like_classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/akumar0205/phishing_spam_jev_like_classifier/resolve/main/inference.py
- Command line
-
hf download hf://akumar0205/phishing_spam_jev_like_classifier/inference.py
-
curl -L -o inference.py https://huggingface.co/akumar0205/phishing_spam_jev_like_classifier/resolve/main/inference.py
1.96 kB
| """Standalone inference for the DistilBERT email-triage model (see module docstring).""" | |
| INPUT_FORMAT = ("Subject: ...\nFrom: ***@domain\nReply-To: ...\nBody: ...\nURLs: ... " | |
| "(§4 normalize_row + PII redaction; truncated at max_length)") | |
| import json, os | |
| import numpy as np | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| MODEL_DIR = os.environ.get('JEV_MODEL_DIR', os.path.dirname(os.path.abspath(__file__))) | |
| with open(os.path.join(MODEL_DIR, 'label_map.json')) as _f: | |
| _LM = json.load(_f) | |
| LABELS = _LM['labels'] | |
| ACTION = {'legitimate': 'allow', 'spam': 'filter_to_spam', | |
| 'phishing': 'quarantine_or_review', 'malware': 'quarantine_or_review'} | |
| _THRESHOLD = float(_LM.get('review_threshold', 0.55)) | |
| _MAX = int(_LM.get('max_length', 512)) | |
| _tok = AutoTokenizer.from_pretrained(MODEL_DIR) | |
| _model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR).eval() | |
| def predict(texts, threshold=_THRESHOLD, batch_size=16): | |
| outs, all_p = [], [] | |
| for i in range(0, len(texts), batch_size): | |
| t = _tok(list(texts[i:i + batch_size]), truncation=True, padding=True, | |
| max_length=_MAX, return_tensors='pt') | |
| all_p.append(torch.softmax(_model(**t).logits, -1).cpu().numpy()) | |
| import numpy as _np | |
| P = _np.concatenate(all_p) if all_p else _np.zeros((0, len(LABELS))) | |
| for t, p in zip(texts, P): | |
| scores = {l: float(p[LABELS.index(l)]) for l in LABELS} | |
| top = LABELS[int(p.argmax())] | |
| if not str(t).strip() or float(p.max()) < threshold: | |
| outs.append({'label': 'review', 'scores': scores, 'action': 'review'}) | |
| else: | |
| outs.append({'label': top, 'scores': scores, 'action': ACTION[top]}) | |
| return outs | |
| if __name__ == '__main__': | |
| demo = ['Subject: Meeting moved to 2 PM\nFrom: \nReply-To: \nBody: See the calendar invite.\nURLs: ', ''] | |
| print(json.dumps(predict(demo), indent=2)) | |