A small, local, non-generative multi-label classifier that reads a short chat between a minor ([CHILD]) and someone else ([OTHER]) and estimates the risk of grooming, sexual harassment, sextortion, bullying, threats, violence, self-harm, scams and more.
It also flags behavioural signals, such as asking for the child's age, school or photos, or for secrecy, and returns a severity level. It is built for Italian chats, including slang and emoji, plus some English slang. The INT8 model is 33.7 MB and runs in about 4.5 ms per conversation on a laptop CPU.
🇮🇹 In breve — Classificatore locale (non generativo) per la sicurezza dei minori nelle chat in italiano. Riconosce grooming, molestie sessuali, sextortion, bullismo, minacce, violenza, autolesionismo e truffe. Segnala anche comportamenti sospetti come chiedere età, scuola, foto o segretezza e restituisce un livello di gravità. Tiene conto di slang ed emoji: "ti ammazzo 😂😂😂" non è uguale a "ti ammazzo 🔪". La versione INT8 pesa 34 MB e gira sul telefono, senza inviare i messaggi a nessun server.
⚠️ Research proof of concept. It was trained on synthetic data only and has not been validated on real conversations or with child-protection professionals. Use it as one signal to support human judgement, never as the only basis for decisions about a child. See Limitations.
v2/ folder)V2.1 is the model now in v2/. It uses the same MiniLM architecture, vocabulary and training recipe as V1, and reads the last 24 messages (V1: 12) with up to 256 tokens. The files at the repo root are still V1, unchanged.
Every record keeps its generator in its metadata. The previous V2 weights are still in this repo's commit history.
Results on FSBench V2, a separate robustness benchmark of 3k conversations that is never used for training. The scores are macro-F1 over risk labels for the INT8 model, with thresholds tuned on validation only.
| Set | V1 | V2 | V2.1 (published) |
|---|---|---|---|
| explicit | 0.608 | 0.682 | 0.644 |
| implicit | 0.407 | 0.447 | 0.468 |
| youth language | 0.794 | 0.883 | 0.877 |
| typos | 0.668 | 0.706 | 0.759 |
| emoji | 0.700 | 0.804 | 0.778 |
| slang | 0.648 | 0.733 | 0.716 |
| multi-turn (13–48 msgs) | 0.756 | 0.878 | 0.860 |
| adversarial | 0.474 | 0.496 | 0.526 |
| context dependency | 0.470 | 0.468 | 0.472 |
| mixed noise | 0.425 | 0.512 | 0.516 |
| invariance | 0.684 | 0.714 | 0.744 |
| mean macro-F1 | 0.603 | 0.666 | 0.669 |
| mean false-positive rate | 0.088 | 0.056 | 0.058 |
| mean false-negative rate | 0.136 | 0.110 | 0.096 |
Compared with V2, V2.1 misses fewer risks:
| Risk recall | V2 | V2.1 |
|---|---|---|
| grooming | 0.79 | 0.87 |
| violence | 0.76 | 0.92 |
| self-harm | 0.67 | 0.71 |
On 39 held-out hand-written chats with typos, abbreviations and youth slang, V1 gets 34 right, V2 31 and V2.1 34.
Known weak spots:
The full per-set table, with FPR and FNR, is in v2/benchmark_fsbench_v2.md.
from huggingface_hub import snapshot_download
d = snapshot_download("markuz89/family-safety-ai-it", allow_patterns=["v2/*"]) + "/v2"
# then: python predict_onnx.py inside d (it reads max_messages=24 from onnx/model_info.json)
🇮🇹 V2.1 (cartella
v2/). Stesso modello e stessa ricetta di V1, riaddestrato con 5.1k conversazioni nuove sui punti deboli di V1, più 369 conversazioni scritte apposta per correggere i falsi allarmi trovati provando la V2 a mano. Per esempio, "non ce la faccio più" detto per i compiti o l'allenamento veniva preso per autolesionismo. Legge gli ultimi 24 messaggi invece di 12.Su FSBench V2 il macro-F1 medio passa da 0.60 (V1) a 0.67. I falsi allarmi scendono dall'8.8% al 5.8% e i rischi mancati dal 13.6% al 9.6%. Restano deboli i rischi impliciti, soprattutto l'autolesionismo detto tra le righe.
Si può provare nella pagina di test scegliendo "V2.1".
{
"risks": {"grooming": 0.992, "sexual_harassment": 0.979, "safe": 0.002, "...": 0.0},
"signals": {"asks_age": 1.0, "asks_photo": 1.0, "asks_secrecy": 1.0, "...": 0.0},
"detected_risks": ["sexual_harassment", "grooming"],
"detected_signals": ["asks_age", "asks_photo", "asks_secrecy"],
"severity": "critical"
}
| Group | Labels |
|---|---|
Risk categories (13 + safe) |
bullying harassment violence threat racism discrimination sexual_content sexual_harassment grooming coercion blackmail self_harm scam · safe |
| Signals (9) | asks_age asks_location asks_school asks_photo asks_nude asks_secrecy requests_meeting threatens_disclosure repeated_insults |
| Severity | safe · low · medium · high · critical |
All 23 outputs are independent sigmoids, so this is multi-label. Each label has its own tuned threshold, stored in thresholds.json. The four labels where missing a case is most costly (grooming, violence, sexual_harassment, self_harm) were tuned for recall ≥ 0.9.
Severity is a deterministic rule applied on top of the detected labels, so you can change it without retraining:
grooming, blackmail or self_harm, or at least two of {sexual_harassment, threat, violence, coercion}sexual_harassment, threat, violence, coercion}bullying, harassment, racism, discrimination, sexual_content or scamasks_nude, threatens_disclosure or repeated_insults, or at least two contact signals (age, location, school, photo, secrecy, meeting)Signals on their own are not risks. "Quanti anni hai?" from a classmate is asks_age with severity safe. Signals become meaningful in combination, and the risk heads learn those combinations from context.
The model reads the last 12 messages as one line, with a speaker token before each message. Emoji are kept and carry meaning:
[OTHER] quanti anni hai? [CHILD] 13 [OTHER] mandami una foto 😏 [OTHER] non dirlo ai tuoi
The maximum length is 160 tokens. If the conversation is longer, the oldest tokens are dropped (left truncation), so the most recent messages are always kept.
pip install onnxruntime tokenizers numpy huggingface_hub
from huggingface_hub import snapshot_download
import sys
path = snapshot_download("markuz89/family-safety-ai-it", allow_patterns=["onnx/*", "predict_onnx.py"])
sys.path.insert(0, path)
from predict_onnx import SafetyModel
model = SafetyModel(f"{path}/onnx") # loads model.int8.onnx by default
print(model([
{"speaker": "other", "text": "quanti anni hai?"},
{"speaker": "child", "text": "13"},
{"speaker": "other", "text": "mandami una foto 😏"},
{"speaker": "other", "text": "non dirlo ai tuoi"},
]))
predict_onnx.py is about 100 lines with no other dependencies: formatting, left truncation, thresholds and the severity rule. You can port it as-is to Kotlin or Swift. The ONNX graph takes input_ids and attention_mask (int64, [batch, seq]) and returns probs (float32, [batch, 23]) with the sigmoid already applied.
| Conversation | Prediction |
|---|---|
| O: quanti anni hai? / C: 13 / O: anche mia sorella ha 13 anni | safe · signals: asks_age |
| O: mandami una foto / C: del compito? / O: sì | safe · signals: asks_photo |
| O: non dirlo a mamma è una sorpresa / C: ok!! 🎂 | safe · signals: asks_secrecy |
| C: ho sbagliato il rigore 😭 / O: sei scemo 😂 / C: ahah zitto tu | safe |
| O: ti ammazzo 😂😂😂 | safe |
| O: ti ammazzo 🔪 | critical · violence, threat |
| O: sei scemo 🖕 | medium · harassment |
| O: ciccione 😂 / O: nessuno ti vuole qui / O: sparisci sfigato / C: perché fate così | medium · bullying, harassment · repeated_insults |
| O: quanti anni hai? / C: 13 / O: mandami una foto 😏 / O: non dirlo ai tuoi | critical · grooming, sexual_harassment · asks_age, asks_photo, asks_secrecy |
| O: send me a pic without ur shirt 😏 / C: no / O: send it or i show everyone the other one | critical · sexual_harassment, coercion, blackmail · asks_nude, threatens_disclosure |
| C: non ce la faccio più / C: vorrei sparire per sempre 💔 | critical · self_harm |
| O: hai vinto un buono Amazon da 500€! 🎁 clicca il link e inserisci i dati della carta | medium · scam |
| Path | What | Size |
|---|---|---|
onnx/model.int8.onnx |
Recommended. MiniLM, dynamic INT8 quantization | 33.7 MB |
onnx/model.onnx |
MiniLM, FP32 | 133 MB |
onnx/tokenizer/, labels.json, thresholds.json, model_info.json |
everything needed at inference time | |
pytorch/ |
MiniLM PyTorch weights (encoder/ + head.pt), for fine-tuning |
133 MB |
xlmr-base/onnx/model.onnx |
XLM-R-base variant, FP32 ONNX, more accurate (server or desktop) | 427 MB |
xlmr-base/pytorch/ |
XLM-R-base PyTorch weights | 429 MB |
predict_onnx.py |
standalone reference inference | |
v2/onnx/model.int8.onnx |
V2.1, MiniLM INT8 (24 messages / 256 tokens) | 33.7 MB |
v2/onnx/model.onnx, v2/pytorch/ |
V2.1 FP32 ONNX and PyTorch weights | 133 MB each |
v2/predict_onnx.py |
inference script that reads the message window from model_info.json (works for V1 too) |
|
v2/benchmark_fsbench_v2.md |
FSBench V2: V1 vs V2 vs V2.1 per set |
paraphrase-multilingual-MiniLM-L12-v2 (12 layers, hidden size 384).[CHILD] and [OTHER], plus 15 emoji missing from the original vocabulary (🔪 🩸 🪓 🖕 🤬 🤫 🤐 🥵 🫦 🥺 🤢 🤮 💩 🫠 🫣). Their embeddings start from the embedding of a short text description.XLM-R-base variant: same recipe on xlm-roberta-base (pruned to 112.4M parameters). It is more accurate in FP32 but loses more quality under INT8 (macro F1 0.882 → 0.84). On a phone, the MiniLM INT8 model is the better choice.
The dataset has 36.5k synthetic conversations (31.7k for training), about 85% Italian and 15% English, with 1–12 messages each.
The data is split by generation call, so near-duplicate conversations from the same call never end up in both train and test. Template phrases in the test set never appear in training.
The dataset is not released, because it contains synthetic depictions of grooming and sextortion.
Training: MiniLM ran 10 epochs (lr 6e-5, batch 64, bf16) and XLM-R ran 6 epochs (lr 3e-5, batch 32) on one RTX 4090. MiniLM took about 3 minutes and XLM-R about 4. The best epoch on validation was kept, then per-label thresholds were tuned on validation.
Results use the tuned thresholds and test data never seen in training:
| Model | Size | LLM test macro-F1 | Hard test macro-F1 | Hard test FPR | Hard test FNR | Latency* |
|---|---|---|---|---|---|---|
| MiniLM INT8 (recommended) | 33.7 MB | 0.863† | 0.845 | 0.0% | 8.1% | 4.5 ms |
| MiniLM FP32 | 133 MB | 0.867 | 0.822 | 0.0% | 8.1% | 10.6 ms |
| XLM-R-base FP32 | 427 MB | 0.879 | 0.843 | 6.2% | 3.2% | 35 ms |
| XLM-R-base INT8 | 108 MB | 0.84† | 0.837 | – | – | 12.5 ms |
| v1 baseline (template data only, FP32) | 449 MB | 0.43‡ | 0.762 | 16.2% | 9.3% | 10.9 ms |
* ONNX Runtime, one conversation, 4 threads on an Intel i7-1355U laptop CPU. Peak process RAM for MiniLM INT8 is about 95 MB above the runtime itself.
† Measured on the full mixed test set (LLM and template conversations together).
‡ Measured on an earlier pilot set of LLM conversations; v1 was trained only on templates and did not generalise to them.
FPR and FNR are "any risk" rates: FPR is the share of safe conversations that get at least one risk label, and FNR is the share of risky conversations that get none.
Recall on critical categories (MiniLM, LLM test): grooming 0.98 · sexual_harassment 0.98 · self_harm 0.98 · violence 0.93. ROC-AUC (macro over risks, full test) is 0.98.
Per-label metrics (MiniLM FP32, full test, n = 2,725)| label | precision | recall | F1 | F1 (XLM-R) | support |
|---|---|---|---|---|---|
| bullying | 0.85 | 0.75 | 0.80 | 0.83 | 327 |
| harassment | 0.88 | 0.86 | 0.87 | 0.87 | 553 |
| violence | 0.75 | 0.89 | 0.81 | 0.82 | 116 |
| threat | 0.83 | 0.85 | 0.84 | 0.87 | 141 |
| racism | 0.92 | 0.94 | 0.93 | 0.90 | 150 |
| discrimination | 0.93 | 0.90 | 0.91 | 0.91 | 175 |
| sexual_content | 0.88 | 0.76 | 0.81 | 0.83 | 141 |
| sexual_harassment | 0.82 | 0.94 | 0.88 | 0.90 | 270 |
| grooming | 0.85 | 0.98 | 0.91 | 0.90 | 241 |
| coercion | 0.76 | 0.90 | 0.82 | 0.85 | 313 |
| blackmail | 0.90 | 0.94 | 0.92 | 0.96 | 164 |
| self_harm | 0.95 | 0.78 | 0.85 | 0.89 | 94 |
| scam | 0.99 | 0.92 | 0.95 | 0.92 | 76 |
| safe | 0.96 | 0.97 | 0.97 | 0.98 | 1383 |
| asks_age | 0.96 | 0.95 | 0.96 | 0.96 | 218 |
| asks_location | 0.89 | 0.76 | 0.82 | 0.86 | 224 |
| asks_school | 0.63 | 0.84 | 0.72 | 0.80 | 143 |
| asks_photo | 0.90 | 0.88 | 0.89 | 0.89 | 481 |
| asks_nude | 0.76 | 0.71 | 0.73 | 0.79 | 143 |
| asks_secrecy | 0.94 | 0.92 | 0.93 | 0.95 | 324 |
| requests_meeting | 0.84 | 0.87 | 0.85 | 0.86 | 304 |
| threatens_disclosure | 0.94 | 0.90 | 0.92 | 0.95 | 189 |
| repeated_insults | 0.78 | 0.78 | 0.78 | 0.80 | 202 |
harassment next to bullying or coercion next to blackmail. Severity is usually still correct.V2.1 (v2/), measured on FSBench V2 and on 39 held-out hand-written chats:
asks_location / requests_meeting signals. A heavily garbled request ("kuanti annni aiii / mandm 1 fotoo") gets signals only (low), while V1 says high.@misc{family-safety-ai-2026,
title = {family-safety-ai: a small on-device classifier for child safety in Italian chats},
author = {Marco Liberati},
year = {2026},
url = {https://huggingface.co/markuz89/family-safety-ai-it}
}
xlmr-base/pytorch/encoder/model.safetensors 450 MBxlmr-base/onnx/model.onnx 448 MBpytorch/encoder/model.safetensors 139 MBv2/pytorch/encoder/model.safetensors 139 MBonnx/model.onnx 139 MBv2/onnx/model.onnx 139 MBonnx/model.int8.onnx 35 MBv2/onnx/model.int8.onnx 35 MBxlmr-base/pytorch/head.pt 72.5 kBpytorch/head.pt 37.2 kBv2/pytorch/head.pt 37.2 kBFacebookAI/xlm-roberta-base