Downloads · 30 days
51
3% of all-time downloads
AndrewAndrewsen/distilbert-secret-masker
distilbert-secret-masker is a token classification model from AndrewAndrewsen. Use it when you need labels on individual words, such as names. It is set up for transformers. The card lists the license as apache-2.0.
New recommended model: AndrewAndrewsen/distilbert-secret-masker-v3.3a-rs This repository is the previous v2 release, kept for reproducibility. v3.3a-RS has different training, a stronger real-code evaluation, and a fr…
Downloads · 30 days
51
3% of all-time downloads
All-time downloads
1.9K
Public
Parameters
66.4M
531 MB on disk
Likes
0
Public
Click a slice to open those files.
.onnx266 MB · 50%
From the Hugging Face model README
New recommended model:
AndrewAndrewsen/distilbert-secret-masker-v3.3a-rsThis repository is the previous v2 release, kept for reproducibility. v3.3a-RS has different training, a stronger real-code evaluation, and a frozen sliding-window inference path — see its card for benchmarks.
Fast Expert model for SecMask MoE system - specialized for rapid secret detection in short to medium-length texts (≤512 tokens).
Fine-tuned DistilBERT model for detecting and classifying secrets (API keys, tokens, credentials) in text using Named Entity Recognition (NER). Serves as the Fast Expert in the SecMask Mixture of Experts architecture, handling 92.7% of inference requests with ~6ms latency.
✅ High Speed: 11ms P50 latency on CPU
✅ High Precision: 82% (NER-only), 92.3% with filters
✅ Production Ready: Handles 92.7% of real-world cases
✅ Lightweight: 265MB (66M parameters)
✅ Multi-Secret Types: AWS keys, GitHub tokens, JWTs, API keys, PEM blocks, K8s secrets
Production Performance: When combined with post-processing filters (PEM blocks, K8s secrets, pattern matching), achieves 92.3% precision, 80% recall, F1: 0.857. The NER model alone achieves 82% precision and 38% recall. See comprehensive benchmarks for details.
Recommended Configuration: Fast Expert + Filters (this model with post-processing) is the recommended production setup, outperforming Full MoE configurations. See Configuration Guide for usage recommendations.
| Secret Type | Example Pattern | F1 Score |
|---|---|---|
| AWS Access Keys | AKIA... | 0.92 |
| GitHub Personal Tokens | ghp_..., gho_... | 0.88 |
| JWT Tokens | eyJ0eXAiOiJKV1QiLCJhbGc... | 0.85 |
| Generic API Keys | sk-proj-..., api_key=... | 0.79 |
| PEM Certificate Blocks | -----BEGIN PRIVATE KEY----- | 0.95 |
| Kubernetes Secrets (data) | kind: Secret → data: values | 0.81 |
| Database Credentials | Connection strings with passwords | 0.74 |
pip install transformers torch
Standalone (Direct):
from transformers import pipeline
# Load model
classifier = pipeline(
"token-classification",
model="AndrewAndrewsen/distilbert-secret-masker",
aggregation_strategy="simple"
)
# Detect secrets
text = "My API key is sk-proj-1234567890abcdefghijklmnopqrstuvwxyz"
results = classifier(text)
print(results)
# [{'entity_group': 'SECRET', 'score': 0.95, 'word': 'sk-proj-1234567890abcdefghijklmnopqrstuvwxyz', ...}]
Recommended (via SecMask MoE):
# Clone SecMask repo
# git clone https://github.com/AndrewAndrewsen/secmask.git
from infer_moe import mask_text_moe
masked = mask_text_moe(
"My GitHub token is ghp_1234567890abcdefghijklmnopqrstuvwxyz",
fast_model_dir="AndrewAndrewsen/distilbert-secret-masker",
tau=0.80,
routing_mode="heuristic"
)
print(masked)
# "My GitHub token is [SECRET]"
# Clone repo
git clone https://github.com/AndrewAndrewsen/secmask.git
cd secmask
# Mask secrets
python infer_moe.py \
--text "AWS key: AKIAIOSFODNN7EXAMPLE" \
--fast-model AndrewAndrewsen/distilbert-secret-masker \
--routing-mode heuristic \
--tau 0.80
# Output: AWS key: [SECRET]
| Metric | NER Only | With Filters (Recommended) |
|---|---|---|
| F1 Score | 0.52 | 0.857 |
| Precision | 82% | 92.3% |
| Recall | 38% | 80.0% |
| P50 Latency | 11ms | 11ms |
| P90 Latency | 14ms | 14ms |
| P99 Latency | 17ms | 17ms |
| Throughput | 84 req/s | 84 req/s (CPU) |
Note: NER-only metrics measured at τ=0.80. Production systems combine NER with post-processing filters (PEM blocks, K8s secrets, pattern matching) to achieve 92.3% precision and 80% recall. Post-processing adds no latency overhead. See BENCHMARK_RESULTS.md for comprehensive benchmarks.
The router selects this Fast Expert when:
Note: The recommended production configuration is Fast Expert + Filters alone (without the Long Expert). This achieves better results than Full MoE. See Configuration Guide for details.
distilbert-base-uncased (66M params, Apache 2.0)B-SECRET, I-SECRET, O (BIO tagging)Evaluated on 600 held-out examples from SecretMask v2 test set:
Precision: 0.82
Recall: 0.38
F1: 0.52
Support: 1,021 secret tokens
Key Insights:
filters.py) for PEM blocks, K8s secrets, and AWS patterns to achieve >90% coverage# .git/hooks/pre-commit
from transformers import pipeline
classifier = pipeline("token-classification", model="AndrewAndrewsen/distilbert-secret-masker")
for file in staged_files:
content = read_file(file)
secrets = classifier(content)
if secrets:
print(f"❌ Secret detected in {file}!")
exit(1)
See SecMask Examples for more.
❌ Non-English text
❌ Binary data or encrypted content
❌ Images/PDFs (extract text first)
❌ Very long documents (use longformer-secret-masker)
❌ Real-time streaming (consider batching)
tau for higher recall (more false positives)Apache 2.0 (inherited from distilbert-base-uncased)
This model is fine-tuned from:
distilbert-base-uncased@inproceedings{sanh2019distilbert,
title={DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter},
author={Sanh, Victor and Debut, Lysandre and Chaumond, Julien and Wolf, Thomas},
booktitle={NeurIPS EMC^2 Workshop},
year={2019}
}
The SecMask inference code and training scripts are licensed under MIT. See GitHub repo.
| Model | Size | Max Tokens | Latency | Use Case |
|---|---|---|---|---|
| distilbert-secret-masker (this model) | 265MB | 512 | 6ms | Short texts, fast routing |
| longformer-secret-masker | 592MB | 2048 | 12ms | Long documents, configs |
| secretmask-gate | 12KB | N/A | +0.2ms | Learned MoE routing |
Issues and contributions welcome! See CONTRIBUTING.md.
Developed by: Anders Andersson (@AndrewAndrewsen)
Part of: SecMask MoE System