small-lm-data-element
A 22.8M-parameter shared encoder (nreimers/MiniLM-L6-H384-uncased) fine-tuned with
two heads: a binary gate that decides whether a short column-name or abbreviation string
(e.g. fst_nm, dob, created_at) is personal data at all, and a 258-way head that picks its
canonical Data Element label (e.g. First Name, Date of Birth) -- but only when the gate
says it's PII. Not-PII inputs (timestamps, surrogate keys, auth/session internals, storage
metadata, ...) never have to be forced into one of the 258 classes, which is what a single-head
classifier with no reject option does, and does badly: an audit of an earlier single-head version
of this model found it confidently mapping claims to "Claim History", nonce to "Dietary
Preferences", and is_sso_user to "SSN (Social Security Number) (US)" at 95%+ confidence, because
it had no way to say "this isn't PII" at all. A confidence threshold doesn't fix that either: right
and wrong predictions have overlapping confidence distributions, so no cutoff cleanly separates them.
Benchmarks
- End-to-end accuracy (gate right, and type right if PII): 96.22% (8880 held-out examples)
- PII gate: accuracy 99.07%, precision 99.28%, recall 99.48%, F1 99.38%
- Type accuracy given true PII: 95.75% (6686 PII rows)
- CPU inference latency: 1.89 ms/example (single thread, batch size 1)
- Best epoch: 49, validation end-to-end accuracy 96.85%
Lowest-accuracy categories on the test set (PII rows only):
| Category | Accuracy |
|---|---|
| Health & Biometric Data | 84.6% |
| Service & Booking Data | 91.0% |
| Device & Technology Data | 91.7% |
| Employment Data | 92.9% |
| Identity Data | 93.4% |
Out-of-distribution benchmark
The test set above is drawn from the same spreadsheet + synthetic-augmentation pipeline as
training, so it doesn't show how the model handles real column names it's never seen a naming
pattern for. Checked against four independent sources: real dataset column names from
trl-lab/contextual-sensitive-data,
both mapped onto this label set and kept as not-PII negatives (128 rows), real
field names from public API/schema vocabularies (Salesforce, Schema.org, Stripe, Shopify,
FHIR/OpenMRS) hand-labeled against these 258 Data Elements (64 rows), a
fresh PII batch (26 rows) from systems (Workday, Okta, Twilio, PayPal,
HubSpot, GitHub, DMV) added only after the training data below was finalized, and a fresh
not-PII batch (24 rows) of system/infra field names (AWS, Kafka,
Datadog, Segment) added the same way, to get an uncontaminated read on the gate.
Combined: 90.9% (85.9% / 96.9% / 92.3% / 100.0% on the four sources). Take the first two with a grain of salt — some of their miss-words ended up in this model's training vocabulary, so part of that score is memorization. The two fresh sources are the honest numbers: real generalization to column names and naming styles never targeted during training. Known limitation — don't rely on this for unseen real schemas without more representative training data.
Training data
Trained on a dataset of data-element names and their abbreviations/case-variants (e.g.
first_name -> fname, f_nm, firstName, ...), expanded with synthetically generated
naming-style and abbreviation-pattern variants, plus a separate not-PII set of system/technical
column names generated the same way and real negatives from trl-lab/contextual-sensitive-data
(see the fieldmap repo for the generation scripts).
Usage
This is a custom dual-head architecture (modeling_dual_head.py, shipped in this repo), not a
standard AutoModelForSequenceClassification -- loading it needs trust_remote_code=True:
from transformers import AutoTokenizer, AutoModel
import torch
tok = AutoTokenizer.from_pretrained("sairaamv1/small-lm-data-element")
model = AutoModel.from_pretrained("sairaamv1/small-lm-data-element", trust_remote_code=True)
type_labels = model.config.id2type_label
inputs = tok("fst_nm", return_tensors="pt")
out = model(**inputs)
if out.pii_logits.argmax(-1).item() == 1:
print(type_labels[str(out.type_logits.argmax(-1).item())])
else:
print("not PII")