Instructions to use Battlettt/smishield with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Battlettt/smishield with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Battlettt/smishield", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
Download README.md from Battlettt/smishield: direct link, hf CLI and curl.
- Browser
- Download file 3.49 kB
-
https://huggingface.co/Battlettt/smishield/resolve/main/README.md
- Command line
-
hf download hf://Battlettt/smishield/README.md
-
curl -L -o README.md https://huggingface.co/Battlettt/smishield/resolve/main/README.md
language: en
library_name: sklearn
pipeline_tag: text-classification
tags:
- sms
- spam-detection
- smishing
- phishing
- tf-idf
- logistic-regression
- explainable-ai
- in-browser
datasets:
- ucirvine/sms_spam
metrics:
- accuracy
- precision
- recall
- f1
model-index:
- name: smishield
results:
- task:
type: text-classification
name: SMS spam / smishing detection
dataset:
name: SMS Spam Collection v.1 (held-out 20% stratified split, seed 42)
type: ucirvine/sms_spam
metrics:
- type: accuracy
value: 0.9901
- type: precision
value: 0.9792
- type: recall
value: 0.9463
- type: f1
value: 0.9625
smishield
A small, explainable SMS smishing and spam classifier built to run entirely in the browser. The whole model is one 140 KB JSON file (model.json). Plain TypeScript scores messages on the device, so no text ever leaves the user's tab.
- Live demo: Space: Battlettt/smishield
- Source and tests: github.com/battlettt/smishield
Results
Evaluated on a held-out, stratified 20% test split (1,115 messages: 966 legitimate, 149 spam) of the SMS Spam Collection.
| Metric | Value |
|---|---|
| Accuracy | 0.9901 |
| Precision (spam) | 0.9792 |
| Recall (spam) | 0.9463 |
| F1 (spam) | 0.9625 |
| Predicted legitimate | Predicted spam | |
|---|---|---|
| Actually legitimate | 963 | 3 |
| Actually spam | 8 | 141 |
Full numbers: metrics.json.
How it works
- Tokenizer. Lowercase, split on
[a-z0-9]+. URLs, shortened links, currency amounts and long numbers become special tokens. - TF-IDF. Word unigrams and bigrams, sublinear term frequency, smoothed IDF, L2 norm. Vocabulary capped at 3,000 terms (min document frequency 2).
- Logistic regression. scikit-learn 1.9.1,
liblinear, balanced class weights.C = 10, picked by 5-fold cross-validated F1 (0.9624) on the training split only. - Export.
train.pywrites vocabulary, IDF values, coefficients, intercept and threshold tomodel.json. - Scoring.
P(spam) = sigmoid(intercept + sum(tfidf_i * coef_i)), flagged at 0.5. Each verdict lists the words that pushed the score most, plus pattern-based warning signs (shortened links, urgency, prize wording).
A parity test in the GitHub repo checks that the TypeScript scorer reproduces scikit-learn's tokens and probabilities on 100 held-out messages.
Use it
model.json holds everything needed to score a message: vocabulary, IDF values, coefficients, intercept and threshold. The tokenizer is in train.py (Python) and mirrored in src/tokenizer.ts in the GitHub repo.
To retrain: pip install scikit-learn && python train.py (downloads the dataset from UCI).
Limitations
- 2012-era data. The dataset was collected around 2011-2012, mostly from UK and Singapore. Its spam is mostly premium-rate prize, ringtone and dating texts. Modern smishing (parcel fees, bank and toll alerts) looks different, so real-world accuracy will be lower than the table above.
- English only.
- A learning and demo project. It does not replace carrier spam filtering, and "likely legitimate" is not a safety guarantee.
Data
SMS Spam Collection v.1, Almeida and Gomez Hidalgo, UCI Machine Learning Repository (CC BY 4.0). 5,574 messages: 4,827 ham, 747 spam.