Views
No views yet
ham or spam, and gives you a probability in case you would like to set your own threshold.1import sys, joblib
2from huggingface_hub import snapshot_download
3
4repo = snapshot_download("jngb-labs/sms-spam-classical")
5sys.path.insert(0, f"{repo}/src")
6import features # required for unpickling
7
8bundle = joblib.load(f"{repo}/model/classifier.joblib")
9clf = bundle["pipeline"]
10
11clf.predict(["FREE entry to win £1000! Text WIN to 87121"])
12# array([1]) # 1 = spam
13
14clf.predict_proba(["FREE entry to win £1000! Text WIN to 87121"])
15# array([[0.000..., 0.999...]]) # [P(ham), P(spam)]| Metric | Mean | Std |
|---|---|---|
| Accuracy | 0.9888 | 0.0055 |
| Spam F1 | 0.9536 | 0.0231 |
| Spam precision | 0.9772 | 0.0215 |
| Spam recall | 0.9315 | 0.0298 |
FeatureUnion over three feature blocks. Word TF-IDF, unigrams and bigrams, sublinear-scaled. Character TF-IDF, three to five character windows with char_wb (so n-grams respect word boundaries). Hand-crafted surface features: length, digit ratio, uppercase ratio, punctuation density, presence of URLs, presence of phone numbers, presence of currency symbols, exclamation count. Spam, visually, looks different from ham, and a few engineered features capture that.LinearSVC with balanced class weights (the dataset is roughly 88 percent ham), wrapped in a CalibratedClassifierCV so you get probabilities instead of bare decision scores.max_df=0.95 plus IDF weighting handles common-word suppression more carefully than sklearn's default English stop list, which would happily discard "call". In the context of SMS spam, "call" does a lot of work.import joblib.ham, because nothing quite like it appears in the training data. If you are deploying against contemporary attacks, retrain on contemporary data.jngb-labs/sms-spam. 5,159 messages, 87.6 percent ham, 12.4 percent spam, originally assembled by Almeida and Gómez Hidalgo. Full data card at the dataset link.jngb-labs/sms-spam-distilbert, DistilBERT fine-tuned on the same dataset.jngb-labs/sms-spam-classifier, a Hugging Face Space that runs this classifier on any SMS you type.1git clone https://huggingface.co/jngb-labs/sms-spam-classical
2cd sms-spam-classical
3pip install -r requirements.txt
4python scripts/train.py \
5 --data /path/to/jngb-labs/sms-spam/data.csv \
6 --out model/classifier.joblib \
7 --report model/cv_report.json1@inproceedings{Almeida2011SMSSpam,
2 author = {Tiago A. Almeida and Jos\'{e} Mar\'{i}a G\'{o}mez Hidalgo and Akebo Yamakami},
3 title = {Contributions to the study of {SMS} spam filtering: new collection and results},
4 booktitle = {Proceedings of the 2011 ACM Symposium on Document Engineering},
5 year = {2011},
6}