Downloads · 30 days
16
5% of all-time downloads
AndrewAndrewsen/longformer-secret-masker
longformer-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.
[](https://opensource.org/licenses/Apache-2.0) [](https://huggingface.co/AndrewAndrewsen/longformer-secret-masker) [](https://huggingface.co/AndrewAndrewsen/longformer-secret-masker)
Downloads · 30 days
16
5% of all-time downloads
All-time downloads
329
Public
Parameters
148M
592 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors592 MB · 99%
From the Hugging Face model README
Long Expert model for SecMask MoE system - specialized for detecting secrets in long-context documents (up to 2048 tokens).
Fine-tuned Longformer model for detecting and classifying secrets (API keys, tokens, credentials) in long-form text using Named Entity Recognition (NER). Serves as the Long Expert in the SecMask Mixture of Experts architecture, handling complex cases requiring extended context (7.3% of requests) with ~12ms latency.
⚠️ IMPORTANT: This model has known compatibility issues with the current inference pipeline. Some test cases (PEM blocks, K8s secrets) produce errors. The recommended production configuration is Fast Expert + Filters alone, which achieves better results (92.3% precision, 80% recall) than Full MoE. This Long Expert model is experimental and optional. See Configuration Guide for details.
✅ Extended Context: 2048 token limit (4x larger than DistilBERT)
✅ High Precision: 82% (low false positives)
✅ Complex Structures: Handles multi-line YAML, K8s manifests, large configs
⚠️ Experimental: Known compatibility issues, not required for production
✅ Multi-Secret Types: AWS keys, GitHub tokens, JWTs, API keys, PEM blocks, K8s secrets
Note: Combines NER model (82% precision, 38% recall) with deterministic post-filters for comprehensive long-document secret detection. However, due to compatibility issues, Fast Expert + Filters achieves better results in practice.
🎯 Kubernetes Manifests (1000+ line YAML files)
🎯 Terraform/CloudFormation configs
🎯 Docker Compose files
🎯 Large Log Files with embedded secrets
🎯 Multi-file Concatenated outputs
🎯 API Response Payloads (JSON arrays)
pip install transformers torch
Standalone (Direct):
from transformers import pipeline
# Load model
classifier = pipeline(
"token-classification",
model="AndrewAndrewsen/longformer-secret-masker",
aggregation_strategy="simple"
)
# Detect secrets in long config file
with open('docker-compose.yml', 'r') as f:
config = f.read() # May be >512 tokens
results = classifier(config)
print(results)
# [{'entity_group': 'SECRET', 'score': 0.92, 'word': 'AKIAIOSFODNN7EXAMPLE', ...}, ...]
Recommended (via SecMask MoE):
# Clone SecMask repo
# git clone https://github.com/AndrewAndrewsen/secmask.git
from infer_moe import mask_text_moe
# Router automatically uses Long Expert for complex texts
masked = mask_text_moe(
long_yaml_content, # >512 tokens or multi-line structure
fast_model_dir="AndrewAndrewsen/distilbert-secret-masker",
long_model_dir="AndrewAndrewsen/longformer-secret-masker",
tau=0.80,
routing_mode="heuristic"
)
print(masked)
# Secrets in long document masked
# Clone repo
git clone https://github.com/AndrewAndrewsen/secmask.git
cd secmask
# Mask secrets in long file
python infer_moe.py \
--in k8s-deployment.yaml \
--fast-model AndrewAndrewsen/distilbert-secret-masker \
--long-model AndrewAndrewsen/longformer-secret-masker \
--routing-mode heuristic \
--tau 0.80 \
--out k8s-deployment-masked.yaml
| Metric | Value | Status |
|---|---|---|
| F1 Score | 0.52 | NER-only |
| Precision | 0.82 | NER-only |
| Recall | 0.38 | NER-only |
| Avg Latency | 12ms | ⚠️ When working |
| P99 Latency | 87.3ms | ⚠️ When working |
⚠️ Note: This model has compatibility issues with the current inference pipeline. Evaluation shows errors on PEM block and K8s secret test cases. The Full MoE configuration (Fast+Long+Filters) achieves 90.9% precision and 76.9% recall due to these errors, compared to 92.3% precision and 80% recall for Fast+Filters alone. See BENCHMARK_RESULTS.md for details.
The router would select this Long Expert when:
-----BEGIN ... -----END ...)kind: Secret)⚠️ Recommendation: Due to compatibility issues, use the DistilBERT Secret Masker with post-processing filters instead. This achieves better results without the Long Expert.
allenai/longformer-base-4096 (149M 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:
Infrastructure-as-Code (IaC) Scanning
.tf files.yaml templatesKubernetes Security
kind: Secret resourcesConfiguration Auditing
.env files (concatenated)Log File Sanitization
Documentation Cleanup
from transformers import pipeline
classifier = pipeline(
"token-classification",
model="AndrewAndrewsen/longformer-secret-masker"
)
# Read K8s manifest
with open('deployment.yaml', 'r') as f:
manifest = f.read()
# Detect secrets
secrets = classifier(manifest)
if secrets:
print(f"⚠️ Found {len(secrets)} secrets in manifest!")
for secret in secrets:
print(f" - {secret['word'][:20]}... (score: {secret['score']:.2f})")
import json
from transformers import pipeline
classifier = pipeline(
"token-classification",
model="AndrewAndrewsen/longformer-secret-masker"
)
# Read Terraform state (can be very long)
with open('terraform.tfstate', 'r') as f:
state = f.read()
# Detect secrets
secrets = classifier(state[:4096]) # Truncate if >4096 tokens
# Flag resources with secrets
if secrets:
print("❌ Secrets detected in Terraform state!")
print("Consider using encrypted backends or secret managers.")
See SecMask Examples for more.
❌ Short texts (<100 tokens) - use distilbert-secret-masker for speed
❌ Real-time streaming (higher latency)
❌ Non-English text
❌ Binary data or encrypted content
❌ Extremely long documents >4096 tokens (use chunking)
tau for higher recall (more false positives)Apache 2.0 (inherited from allenai/longformer-base-4096)
This model is fine-tuned from:
allenai/longformer-base-4096@inproceedings{beltagy2020longformer,
title={Longformer: The Long-Document Transformer},
author={Beltagy, Iz and Peters, Matthew E. and Cohan, Arman},
booktitle={arXiv:2004.05150},
year={2020}
}
The SecMask inference code and training scripts are licensed under MIT. See GitHub repo.
| Model | Size | Max Tokens | Latency | Use Case |
|---|---|---|---|---|
| distilbert-secret-masker | 265MB | 512 | 6ms | Short texts, fast routing |
| longformer-secret-masker (this model) | 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