Text Classification
Transformers
ONNX
Safetensors
English
modernbert
ai-text-detection
email
text-embeddings-inference
Instructions to use SkootrAI/PostBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SkootrAI/PostBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="SkootrAI/PostBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("SkootrAI/PostBERT") model = AutoModelForSequenceClassification.from_pretrained("SkootrAI/PostBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 7,975 Bytes
5fbb148 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | ---
license: apache-2.0
language:
- en
base_model: answerdotai/ModernBERT-base
pipeline_tag: text-classification
library_name: transformers
inference: false
tags:
- ai-text-detection
- email
- modernbert
- onnx
---
# PostBERT

**PostBERT** is a fast, compact open-weight classifier built specifically for email. It scores an English email body from `0` (human) to `100` (AI) in a single pass up to **1,024 tokens** (~750 words), running locally on a laptop CPU, GPU, or directly inside a web browser. Your email never leaves the device.
Built by **Skootr** on [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) (149.6M parameters, Apache-2.0).
## Why PostBERT
- **Built for real email, not essays.** General AI detectors often trip on normal email formatting, short replies, and signatures. PostBERT is trained and normalized specifically for email bodies from 25 words up to 1,024 tokens.
- **Private by design.** At 300 MB in half-precision ONNX, PostBERT runs natively in Chrome WebGPU, WebAssembly, or local CPU with zero API calls.
- **Tunable 3-bracket scoring.** Outputs a continuous `0-100` score (`ai_score`) so you can sort messages into **Likely human**, **Potentially AI**, and **Likely AI** using brackets that fit your workflow.
- **Strong on unseen models.** Tested against three AI model families held completely out of training, holding **94.8%** detection on unseen families at 1 false alarm per 500 human emails.
## Recommended Score Brackets
PostBERT outputs a continuous `0-100` score. You can set your own thresholds for your tolerance, or use our recommended 3-bracket setup:
| Bracket | Score range | Meaning |
|---|---|---|
| **Likely human** | `0` to `10` | Reads as human-written |
| **Potentially AI** | `10` to `51` | Mixed, AI-assisted, or uncertain |
| **Likely AI** | `51` to `100` | Reads as AI-written (1-in-500 human false-alarm rate) |
### Benchmark Results (Recommended Brackets)
Measured on our held-out November 2026 test set (16,080 pre-Nov-2022 human emails, 1,690 mixed-AI emails, and 1,209 full-AI emails; none used in training):
| Email group | Count | Likely human (`0-10`) | Potentially AI (`10-51`) | Likely AI (`51-100`) | AUROC |
|---|---:|---:|---:|---:|---:|
| **Human** | 16,080 | **98.0%** | 1.8% | **0.2%** | - |
| **Full AI (>100 words)** | 386 | 0.3% | 1.0% | **98.7%** | **0.9998** |
| **Full AI (25-100 words)** | 823 | 2.8% | 1.8% | **95.4%** | **0.996** |
| **Full AI (unseen model families)** | 343 | 2.6% | 2.6% | **94.8%** | **0.994** |
| **Mixed AI (all)** | 1,690 | 7.2% | 18.3% | **74.5%** | **0.988** |
| Mixed: AI-written from summary | 938 | 3.4% | 5.8% | **90.8%** | 0.995 |
| Mixed: AI rewrite of human email | 752 | 12.0% | 33.9% | **54.1%** | 0.980 |
- **Long emails (401 to 3,500 words):** On an additional held-out set of longer emails (674 human, 123 AI rewrites, 142 AI-from-summary, 121 full AI) scored in one pass up to 1,024 tokens, **0 of 674** human emails landed in Likely AI (`>=51`) and **100%** of full-AI and AI-from-summary emails were detected (AUROC `1.000`; AI rewrites AUROC `0.996`).
## Quick Start
```python
import importlib.util
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer, AutoModelForSequenceClassification
repo = "SkootrAI/PostBERT"
# Load the required text normalizer from this repository
spec = importlib.util.spec_from_file_location(
"normalize", hf_hub_download(repo, "normalize.py"))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
normalize = mod.normalize
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSequenceClassification.from_pretrained(repo).eval()
def score_email(email_body: str) -> tuple[float, str]:
enc = tok(normalize(email_body), truncation=True, max_length=1024,
return_tensors="pt")
with torch.inference_mode():
score = 100 * torch.sigmoid(model(**enc).logits[0, 0]).item()
bracket = "likely_human" if score < 10 else "potentially_ai" if score < 51 else "likely_ai"
return round(score, 1), bracket
print(score_email("Paste an email body of 25 words or more here ..."))
```
### Best Practices
1. **Always run `normalize()` first.** It standardizes typography, spacing, and hard line wraps and replaces URLs, email addresses, and phone numbers with fixed placeholders so the model focuses on authorship rather than formatting.
2. **Score only the new message.** Strip quoted replies, forwarded threads, and automatic footers beforehand.
3. **Use 25+ words.** Messages under 25 words do not carry enough signal to score reliably.
### Emails Over 1,024 Tokens
Single-pass scoring covers up to 1,024 tokens (~750 words). For longer emails, you can score overlapping 1,024-token windows (1,022 content tokens plus start and end tokens) and combine the scores however fits your app:
```python
def part_scores(email_body: str, size: int = 1022) -> list[float]:
ids = tok(normalize(email_body), add_special_tokens=False)["input_ids"]
starts = [0]
if len(ids) > size:
starts = list(range(0, len(ids) - size, size)) + [len(ids) - size]
scores = []
for s in starts:
part = [tok.cls_token_id] + ids[s:s + size] + [tok.sep_token_id]
with torch.inference_mode():
logit = model(input_ids=torch.tensor([part])).logits[0, 0]
scores.append(100 * torch.sigmoid(logit).item())
return scores
```
## Speed Benchmarks
Median single-email latency measured on an Apple M1 Ultra (`model_fp16.onnx` for ONNX / browser, `model.safetensors` for PyTorch MPS):
| Runtime | 64 tokens (~25-50 words) | 128 tokens (~50-100 words) | 256 tokens (~100-200 words) | 512 tokens (~200-400 words) | 1,024 tokens (~400-750 words) |
|---|---:|---:|---:|---:|---:|
| **PyTorch (MPS GPU)** | 14 ms | 16 ms | 18 ms | 30 ms | 63 ms |
| **Chrome (WebGPU)** | 78 ms | 78 ms | 96 ms | 159 ms | 402 ms |
| **ONNX Runtime (4 CPU threads)** | 59 ms | 113 ms | 224 ms | 496 ms | 1,199 ms |
| **Chrome (WASM, 8 threads)** | 72 ms | 132 ms | 258 ms | 588 ms | 1,394 ms |
| **ONNX Runtime (1 CPU thread)** | 176 ms | 352 ms | 774 ms | 1,719 ms | 3,889 ms |
## Repository Files
| File | Purpose |
|---|---|
| `model.safetensors` | PyTorch / Transformers weights (fp32, ~600 MB) |
| `onnx/model.onnx` | ONNX Runtime weights (fp32, ~600 MB) |
| `onnx/model_fp16.onnx` | ONNX Runtime & ONNX Runtime Web weights (fp16, ~300 MB) |
| `normalize.py` | Standalone text normalizer (Python standard library only) |
## Training Overview
PostBERT was trained on ~45,000 English emails:
- **~27,000 human emails:** publicly available pre-November-2022 email from public-record archives and open mailing lists.
- **~18,000 AI emails:** generated across 10 language models from 5 model families, covering full drafts, summary-to-email drafts, and rewrites of human messages.
No private or customer email was used.
## Scope & Practical Notes
- **Signal, not proof:** Treat PostBERT as a triage and awareness signal rather than standalone proof of authorship.
- **English email (25+ words):** Built and benchmarked for English email bodies of 25 words or more.
- **Tune for your inbox:** Benchmark brackets on a small sample of your own known-human mail if your domain has unusual templates or boilerplate.
## Questions & Comments
If you have questions or comments, please open a thread in the [Community tab](https://huggingface.co/SkootrAI/PostBERT/discussions) or contact us at [models@skootr.ai](mailto:models@skootr.ai).
## License
Apache License 2.0 (same as [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base)). Copyright 2026 Skootr.
## Citation
```bibtex
@misc{postbert2026,
title = {PostBERT: an on-device detector for AI-written email},
author = {Skootr},
year = {2026},
url = {https://huggingface.co/SkootrAI/PostBERT}
}
```
|