Instructions to use Ywooo/StecSentinel-ModernBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ywooo/StecSentinel-ModernBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="Ywooo/StecSentinel-ModernBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("Ywooo/StecSentinel-ModernBERT") model = AutoModelForSequenceClassification.from_pretrained("Ywooo/StecSentinel-ModernBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
StecSentinel ModernBERT (v9g2)
A ModernBERT-base classifier that reads an HTTP request as "{METHOD} {URI}" (e.g. GET /search?q=...) and decides
whether it is an attack: BENIGN (0) or ATTACK (1).
It targets injection-style attacks in the URI (SQL injection, XSS, path traversal, command injection, etc.)
and path scanning for web shells and sensitive files, and is tuned to keep false positives on ordinary
traffic low.
Access: the weights are gated (manual approval). The model was fine-tuned in part on labeled real-world service traffic, so please do not redistribute the weights.
Usage
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
repo = "Ywooo/StecSentinel-ModernBERT"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()
req = "GET /search?q=1%27%20UNION%20SELECT%20username,password%20FROM%20users--"
x = tok(req, truncation=True, max_length=1024, return_tensors="pt")
with torch.no_grad():
p_attack = model(**x).logits.softmax(-1)[0, 1].item()
print("ATTACK" if p_attack >= 0.1 else "BENIGN", round(p_attack, 4))
The decision threshold used in training and evaluation is 0.1 on P(ATTACK); max length 1024 tokens.
Results (v9g2, validation sets, threshold 0.1)
| Set | What it tests | F1 | Recall | FPR | TP / FN / FP / TN |
|---|---|---|---|---|---|
| public_val | Public HTTP attack / normal datasets | 0.9993 | 0.9991 | 0.03% | 2300 / 2 / 1 / 3804 |
| real_val | Labeled real service traffic | 1.0000 | 1.0000 | 0.00% | 34 / 0 / 0 / 147 |
| csic_val | CSIC 2010 HTTP dataset | 0.9888 | 0.9778 | 0.00% | 176 / 4 / 0 / 180 |
| hard_val | Hard negatives: normal requests that look like attacks | 1.0000 | 1.0000 | 0.00% | 300 / 0 / 0 / 389 |
| complex_val | Long, complex API requests with attacks hidden deep inside | 1.0000 | 1.0000 | 0.00% | 655 / 0 / 0 / 521 |
| cc_val | Common Crawl normal URLs (split by host) + injected payloads | 0.9973 | 1.0000 | 0.24% | 1100 / 0 / 6 / 2505 |
| scan_val | Path scanning (web shells, sensitive files) vs. look-alike normal paths | 0.9810 | 0.9718 | 0.41% | 931 / 27 / 9 / 2210 |
Splits are made so validation does not leak from training: Common Crawl URLs are split by host, scan targets are split by file name (validation names never appear in training), and some public payload lists (FWAF, SecLists, PayloadsAllTheThings) are kept for testing only.
Baseline: a TF-IDF + linear classifier reaches F1 0.846 on csic_val (threshold 0.5; 0.899 at 0.25), against 0.989 for this model.
How it got here
Each version added a new evaluation set for a failure seen in the previous one, then fixed it with data.
| Version | Change | Effect |
|---|---|---|
| v1 | ModernBERT-base fine-tuned on public HTTP datasets | real traffic F1 0.875, FPR 4.5%: public data alone does not transfer |
| v2 | Add labeled real traffic | real F1 0.986 |
| v3โv4 | Add CSIC 2010 and hard negatives | CSIC F1 0.892 โ 0.957, hard negatives F1 0.997 |
| v5 | Add long / complex API requests | complex F1 1.000 (attacks late in long requests still caught) |
| v6โv8 | Add Common Crawl normal URLs, host-split, with injected payloads | CSIC F1 0.966 โ 0.986, Common Crawl FPR ~0.12% |
| v9 | Add path-scanning attacks and look-alike normal paths | scan F1 0.979, CSIC F1 0.997 |
| v9bโv9g | Rebalance scan / normal data | trade-off between scan recall and normal FPR |
| v9g2 | 2.0-epoch checkpoint of v9g instead of the early-stopped 1.0-epoch one | fewer false positives on ordinary traffic |
Training
- Base:
answerdotai/ModernBERT-base(22 layers, hidden 768), sequence classification, mean pooling - Initialized from v5; learning rate 5e-6, effective batch 32 (8 ร 4 accumulation), bf16
- Checkpoint selection on a combined score over all seven validation sets
Limitations
- Sees only the method and URI (path + query string), not headers or bodies.
- Validation numbers are on held-out splits of the data sources above; traffic from very different applications may need re-tuning of the threshold.
- Intended as one signal in a detection pipeline, not as a sole blocking rule.
- Downloads last month
- -
Model tree for Ywooo/StecSentinel-ModernBERT
Base model
answerdotai/ModernBERT-base