/ Модель

Характеристики

Контекст
512 токенов
Лицензия
Apache 2.0
Архитектура
distilbert · dense
Базовая модель
distilbert-base-uncased
Библиотека
transformers
Опубликована
12 ноя 2025

distilbert-secret-masker

Разметка токеновТекст → label8 профессий

Дообученная DistilBERT-модель для поиска и разметки секретов, таких как API-ключи и токены, в английском тексте длиной до 512 токенов.

100скачиваний за 30 дней0лайковвеса обновлены1 сен 2026

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

AndrewAndrewsen/distilbert-secret-masker — дообученная модель DistilBERT для обнаружения и разметки секретов в английском тексте. Она использует архитектуру DistilBertForTokenClassification с BIO-метками B-SECRET, I-SECRET и O, содержит 66 млн параметров и рассчитана на последовательности длиной до 512 токенов. Модель предназначена для поиска API-ключей, токенов и учётных данных в коротких и средних текстах, например в коммитах, журналах и выводе API.

Модель описана как быстрый эксперт системы SecMask; для типичных запросов автор указывает задержку около 11 мс на CPU. Самостоятельно модель показывает точность 82% и полноту 38% на приведённой оценке. В сочетании с детерминированными фильтрами для отдельных форматов секретов README сообщает точность 92,3% и полноту 80%, поэтому для сканирования с высокой полнотой рекомендуется использовать постобработку. Модель может пропускать секреты, особенно новые типы и необычно оформленные значения; она не предназначена для неанглийского текста, бинарных данных, изображений или длинных документов. Лицензия — Apache-2.0.

Сценарии применения

  • поиск ключей и токенов перед фиксацией изменений в Git
  • сканирование кода в CI/CD перед развёртыванием
  • обнаружение учётных данных в журналах приложений
  • маскирование секретов в отладочных ответах API
  • проверка документации перед публикацией в открытом доступе
  • аудит кода на случайно раскрытые секреты

Ограничения

Модель принимает последовательности до 512 токенов и обучена для английского текста; она может пропускать секреты, особенно новые типы и значения с необычным форматированием. Для повышения полноты автор рекомендует сочетать её с детерминированными фильтрами.

Для каких профессий подходит8

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Также подходит для

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

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 frozen sliding-window inference path — see its card for benchmarks.

DistilBERT Secret Masker (Fast Expert)

License: Apache 2.0 Model Size Inference Speed

Fast Expert model for SecMask MoE system - specialized for rapid secret detection in short to medium-length texts (≤512 tokens).


🎯 Overview

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.

Key Features

✅ 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.

Detected Secret Types

Secret TypeExample PatternF1 Score
AWS Access KeysAKIA...0.92
GitHub Personal Tokensghp_..., gho_...0.88
JWT TokenseyJ0eXAiOiJKV1QiLCJhbGc...0.85
Generic API Keyssk-proj-..., api_key=...0.79
PEM Certificate Blocks-----BEGIN PRIVATE KEY-----0.95
Kubernetes Secrets (data)kind: Secret → data: values0.81
Database CredentialsConnection strings with passwords0.74

🚀 Quick Start

Installation

pip install transformers torch

Basic Usage

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]"

Command Line (via SecMask)

# 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]

📊 Performance

Secret Detection Metrics

MetricNER OnlyWith Filters (Recommended)
F1 Score0.520.857
Precision82%92.3%
Recall38%80.0%
P50 Latency11ms11ms
P90 Latency14ms14ms
P99 Latency17ms17ms
Throughput84 req/s84 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.

When This Model Is Used (MoE Routing)

The router selects this Fast Expert when:

  • Token count ≤ 512
  • No multi-line structures (PEM blocks, K8s YAML)
  • Simple text patterns
  • Coverage: 92.7% of real-world requests

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.


🏗️ Model Details

Architecture

  • Base Model: distilbert-base-uncased (66M params, Apache 2.0)
  • Task: Token Classification (NER)
  • Max Sequence Length: 512 tokens
  • Label: B-SECRET, I-SECRET, O (BIO tagging)

Training Details

  • Dataset: Custom SecretMask v2 (6,000 training examples)
  • Optimizer: AdamW (lr=5e-5)
  • Epochs: 3
  • Batch Size: 16
  • Hardware: GPU (NVIDIA A100 or equivalent)
  • Training Time: ~30 minutes

Evaluation

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:

  • High Precision (82%): Very low false positive rate - safe for production
  • Lower Recall (38%): Misses some secrets when used standalone
  • Production Strategy: Combine with deterministic filters (see filters.py) for PEM blocks, K8s secrets, and AWS patterns to achieve >90% coverage
  • Threshold Tuning: Lower τ from 0.80 to 0.50 for higher recall (trade-off: more false positives)

💡 Use Cases

Production Applications

  1. Pre-Commit Hooks - Prevent secrets in git commits
  2. CI/CD Pipelines - Scan code before deployment
  3. Log Sanitization - Remove secrets from application logs
  4. API Response Filtering - Mask secrets in debug output
  5. Documentation Cleanup - Sanitize before open-sourcing
  6. Security Audits - Scan codebases for exposed credentials

Example: Pre-Commit Hook

# .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.


⚠️ Limitations

Known Issues

  1. Token Limit: Cannot handle texts >512 tokens (use Longformer expert)
  2. English Only: Trained on English text
  3. False Negatives: ~25% recall means some secrets may be missed
  4. Context Sensitivity: May struggle with unusual formatting
  5. Novel Patterns: May miss new secret types not in training data

Not Suitable For

❌ 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)

Recommended Mitigations

  • Combine with filters: Use deterministic filters for PEM blocks, K8s secrets (see SecMask filters)
  • Adjust threshold: Lower tau for higher recall (more false positives)
  • Use MoE system: Automatic routing to appropriate expert
  • Add regex patterns: Supplement with custom patterns for your use case

📜 License & Attribution

Model License

Apache 2.0 (inherited from distilbert-base-uncased)

Base Model Attribution

This model is fine-tuned from:

  • Model: distilbert-base-uncased
  • Authors: Hugging Face
  • License: Apache 2.0
  • Citation:
    @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}
    }
    

SecMask Code License

The SecMask inference code and training scripts are licensed under MIT. See GitHub repo.


🔗 Related Models

ModelSizeMax TokensLatencyUse Case
distilbert-secret-masker (this model)265MB5126msShort texts, fast routing
longformer-secret-masker592MB204812msLong documents, configs
secretmask-gate12KBN/A+0.2msLearned MoE routing

📚 Resources


🤝 Contributing

Issues and contributions welcome! See CONTRIBUTING.md.


Developed by: Anders Andersson (@AndrewAndrewsen)
Part of: SecMask MoE System

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · transformers · token-classification

Можно запустить

Подбираем GPU…

Класс архитектуры
DistilBertForTokenClassification
Ревизия весов
2122140

0 моделей