A French e-mail classifier with three classes: phishing, spam and legitimate. It is CamemBERTaV2 fine-tuned for Sicurre, a phishing detection project for French small businesses, where it is the machine learning stage of a pipeline that also uses rules and blocklists.
The repository holds the model in two formats, PyTorch and ONNX, so it can be fine-tuned further or served on CPU.
| Property | Value |
|---|---|
| Task | Text classification, one label per e-mail |
| Labels | 0 phishing, 1 spam, 2 legitimate |
| Language | French |
| Base model | almanach/camembertav2-base (111 million parameters) |
| Input | Subject and body as text, up to 256 tokens |
| Formats | model.safetensors (PyTorch) and model.onnx, about 445 MB each |
| Version | 1.0.30 |
| Licence | MIT |
from transformers import pipeline
classifier = pipeline(
"text-classification",
model="Mikolinton/sicurre-french-email-classifier",
)
email = (
"Objet : Votre colis est en attente de livraison\n\n"
"Bonjour, votre colis n'a pas pu être livré. Merci de régler les frais de "
"réexpédition de 1,99 EUR sous 48 heures : [URL]"
)
print(classifier(email, truncation=True, max_length=256))
# [{'label': 'phishing', 'score': 0.93}]
Pass top_k=None to get the score of all three classes.
The model was trained on text shaped like this, and works best when it receives the same shape:
Objet : <subject>
<body>
Objet : and the subject, then a blank line, then the body.[URL], [EMAIL], [PHONE] and [IBAN]. Doing the same brings
your input closer to it.truncation=True, max_length=256. Longer e-mails are cut at 256
tokens, so the subject and the opening of the body carry the decision.import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo = "Mikolinton/sicurre-french-email-classifier"
tokenizer = AutoTokenizer.from_pretrained(repo)
session = ort.InferenceSession(hf_hub_download(repo, "model.onnx"))
encoded = tokenizer(email, return_tensors="np", truncation=True, max_length=256)
logits = session.run(None, {
"input_ids": encoded["input_ids"].astype(np.int64),
"attention_mask": encoded["attention_mask"].astype(np.int64),
})[0][0]
scores = np.exp(logits - logits.max())
scores /= scores.sum()
print(dict(zip(["phishing", "spam", "legitimate"], scores.round(3))))
The ONNX file has dynamic sequence length, so short e-mails need no padding. It gives the same scores as the PyTorch weights.
Data. 43,700 French e-mails, split 80/10/10:
| Split | phishing | spam | legitimate | Total |
|---|---|---|---|---|
| train | 14,176 | 9,244 | 11,540 | 34,960 |
| validation | 1,772 | 1,155 | 1,442 | 4,369 |
| test | 1,772 | 1,156 | 1,443 | 4,371 |
Procedure.
| Setting | Value |
|---|---|
| Epochs | 4, keeping the best validation weighted F1; early stopping after two epochs without gain |
| Optimiser | AdamW, learning rate 2e-5, weight decay 0.01 |
| Schedule | Linear decay after 874 warm-up steps |
| Batch size | 16, with mixed precision |
| Maximum length | 256 tokens |
| Loss | Focal loss (gamma 1.5) with inverse class frequency weights and label smoothing 0.1 |
| Seed | 42 |
| Hardware | One Kaggle GPU |
The notebook training/train_classifier.ipynb
reproduces this procedure, from a labelled CSV file to the ONNX export.
Held-out test split (4,371 e-mails, same sources as the training data):
| Class | Precision | Recall | F1 | E-mails |
|---|---|---|---|---|
| phishing | 1.000 | 1.000 | 1.000 | 1,772 |
| spam | 0.998 | 0.998 | 0.998 | 1,156 |
| legitimate | 0.999 | 0.999 | 0.999 | 1,443 |
Accuracy and weighted F1 are both 0.999.
Release set (95 French e-mails written and reviewed separately from the training data: 42 phishing, 11 spam, 42 legitimate). Every version must pass it before release:
| Metric | Result |
|---|---|
| Weighted F1 | 0.86 |
| Phishing recall | 0.81 (34 of 42) |
| Legitimate e-mails flagged | 4 of 42 |
How to read these numbers: the test split shares its templates with the training data, so it shows that the model has learned its training distribution. The release set is the more demanding reference. Both are synthetic, so measure the model on your own mail before relying on a threshold.
| Resource | Link |
|---|---|
| Patterns dataset | Mikolinton/sicurre-french-emails |
| Training notebook | training/train_classifier.ipynb |
| Base model | almanach/camembertav2-base |
MIT, like the base model.
@misc{adebayo2026sicurrephishing,
author = {Adebayo, Michael},
title = {Sicurre French e-mail classifier},
year = {2026},
url = {https://huggingface.co/Mikolinton/sicurre-french-email-classifier}
}
The base model is CamemBERTaV2 (Antoun et al., 2024); please cite it as well when you use this model.
Classifieur d'e-mails français à trois classes : hameçonnage, spam et légitime. Il s'agit de CamemBERTaV2 affiné pour le projet open source Sicurre, où il constitue l'étape d'apprentissage automatique d'une chaîne de détection qui s'appuie aussi sur des règles et des listes de blocage. Le modèle est fourni aux formats PyTorch et ONNX. Il attend le texte sous la forme « Objet : sujet », une ligne vide, puis le corps du message, et lit au plus 256 jetons. Il convient comme signal parmi d'autres, comme base d'affinage ou pour l'enseignement.
model.onnx 446 MBmodel.safetensors 445 MB