EC2 Default User commited on
Commit
9ad9142
·
1 Parent(s): 36e7d8f

Clean slate: remove all files for v2 upload

Browse files
.gitattributes DELETED
@@ -1,35 +0,0 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md DELETED
@@ -1,218 +0,0 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- language:
4
- - en
5
- - hi
6
- tags:
7
- - encoder
8
- - classifier
9
- - compliance
10
- - pii-detection
11
- - fsi
12
- - query-routing
13
- - financial-services
14
- - india
15
- library_name: pytorch
16
- pipeline_tag: text-classification
17
- model-index:
18
- - name: deycoding.compliance-classifier-in-1-0
19
- results:
20
- - task:
21
- type: text-classification
22
- metrics:
23
- - name: Accuracy
24
- type: accuracy
25
- value: 99.2
26
- ---
27
-
28
- # Indian Compliance Classifier Router
29
-
30
- A ~140M parameter 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.
31
-
32
- 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.
33
-
34
- ## Model Description
35
-
36
- 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.
37
-
38
- The model outputs one of four labels, each mapping directly to a routing action:
39
-
40
- | Label | Complexity | PII | Routing Action |
41
- |-------|-----------|-----|----------------|
42
- | `simple_no_pii` | Low | No | Small model, cross-region allowed |
43
- | `simple_pii` | Low | Yes | Small model, local only (data residency) |
44
- | `complex_no_pii` | High | No | Large model, cross-region allowed |
45
- | `complex_pii` | High | Yes | Large model, local only (data residency) |
46
-
47
- ## Key Results
48
-
49
- 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.
50
-
51
- - **Accuracy:** 99.2%
52
- - **PII Recall:** ~100% (conservative - prefers false positive over missed PII)
53
- - **Latency:** ~7ms (GPU) / ~72ms (CPU)
54
- - **Throughput:** ~130 queries/sec per GPU instance
55
- - **Model Size:** ~140M parameters / ~530 MB on disk
56
- - **Inference Memory:** ~530 MB VRAM (fits on any GPU including T4 16GB)
57
-
58
- ## Files
59
-
60
- The repository contains two files required for inference. The model weights file contains the trained parameters of the 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.
61
-
62
- | File | Size | Description |
63
- |------|------|-------------|
64
- | `deycoding.compliance-classifier-in-1-0.pt` | ~441 MB | Model weights (PyTorch state_dict, FP32) |
65
- | `deycoding.compliance-classifier-in-1-0.json` | ~2 MB | BPE Tokenizer (32K vocab, trained on Wikipedia) |
66
-
67
- ## Architecture
68
-
69
- The model uses a bidirectional transformer encoder architecture 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.
70
-
71
- - **Type:** Bidirectional Transformer Encoder (no causal mask)
72
- - **Dimensions:** 768
73
- - **Layers:** 12
74
- - **Attention Heads:** 12
75
- - **FFN Dimension:** 3072
76
- - **Max Sequence Length:** 128 tokens (inference) / 512 tokens (pre-training)
77
- - **Vocabulary:** 32,000 (BPE, includes special tokens)
78
- - **Activation:** GELU
79
- - **Normalization:** LayerNorm (pre-norm variant)
80
- - **Classification Head:** Linear(768-768) - Tanh - Dropout - Linear(768-4)
81
-
82
- ## Training
83
-
84
- 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.
85
-
86
- ### Pre-training
87
-
88
- 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 token, 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.
89
-
90
- - **Objective:** Masked Language Model (MLM), 15% masking (80/10/10)
91
- - **Data:** English Wikipedia (2B tokens processed over 500K steps)
92
- - **Batch size:** 8, sequence length: 512
93
- - **Learning Rate:** 1e-4 to 1e-5 (cosine schedule, warmup 2000 steps)
94
- - **Optimizer:** AdamW (betas=0.9/0.999, weight_decay=0.01)
95
- - **Hardware:** NVIDIA L4 (24 GB), ~48 hours
96
- - **Precision:** BF16 mixed precision with gradient checkpointing
97
- - **Final Loss:** 1.815
98
-
99
- ### Fine-tuning
100
-
101
- 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.
102
-
103
- - **Data:** 50,000 synthetic FSI examples (balanced, 12,500 per class)
104
- - **PII Types:** 14 (PAN, Aadhaar, phone, email, UPI, DOB, card, DL, voter, passport, address, IFSC)
105
- - **Input Formats:** Structured + unstructured (human-typed messy input)
106
- - **Languages:** English + Hinglish (15% code-mixed)
107
- - **Steps:** 8,000, batch=32, sequence length=128
108
- - **Learning Rate:** 2e-5 to 2e-6 (cosine schedule)
109
- - **Hardware:** NVIDIA L4, ~15 minutes
110
- - **Final Accuracy:** 99.2%
111
-
112
- ## Usage
113
-
114
- Using this model requires defining the encoder 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.
115
-
116
- ```python
117
- import torch
118
- import torch.nn.functional as F
119
- from tokenizers import Tokenizer
120
-
121
- # Load tokenizer
122
- tokenizer = Tokenizer.from_file("deycoding.compliance-classifier-in-1-0.json")
123
-
124
- # Load model weights (requires architecture definition - see documentation)
125
- model.load_state_dict(torch.load("deycoding.compliance-classifier-in-1-0.pt", map_location="cpu"))
126
- model.eval()
127
-
128
- # Classify a query
129
- text = "Check balance for Amit Patel account 4532-8876-1234"
130
- ids = tokenizer.encode(text).ids[:128]
131
- pad_len = 128 - len(ids)
132
- input_ids = torch.tensor([ids + [0] * pad_len])
133
- attn_mask = torch.tensor([[1] * len(ids) + [0] * pad_len])
134
-
135
- with torch.no_grad():
136
- probs = F.softmax(model(input_ids, pad_mask=attn_mask), dim=-1)
137
-
138
- labels = ["simple_no_pii", "simple_pii", "complex_no_pii", "complex_pii"]
139
- prediction = labels[probs.argmax().item()]
140
- confidence = probs.max().item() * 100
141
- print(f"{prediction} ({confidence:.1f}%)")
142
- # Output: simple_pii (100.0%)
143
- ```
144
-
145
- ## PII Detection Capabilities
146
-
147
- 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.
148
-
149
- | PII Type | Structured Example | Unstructured Example |
150
- |----------|-------------------|---------------------|
151
- | PAN | ABCDE1234F | pan abcde1234f |
152
- | Aadhaar | 1234 5678 9012 | aadhar no 123456789012 |
153
- | Phone | +91-98765-43210 | my number is 9876543210 |
154
- | Email | name@gmail.com | name at gmail dot com |
155
- | UPI | name@oksbi | my upi is 9876@paytm |
156
- | Account | 1234-5678-9012 | a/c 12345678 |
157
- | Card | XXXX-XXXX-XXXX-1234 | card ending 1234 |
158
- | DOB | 15/03/1990 | born on 15 march 1990 |
159
- | DL | MH-0120190012345 | dl number mh01 2019 0012345 |
160
- | Passport | J1234567 | passport J1234567 |
161
- | Voter ID | ABC1234567 | voter id ABC1234567 |
162
- | Address | Flat 4B, Tower 2, Koramangala | flat 4b tower 2 koramangala bangalore 560034 |
163
- | IFSC | SBIN0123456 | ifsc SBIN0123456 |
164
- | Name (contextual) | Amit Patel | amit patel ka balance |
165
-
166
- ## Intended Use
167
-
168
- 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.
169
-
170
- - Query routing in multi-tier LLM serving architectures
171
- - PII detection for data residency compliance (GDPR, RBI Data Localization, India DPDP Act)
172
- - Cost optimization - route simple queries to cheaper/smaller models (65-73% savings)
173
- - Financial services (banking, insurance, capital markets)
174
- - Healthcare (patient data routing)
175
- - Legal (privileged information detection)
176
-
177
- ## Limitations
178
-
179
- 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.
180
-
181
- - Trained on synthetic data - recommend fine-tuning on real customer queries for production
182
- - English + Hinglish only - other Indian languages (Tamil, Telugu, Bengali, etc.) not covered
183
- - Max 128 tokens - very long queries get truncated, potentially losing PII at the end
184
- - PII detection is learned (not regex) - may miss novel PII formats not represented in training data
185
- - No entity extraction - model detects presence of PII but does not extract or mask specific values
186
- - Confidence calibration not verified - high confidence does not guarantee correctness on out-of-distribution inputs
187
-
188
- ## Ethical Considerations
189
-
190
- 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).
191
-
192
- - Model makes routing decisions, not content decisions
193
- - PII detection is conservative (prefers false positive over missed PII)
194
- - Data residency enforcement is architectural - PII queries physically cannot reach cross-region infrastructure
195
- - No user data is stored or logged by the model itself
196
- - Model should be part of a defense-in-depth strategy, not the sole PII control
197
-
198
- ## Citation
199
-
200
- If you use this model in your research or product, please cite:
201
-
202
- ```bibtex
203
- @misc{dey2026classifier,
204
- title={Indian Compliance Classifier Router: Multi-Tier LLM Routing for Regulated Industries},
205
- author={Abhishek Dey},
206
- year={2026},
207
- url={https://huggingface.co/deycoding/deycoding-compliance-classifier-router}
208
- }
209
- ```
210
-
211
- ## Author
212
-
213
- **Abhishek Dey**
214
- - HuggingFace: [deycoding](https://huggingface.co/deycoding)
215
-
216
- ## License
217
-
218
- 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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
deycoding.compliance-classifier-in-1-0.json DELETED
The diff for this file is too large to render. See raw diff
 
deycoding.compliance-classifier-in-1-0.pt DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:4b8d98aff65ef2cdf39b8476c53341ed7308a53bfaa08289874f1e81ddd6554e
3
- size 441368485