EmbeddingGemma 2 scam classifier (Core ML int8)

An on-device classifier that scores how likely an incoming message, or a short conversation, is a scam. It is a fine-tuned EmbeddingGemma 2 text encoder with a linear head and Platt calibration, converted to Core ML with int8 weights. It runs on the iPhone CPU in about 0.05 s per message.

This is the conversation judge of NotificationScan, an iOS proof of concept. iOS Shortcuts hand each incoming message (SMS, iMessage, LINE, and others) to the app, the app scores it on the device, and it alerts the user in the Dynamic Island only when the risk is high. Message text never leaves the phone.

Status: proof of concept. The thresholds have not been validated on real traffic yet; the app runs in shadow mode (scores are logged on the device, no alerts are shown) until they are.

Files

The repo is laid out for the app's downloader: manifest.json lists every file with its URL, SHA-256 and size, and the app verifies each file before using it.

Path What it is
manifest.json Download manifest (notificationscan-model-manifest-v2)
ftv3-int8-multi-1d236afa/EmbGemma2FT.mlmodelc/ Compiled Core ML model (about 277 MB of int8 weights)
ftv3-int8-multi-1d236afa/tokenizer.json, tokenizer_config.json Gemma tokenizer
ftv3-int8-multi-1d236afa/egemma_thresholds.json Alert thresholds per language and unit (see below)
ftv3-int8-multi-1d236afa/NOTICE.txt Attribution for the base model and the training data

How to use

The model is a multifunction Core ML program. The three functions share the same weights and differ only in the fixed input length: L128, L512, L1024. Pick the smallest one that fits the tokenized text.

Input

  1. Prepend the EmbeddingGemma classification prompt: task: classification | query:
  2. For a single message, use the message text. For a conversation, use the most recent incoming messages (up to 10), oldest first, joined with newlines.
  3. Tokenize with the bundled tokenizer, pad to the function's length, and pass input_ids and attention_mask (Int32, shape [1, L]).

Output

Name Shape Meaning
p_message [1] Calibrated scam probability when the input is a single message
p_conversation [1] Calibrated scam probability when the input is a conversation
logit [1] Raw head output before calibration
embedding [1, 768] Pooled, normalized text embedding

Run it on the CPU (MLComputeUnits.cpuOnly). With float16 on the Neural Engine the outputs drift too far from the reference (cosine similarity about 0.89).

Thresholds. egemma_thresholds.json gives four cut-offs for each language (ja, zh, en) and unit (message, conversation):

Key Chosen at real-ham false-positive rate
monitor 1% (log silently, no alert)
alertBalanced 0.3%
alert 0.1% (default alert)
trustedAlert 0.01% (sender the user marked as trusted)

The scores are not comparable across languages: the Japanese alert threshold is about 0.05 and the Chinese one is about 0.96. Always use the per-language values.

Training

  • Base model: google/embeddinggemma-2, revision f9972ac22e696a105c482202646979e33e4b5a1e.
  • Method: fine-tuned the last 4 encoder layers together with a 768 β†’ 1 linear head on single messages and conversation windows, with dev-set early stopping, then fitted Platt calibration on the dev set. Learning rate 2e-5 (encoder) and 1e-3 (head), batch size 16, 5% warmup plus cosine decay, messages up to 256 tokens and windows up to 1024 tokens.
  • Conversion: Core ML multifunction program, int8 weight quantization, minimum iOS 18. The int8 scores differ from the PyTorch scores by up to 0.14 on a few samples, so the thresholds were set on the int8 scores computed in Swift, not on PyTorch scores.

Training data

Source Language Kind License
Cofacts LINE messages zh-TW real, weak labels from topic tags CC BY-SA 4.0
UCI SMS Spam Collection en real CC BY 4.0
Smishing-Dataset-IMC25 en, ja, zh real, scams only CC BY 4.0
RealPersonaChat ja real, everyday chat only CC BY-SA 4.0
paulkm/chinese_conversation_and_spam zh (converted to Traditional) real, normal messages only Apache-2.0
ScamBench ja, zh, en synthetic CC BY-SA 4.0
BothBosu scam dialogues, multi-agent en synthetic Apache-2.0
Mendeley SMS phishing (vmg875v4xs) en synthetic CC BY 4.0
Project-generated scams and hard negatives (bank OTP, delivery and other look-alike legitimate notices) ja, zh-TW, en synthetic, written with an LLM; zh-TW seeded from data.gov.tw open data β€”

All held-out splits are disjoint from training. Cofacts is split by message prefix, so that near-duplicate forwards of the same message stay on one side of the split.

Evaluation

Held-out test half (the other half was used to pick thresholds). Recall is measured on scam messages; the false-positive rate is measured on real normal messages only. Synthetic normal messages are not used for false-positive rates.

Language, unit Real scams Real normal AUC (real) Recall at 1% FPR Recall at 0.1% FPR
ja, message 38 14,204 0.999 1.00 0.84
zh, message 2,232 5,149 0.980 0.75 0.44
en, message 2,121 912 0.994 0.93 0.87 †
ja, conversation β€” (synthetic 103) 400 β€” 1.00 (synthetic) 0.83 (synthetic) †

† Not enough real normal samples to measure that FPR precisely.

zh and en conversations have no real normal conversations, so their thresholds are derived from the message thresholds. The zh normal set includes forwarded rumours, news and genuine anti-fraud notices, which is why the zh thresholds are strict and the zh recall is lower.

On an iPhone 15 Pro, CPU only:

Metric Value
Latency per message about 0.05 s (128 tokens), 0.19 s (512 tokens)
Load time, background cold start 2.8 s (L128), 9.0 s (L512)
Peak memory footprint about 85–100 MB (weights are memory-mapped)

Limitations

  • Weak labels. Most real Chinese scam labels come from Cofacts topic tags. A manual sample put them at about 85–90% correct.
  • Missing kinds of normal messages. There is little real normal text of the bank, delivery or one-time-password kind, which is exactly what scams imitate.
  • Thresholds unverified. They have not been checked on real traffic, and the Japanese conversation alert threshold rests on very few real chats.
  • No scam category. The model gives a probability only. In the app, the category comes from rules.
  • Not a sole safeguard. It can miss scams and can flag legitimate messages. Don't use it to block messages or to make decisions about people without human review.

License and attribution

  • Base model: EmbeddingGemma 2, Copyright Google LLC, Apache License 2.0.
  • This model: released under CC BY-SA 4.0 because the training data includes CC BY-SA material. Whether trained weights are a derivative work of that data is not settled.
  • Cofacts attribution, required: ζœ¬η·¨θΌ―θ³‡ζ–™ε–θ‡ͺγ€ŒCofacts ηœŸηš„ε‡ηš„γ€θ¨Šζ―ε›žε ±ζ©Ÿε™¨δΊΊθˆ‡ζŸ₯θ­‰ε”δ½œη€ΎηΎ€οΌŒζŽ‘ CC BY-SA 4.0 ζŽˆζ¬ŠζδΎ›γ€‚θ‹₯ζ¬²θ£œε……θ³‡θ¨Šθ«‹θ¨ͺ問 Cofacts LINE bot https://line.me/ti/p/@cofacts
  • Other datasets: see the table above. Full notices are in NOTICE.txt.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for LuionTW/embeddinggemma2-finetune

Finetuned
(193)
this model