smishield / README.md
Battlettt's picture
Publish smishield from github.com/battlettt/smishield
13748f0 verified
|
Raw History Blame Contribute Delete
3.49 kB
metadata
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.

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.