curriculo-tech/onnx-email-gate
07
onnx-email-gate — multilingual KEEP/DROP email prefilter
A tiny multilingual CPU classifier that labels an inbound email KEEP (looks like a real job application → worth further processing) or DROP (junk → skip). It's meant as a cheap pre-filter in front of a more expensive downstream model, discarding obvious junk — newsletters, notifications, one-time codes, job-board alerts, bounces — at roughly a millisecond per email.
- Labels:
{0: DROP, 1: KEEP} - Architecture:
paraphrase-multilingual-MiniLM-L12-v2sentence embedder (mean-pool + L2-normalize) with a logistic-regression head folded into the ONNX graph as a final linear layer — so the whole thing is one classifier ONNX:tokens → 2 logits → argmax. - Quantization: dynamic INT8 (
model_int8.onnx, ~119 MB). - Runtime:
onnxruntimeon CPU, ~ms per email.
Why multilingual
The embedder covers ~50 languages, so the gate reads non-English application emails directly instead of wrong-dropping them (verified on English, Hindi, and Spanish).
Recommended use — an override ladder
The model is best used as the last rung of a cheap rule ladder, so a genuine application is never dropped by the model alone:
- KEEP overrides — résumé attachment / forwarded application / recruiter-style sender → KEEP.
- regex junk — noreply / notifications / OTP / bounce / job-board-alert / newsletter → DROP.
- this model — KEEP/DROP on the remaining ambiguous mail.
Usage
import numpy as np, onnxruntime as ort
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("curriculo-tech/onnx-email-gate")
sess = ort.InferenceSession("model_int8.onnx", providers=["CPUExecutionProvider"])
I2L = {0: "DROP", 1: "KEEP"}
def gate(from_addr, from_name, subject, body):
text = f"{from_addr}\n{from_name}\n{subject}\n{body}"
enc = tok(text, truncation=True, max_length=128, return_tensors="np", padding="max_length")
feed = {"input_ids": enc["input_ids"].astype(np.int64),
"attention_mask": enc["attention_mask"].astype(np.int64)}
logits = sess.run(None, feed)[0][0]
p = int(np.argmax(logits))
sm = np.exp(logits - logits.max()); sm /= sm.sum()
return I2L[p], float(sm[p]) # (label, confidence)Input text = from_address\nfrom_name\nsubject\nbody, truncated to 128 tokens.
Files
Limitations
- The model alone has modest recall — use it behind the override ladder, not standalone.
- Dynamic INT8 shifts a small fraction of borderline predictions vs fp32; ship fp32 if you need exact parity.
- Very low-resource languages may be weaker than the ~50 the embedder covers well.
