Views
No views yet
In the era of massive LLMs, sometimes the smartest solution is the smallest one.
12/05/2024 for IP addresses).1Input: "Schedule a meeting with John in London on Friday"
2Output: {
3 "NER": 0.99, // -> Trigger Name Extractor
4 "ADDRESS": 0.98, // -> Trigger Geocoder
5 "TEMPORAL": 0.95, // -> Trigger Date Parser
6 "REGEX": 0.01 // -> Skip Regex Engine (Save Compute)
7}
8The Ambiguity:
Is a Date a Regex? A date like12/05/2024fits a regex pattern. But semantically, it belongs to the TEMPORAL engine, not the REGEX scanner. Is a State a Name? "California" is technically a Named Entity (NER). But for routing purposes, it must be sent to the Geocoder (ADDRESS), not the Person/Org extractor.
| Source Tag | Action | Destination Engine (Label) |
|---|---|---|
| DATE / TIME | Removed from Regex | TEMPORAL |
| CITY / STATE / ZIP | Removed from NER | ADDRESS |
| IP / EMAIL / IBAN | Kept in Regex | REGEX |
| PERSON / ORG | Kept in NER | NER |
TinyBERT) was forced to mimic the "soft targets" (thought process) of the teacher (XLM-RoBERTa), not just the final labels.| Model | Parameters | Size | Throughput | F1 Retention |
|---|---|---|---|---|
| Teacher (XLM-R) | 278M | ~1 GB | ~360 samples/sec | 100% (Baseline) |
| Student (TinyBERT) | 11M | 42 MB | ~3,300 samples/sec | 96% |

1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "pinialt/bert-tiny-pii-router"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8def route_query(text, threshold=0.5):
9 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
10
11 with torch.no_grad():
12 logits = model(**inputs).logits
13
14 # Sigmoid for multi-label (independent probabilities)
15 probs = torch.sigmoid(logits)[0]
16
17 # Map IDs to Labels
18 active_routes = [
19 model.config.id2label[i]
20 for i, score in enumerate(probs)
21 if score > threshold
22 ]
23
24 if not active_routes:
25 return "⚡ Direct to LLM (No PII)"
26
27 return f"🚦 Route to Engines: {', '.join(active_routes)}"
28
29# === EXAMPLES ===
30# 1. Complex Multi-Entity Request
31print(route_query("Schedule a meeting with John in London on Friday"))
32# Output: 🚦 Route to Engines: NER, ADDRESS, TEMPORAL
33
34# 2. Pure Address
35print(route_query("Ship to 123 Main St, New York, NY"))
36# Output: 🚦 Route to Engines: ADDRESS
37xlm-roberta-basegoogle/bert_uncased_L-4_H-256_A-4ai4privacy/pii-masking-65k (Filtered & Purified)@article{turc2019,
title={Well-Read Students Learn Better: On the Importance of Pre-training Compact Models},
author={Turc, Iulia and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
journal={arXiv preprint arXiv:1908.08962v2 },
year={2019}
}