Abhishek Dey commited on
Commit Β·
de60867
1
Parent(s): 2155b20
Update model card: detailed descriptions for all sections
Browse files
README.md
CHANGED
|
@@ -26,11 +26,15 @@ model-index:
|
|
| 26 |
|
| 27 |
# BERT Compliance Classifier Router
|
| 28 |
|
| 29 |
-
A 134M parameter BERT encoder model
|
|
|
|
|
|
|
| 30 |
|
| 31 |
## Model Description
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
| Label | Complexity | PII | Routing Action |
|
| 36 |
|-------|-----------|-----|----------------|
|
|
@@ -41,53 +45,73 @@ This model classifies incoming user queries into 4 routing categories for cost-o
|
|
| 41 |
|
| 42 |
## Key Results
|
| 43 |
|
|
|
|
|
|
|
| 44 |
- **Accuracy:** 99.2%
|
| 45 |
-
- **PII Recall:** ~100%
|
| 46 |
- **Latency:** ~7ms (GPU) / ~72ms (CPU)
|
| 47 |
-
- **Throughput:** ~130 queries/sec per GPU
|
| 48 |
-
- **Model Size:** 134M parameters / ~530 MB
|
|
|
|
| 49 |
|
| 50 |
## Files
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
| 55 |
-
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
## Architecture
|
| 58 |
|
|
|
|
|
|
|
| 59 |
- **Type:** BERT Encoder (bidirectional transformer, no causal mask)
|
| 60 |
- **Dimensions:** 768
|
| 61 |
- **Layers:** 12
|
| 62 |
- **Attention Heads:** 12
|
| 63 |
- **FFN Dimension:** 3072
|
| 64 |
- **Max Sequence Length:** 128 tokens (inference) / 512 tokens (pre-training)
|
| 65 |
-
- **Vocabulary:** 32,000 (BPE, includes `<mask>` token)
|
| 66 |
-
- **Activation:** GELU
|
| 67 |
-
- **Normalization:** LayerNorm
|
| 68 |
- **Classification Head:** Linear(768β768) β Tanh β Dropout β Linear(768β4)
|
| 69 |
|
| 70 |
## Training
|
| 71 |
|
|
|
|
|
|
|
| 72 |
### Pre-training
|
|
|
|
|
|
|
|
|
|
| 73 |
- **Objective:** Masked Language Model (MLM), 15% masking (80/10/10)
|
| 74 |
-
- **Data:** English Wikipedia (2B tokens
|
| 75 |
- **Batch size:** 8, sequence length: 512
|
| 76 |
-
- **
|
|
|
|
| 77 |
- **Hardware:** NVIDIA L4 (24 GB), ~48 hours
|
|
|
|
| 78 |
- **Final Loss:** 1.815
|
| 79 |
|
| 80 |
### Fine-tuning
|
|
|
|
|
|
|
|
|
|
| 81 |
- **Data:** 50,000 synthetic FSI examples (balanced, 12,500 per class)
|
| 82 |
- **PII Types:** 14 (PAN, Aadhaar, phone, email, UPI, DOB, card, DL, voter, passport, address, IFSC)
|
| 83 |
- **Input Formats:** Structured + unstructured (human-typed messy input)
|
| 84 |
-
- **Languages:** English + Hinglish (15%)
|
| 85 |
-
- **Steps:** 8,000, batch=32,
|
|
|
|
| 86 |
- **Hardware:** NVIDIA L4, ~15 minutes
|
| 87 |
- **Final Accuracy:** 99.2%
|
| 88 |
|
| 89 |
## Usage
|
| 90 |
|
|
|
|
|
|
|
| 91 |
```python
|
| 92 |
import torch
|
| 93 |
import torch.nn.functional as F
|
|
@@ -96,7 +120,7 @@ from tokenizers import Tokenizer
|
|
| 96 |
# Load tokenizer
|
| 97 |
tokenizer = Tokenizer.from_file("deycoding.compliance-classifier-in-1-0.json")
|
| 98 |
|
| 99 |
-
# Load model (requires architecture definition β see
|
| 100 |
model.load_state_dict(torch.load("deycoding.compliance-classifier-in-1-0.pt", map_location="cpu"))
|
| 101 |
model.eval()
|
| 102 |
|
|
@@ -119,10 +143,10 @@ print(f"{prediction} ({confidence:.1f}%)")
|
|
| 119 |
|
| 120 |
## PII Detection Capabilities
|
| 121 |
|
| 122 |
-
|
| 123 |
|
| 124 |
-
| PII Type | Structured | Unstructured |
|
| 125 |
-
|----------|-----------|--------------|
|
| 126 |
| PAN | ABCDE1234F | pan abcde1234f |
|
| 127 |
| Aadhaar | 1234 5678 9012 | aadhar no 123456789012 |
|
| 128 |
| Phone | +91-98765-43210 | my number is 9876543210 |
|
|
@@ -136,35 +160,50 @@ Detects personal identifiable information in both structured and unstructured (h
|
|
| 136 |
| Voter ID | ABC1234567 | voter id ABC1234567 |
|
| 137 |
| Address | Flat 4B, Tower 2, Koramangala | flat 4b tower 2 koramangala bangalore 560034 |
|
| 138 |
| IFSC | SBIN0123456 | ifsc SBIN0123456 |
|
|
|
|
| 139 |
|
| 140 |
## Intended Use
|
| 141 |
|
|
|
|
|
|
|
| 142 |
- Query routing in multi-tier LLM serving architectures
|
| 143 |
-
- PII detection for data residency compliance (GDPR, RBI, DPDP Act)
|
| 144 |
-
- Cost optimization β route simple queries to cheaper models (65-73% savings)
|
| 145 |
-
- Financial services,
|
|
|
|
|
|
|
| 146 |
|
| 147 |
## Limitations
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
-
|
| 152 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
## Ethical Considerations
|
| 155 |
|
|
|
|
|
|
|
| 156 |
- Model makes routing decisions, not content decisions
|
| 157 |
-
- PII detection is conservative (prefers false positive over
|
| 158 |
- Data residency enforcement is architectural β PII queries physically cannot reach cross-region infrastructure
|
|
|
|
|
|
|
| 159 |
|
| 160 |
## Citation
|
| 161 |
|
|
|
|
|
|
|
| 162 |
```bibtex
|
| 163 |
@misc{dey2026classifier,
|
| 164 |
title={Classifier-Gated Multi-Tier LLM Routing for Cost-Optimized Serving in Regulated Industries},
|
| 165 |
author={Abhishek Dey},
|
| 166 |
year={2026},
|
| 167 |
-
url={https://huggingface.co/deycoding/
|
| 168 |
}
|
| 169 |
```
|
| 170 |
|
|
@@ -175,4 +214,4 @@ Detects personal identifiable information in both structured and unstructured (h
|
|
| 175 |
|
| 176 |
## License
|
| 177 |
|
| 178 |
-
CC-BY-NC-4.0
|
|
|
|
| 26 |
|
| 27 |
# BERT Compliance Classifier Router
|
| 28 |
|
| 29 |
+
A 134M parameter BERT encoder model built entirely from scratch β from pre-training through fine-tuning β designed specifically for regulated industries such as Financial Services, Healthcare, and Legal. The model serves as an intelligent query router that classifies incoming prompts based on two critical dimensions: query complexity and the presence of Personally Identifiable Information (PII). This enables cost-optimized, compliance-aware LLM serving where sensitive data never leaves local infrastructure.
|
| 30 |
+
|
| 31 |
+
Unlike traditional keyword-based or regex-based PII detection, this model learns contextual patterns from training data, enabling it to detect PII in both structured formats (like PAN: ABCDE1234F) and unstructured human-typed input (like "my pan is abcde1234f" or "Mera PAN number batao"). The model supports English and Hinglish (Hindi-English code-mixed) queries commonly seen in Indian financial services.
|
| 32 |
|
| 33 |
## Model Description
|
| 34 |
|
| 35 |
+
The core purpose of this model is to sit at the entry point of a multi-tier LLM serving architecture. When a user query arrives, this classifier makes a routing decision in under 10 milliseconds β determining whether the query should go to a small or large language model, and whether the data must stay on local infrastructure or can be processed cross-region. This architectural pattern delivers 65-73% cost savings compared to routing all queries to a single large model, while simultaneously enforcing data residency compliance that is architecturally impossible with Mixture-of-Experts (MoE) approaches.
|
| 36 |
+
|
| 37 |
+
The model outputs one of four labels, each mapping directly to a routing action:
|
| 38 |
|
| 39 |
| Label | Complexity | PII | Routing Action |
|
| 40 |
|-------|-----------|-----|----------------|
|
|
|
|
| 45 |
|
| 46 |
## Key Results
|
| 47 |
|
| 48 |
+
The model achieves production-ready performance across all metrics. The 99.2% accuracy on a held-out test set demonstrates strong generalization, while the sub-10ms latency ensures the routing decision adds negligible overhead to the overall request lifecycle. The throughput of 130+ queries per second on a single GPU means a single instance can serve millions of classification requests per day.
|
| 49 |
+
|
| 50 |
- **Accuracy:** 99.2%
|
| 51 |
+
- **PII Recall:** ~100% (conservative β prefers false positive over missed PII)
|
| 52 |
- **Latency:** ~7ms (GPU) / ~72ms (CPU)
|
| 53 |
+
- **Throughput:** ~130 queries/sec per GPU instance
|
| 54 |
+
- **Model Size:** 134M parameters / ~530 MB on disk
|
| 55 |
+
- **Inference Memory:** ~530 MB VRAM (fits on any GPU including T4 16GB)
|
| 56 |
|
| 57 |
## Files
|
| 58 |
|
| 59 |
+
The repository contains two files required for inference. The model weights file contains the trained parameters of the BERT encoder plus the classification head. The tokenizer file contains the BPE vocabulary and merge rules trained on English Wikipedia, including special tokens required for the model.
|
| 60 |
+
|
| 61 |
+
| File | Size | Description |
|
| 62 |
+
|------|------|-------------|
|
| 63 |
+
| `deycoding.compliance-classifier-in-1-0.pt` | ~441 MB | Model weights (PyTorch state_dict, FP32) |
|
| 64 |
+
| `deycoding.compliance-classifier-in-1-0.json` | ~2 MB | BPE Tokenizer (32K vocab, trained on Wikipedia) |
|
| 65 |
|
| 66 |
## Architecture
|
| 67 |
|
| 68 |
+
The model uses a standard BERT encoder architecture β a bidirectional transformer that attends to all tokens simultaneously (no causal mask). This is fundamentally different from decoder-only models like GPT which can only see past tokens. The bidirectional attention is critical for classification tasks because the model needs to understand the full context of a query before making a routing decision. The classification is performed on the first token's hidden state, which aggregates information from the entire input sequence through self-attention.
|
| 69 |
+
|
| 70 |
- **Type:** BERT Encoder (bidirectional transformer, no causal mask)
|
| 71 |
- **Dimensions:** 768
|
| 72 |
- **Layers:** 12
|
| 73 |
- **Attention Heads:** 12
|
| 74 |
- **FFN Dimension:** 3072
|
| 75 |
- **Max Sequence Length:** 128 tokens (inference) / 512 tokens (pre-training)
|
| 76 |
+
- **Vocabulary:** 32,000 (BPE, includes `<mask>` token at ID=4)
|
| 77 |
+
- **Activation:** GELU (standard for BERT-family models)
|
| 78 |
+
- **Normalization:** LayerNorm (pre-norm variant)
|
| 79 |
- **Classification Head:** Linear(768β768) β Tanh β Dropout β Linear(768β4)
|
| 80 |
|
| 81 |
## Training
|
| 82 |
|
| 83 |
+
The model was trained in two phases following the standard pre-train then fine-tune paradigm. Pre-training teaches the model general English language understanding through the Masked Language Model (MLM) objective β predicting randomly masked tokens from context. Fine-tuning then specializes this general understanding into the specific 4-class classification task using labeled FSI examples.
|
| 84 |
+
|
| 85 |
### Pre-training
|
| 86 |
+
|
| 87 |
+
Pre-training was conducted on English Wikipedia (2B tokens) using the Masked Language Model objective. During each training step, 15% of input tokens are randomly masked (80% replaced with [MASK], 10% replaced with random token, 10% kept unchanged), and the model learns to predict the original tokens. This teaches deep contextual understanding of English language patterns, grammar, and world knowledge β providing a strong foundation for downstream classification.
|
| 88 |
+
|
| 89 |
- **Objective:** Masked Language Model (MLM), 15% masking (80/10/10)
|
| 90 |
+
- **Data:** English Wikipedia (2B tokens processed over 500K steps)
|
| 91 |
- **Batch size:** 8, sequence length: 512
|
| 92 |
+
- **Learning Rate:** 1e-4 β 1e-5 (cosine schedule, warmup 2000 steps)
|
| 93 |
+
- **Optimizer:** AdamW (betas=0.9/0.999, weight_decay=0.01)
|
| 94 |
- **Hardware:** NVIDIA L4 (24 GB), ~48 hours
|
| 95 |
+
- **Precision:** BF16 mixed precision with gradient checkpointing
|
| 96 |
- **Final Loss:** 1.815
|
| 97 |
|
| 98 |
### Fine-tuning
|
| 99 |
+
|
| 100 |
+
Fine-tuning was performed on 50,000 synthetic FSI examples carefully designed to cover the full spectrum of query types encountered in financial services. The training data includes 14 different PII types in multiple formats (structured and unstructured), Hinglish code-mixed queries (15% of dataset), and diverse prefix/suffix variations to prevent the model from memorizing specific patterns. The classification head is trained on top of the pre-trained encoder with a lower learning rate to preserve learned representations.
|
| 101 |
+
|
| 102 |
- **Data:** 50,000 synthetic FSI examples (balanced, 12,500 per class)
|
| 103 |
- **PII Types:** 14 (PAN, Aadhaar, phone, email, UPI, DOB, card, DL, voter, passport, address, IFSC)
|
| 104 |
- **Input Formats:** Structured + unstructured (human-typed messy input)
|
| 105 |
+
- **Languages:** English + Hinglish (15% code-mixed)
|
| 106 |
+
- **Steps:** 8,000, batch=32, sequence length=128
|
| 107 |
+
- **Learning Rate:** 2e-5 β 2e-6 (cosine schedule)
|
| 108 |
- **Hardware:** NVIDIA L4, ~15 minutes
|
| 109 |
- **Final Accuracy:** 99.2%
|
| 110 |
|
| 111 |
## Usage
|
| 112 |
|
| 113 |
+
Using this model requires defining the BERT architecture (as the weights are stored as a PyTorch state_dict without the architecture). The model accepts tokenized input with an attention mask and returns logits for 4 classes. A softmax converts logits to probabilities, and the argmax gives the predicted label.
|
| 114 |
+
|
| 115 |
```python
|
| 116 |
import torch
|
| 117 |
import torch.nn.functional as F
|
|
|
|
| 120 |
# Load tokenizer
|
| 121 |
tokenizer = Tokenizer.from_file("deycoding.compliance-classifier-in-1-0.json")
|
| 122 |
|
| 123 |
+
# Load model weights (requires architecture definition β see documentation)
|
| 124 |
model.load_state_dict(torch.load("deycoding.compliance-classifier-in-1-0.pt", map_location="cpu"))
|
| 125 |
model.eval()
|
| 126 |
|
|
|
|
| 143 |
|
| 144 |
## PII Detection Capabilities
|
| 145 |
|
| 146 |
+
The model detects 14 types of Indian PII across both structured (properly formatted) and unstructured (human-typed, messy) inputs. This is critical for real-world deployment where users rarely type identifiers in perfect format. The model learned these patterns from training data rather than using regex rules, making it robust to variations, typos, and mixed-language input that would break traditional pattern matching.
|
| 147 |
|
| 148 |
+
| PII Type | Structured Example | Unstructured Example |
|
| 149 |
+
|----------|-------------------|---------------------|
|
| 150 |
| PAN | ABCDE1234F | pan abcde1234f |
|
| 151 |
| Aadhaar | 1234 5678 9012 | aadhar no 123456789012 |
|
| 152 |
| Phone | +91-98765-43210 | my number is 9876543210 |
|
|
|
|
| 160 |
| Voter ID | ABC1234567 | voter id ABC1234567 |
|
| 161 |
| Address | Flat 4B, Tower 2, Koramangala | flat 4b tower 2 koramangala bangalore 560034 |
|
| 162 |
| IFSC | SBIN0123456 | ifsc SBIN0123456 |
|
| 163 |
+
| Name (contextual) | Amit Patel | amit patel ka balance |
|
| 164 |
|
| 165 |
## Intended Use
|
| 166 |
|
| 167 |
+
This model is designed for deployment as a lightweight, low-latency routing layer in front of LLM serving infrastructure. The primary use cases are in regulated industries where data residency requirements mandate that certain queries (those containing PII) must be processed on local infrastructure, while non-sensitive queries can be routed to cheaper cross-region compute. The model enables organizations to enforce compliance at the architectural level rather than relying on policy-based controls.
|
| 168 |
+
|
| 169 |
- Query routing in multi-tier LLM serving architectures
|
| 170 |
+
- PII detection for data residency compliance (GDPR, RBI Data Localization, India DPDP Act)
|
| 171 |
+
- Cost optimization β route simple queries to cheaper/smaller models (65-73% savings)
|
| 172 |
+
- Financial services (banking, insurance, capital markets)
|
| 173 |
+
- Healthcare (patient data routing)
|
| 174 |
+
- Legal (privileged information detection)
|
| 175 |
|
| 176 |
## Limitations
|
| 177 |
|
| 178 |
+
While the model achieves high accuracy on the test set, there are important limitations to consider before production deployment. The training data is synthetic (template-generated with variations), which means the model may not generalize perfectly to all real-world query patterns. Production deployment should include a feedback loop where misclassified queries are collected and used to improve subsequent training iterations.
|
| 179 |
+
|
| 180 |
+
- Trained on synthetic data β recommend fine-tuning on real customer queries for production
|
| 181 |
+
- English + Hinglish only β other Indian languages (Tamil, Telugu, Bengali, etc.) not covered
|
| 182 |
+
- Max 128 tokens β very long queries get truncated, potentially losing PII at the end
|
| 183 |
+
- PII detection is learned (not regex) β may miss novel PII formats not represented in training data
|
| 184 |
+
- No entity extraction β model detects presence of PII but doesn't extract or mask specific values
|
| 185 |
+
- Confidence calibration not verified β high confidence doesn't guarantee correctness on out-of-distribution inputs
|
| 186 |
|
| 187 |
## Ethical Considerations
|
| 188 |
|
| 189 |
+
This model is designed to enhance privacy and compliance, not to circumvent it. The routing decisions enforce data residency by ensuring PII-containing queries physically cannot reach cross-region infrastructure. The model makes conservative decisions β when uncertain, it defaults to the most restrictive routing (local processing), preferring false positives (unnecessary local routing) over false negatives (PII leaking to cross-region).
|
| 190 |
+
|
| 191 |
- Model makes routing decisions, not content decisions
|
| 192 |
+
- PII detection is conservative (prefers false positive over missed PII)
|
| 193 |
- Data residency enforcement is architectural β PII queries physically cannot reach cross-region infrastructure
|
| 194 |
+
- No user data is stored or logged by the model itself
|
| 195 |
+
- Model should be part of a defense-in-depth strategy, not the sole PII control
|
| 196 |
|
| 197 |
## Citation
|
| 198 |
|
| 199 |
+
If you use this model in your research or product, please cite:
|
| 200 |
+
|
| 201 |
```bibtex
|
| 202 |
@misc{dey2026classifier,
|
| 203 |
title={Classifier-Gated Multi-Tier LLM Routing for Cost-Optimized Serving in Regulated Industries},
|
| 204 |
author={Abhishek Dey},
|
| 205 |
year={2026},
|
| 206 |
+
url={https://huggingface.co/deycoding/deycoding-compliance-classifier-router}
|
| 207 |
}
|
| 208 |
```
|
| 209 |
|
|
|
|
| 214 |
|
| 215 |
## License
|
| 216 |
|
| 217 |
+
This model is released under CC-BY-NC-4.0 (Creative Commons Attribution Non-Commercial 4.0 International). You are free to use, share, and adapt this model for non-commercial purposes with appropriate attribution. Commercial use requires written permission from the author. Contact for commercial licensing inquiries.
|