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.

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

  1. Tokenizer. Lowercase, split on [a-z0-9]+. URLs, shortened links, currency amounts and long numbers become special tokens.
  2. TF-IDF. Word unigrams and bigrams, sublinear term frequency, smoothed IDF, L2 norm. Vocabulary capped at 3,000 terms (min document frequency 2).
  3. 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.
  4. Export. train.py writes vocabulary, IDF values, coefficients, intercept and threshold to model.json.
  5. 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.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Dataset used to train Battlettt/smishield

Space using Battlettt/smishield 1

Evaluation results

  • accuracy on SMS Spam Collection v.1 (held-out 20% stratified split, seed 42)
    self-reported
    0.990
  • precision on SMS Spam Collection v.1 (held-out 20% stratified split, seed 42)
    self-reported
    0.979
  • recall on SMS Spam Collection v.1 (held-out 20% stratified split, seed 42)
    self-reported
    0.946
  • f1 on SMS Spam Collection v.1 (held-out 20% stratified split, seed 42)
    self-reported
    0.963