Instructions to use LoyalAI/pii-30M-mlx-4bit-v1.2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use LoyalAI/pii-30M-mlx-4bit-v1.2 with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download LoyalAI/pii-30M-mlx-4bit-v1.2 --local-dir pii-30M-mlx-4bit-v1.2
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
PII 30M MLX 4-bit v1.2
A compact model for local detection and redaction of personally identifiable information (PII), packaged for Apple Silicon with MLX.
The model labels every span with what it is, so redacted text stays readable. Version 1.2 labels only the street part of an address STREET_ADDRESS, and postal codes POSTAL_CODE, so redacting an address hides the street and keeps the city, region, postal code and country:
Send it to 1 Satan Street, Springfield, IL 62704, USA. Call me at (510) 555-0123.
Send it to [STREET_ADDRESS], Springfield, IL 62704, USA. Call me at [PHONE].
Designed for browser observations, form content, documents and application text. The model is English-focused, with additional multilingual coverage.
Labels
The model labels 22 classes. By default redact() replaces the first 14, which identify a person or grant access, and keeps the other 8, which are detected but usually harmless and make text easier to read. Pass your own set to change this.
| Redacted by default | Detected, kept by default |
|---|---|
PERSON names |
DATE_TIME dates and times |
EMAIL email addresses |
LOCATION cities, states, countries |
PHONE phone and fax numbers |
ORGANIZATION companies and institutions |
STREET_ADDRESS street names, house and unit numbers |
TITLE titles and honorifics |
COORDINATE geographic coordinates |
URL web addresses |
DATE_OF_BIRTH dates of birth |
DEMOGRAPHIC age, gender, nationality, language |
GOV_ID government and license numbers |
OCCUPATION occupation, education, employment status |
HEALTH_ID medical record and health plan numbers |
POSTAL_CODE ZIP and postal codes |
FINANCIAL card, bank account and IBAN numbers |
|
CREDENTIAL passwords, PINs, API keys, cookies |
|
USERNAME user names |
|
ACCOUNT_ID customer and employee IDs |
|
NETWORK_ID IP and MAC addresses, device IDs |
|
SENSITIVE_TRAIT religion, ethnicity, political views, sexuality, blood type |
Changes from v1.1
STREET_ADDRESScovers the street only: the street name, house or building number and unit. City, region and country stayLOCATION.POSTAL_CODEis new: ZIP and postal codes, kept by default.- The output layer has 45 labels instead of 43; the other 20 classes keep their v1.1 definitions, and the pattern rules are unchanged.
Pattern rules
Beside the model, pii_rules.py finds email addresses, payment card numbers (Luhn checksum), IBANs (country format and mod-97 checksum), IP addresses and US social security numbers. A rule match the model missed, or labeled only in part, takes the rule's label; a match the model labeled in full keeps the model's label. Rules are on by default; pass rules=False (or --no-rules) for the model alone.
Model details
- Parameters: 28,524,077 (approximately 28.5 million, in the 30M class). Post-trained from gravitee-io/bert-small-pii-detection.
- Quantization: affine 4-bit, group size 64, for the embedding and encoder weight matrices. The classifier, other tensors and activations remain float32.
- Weight file size: approximately 18.0 MB; complete download approximately 19 MB.
- Architecture: a four-layer BERT token classifier with a 512-token context window and BIO tags for each class (45 outputs). The included runtime handles longer text with overlapping windows.
- Input: text, including plain text, JSON, HTML, XML and browser tool output.
Usage
On an Apple Silicon Mac with Python 3.10 or later:
python -m pip install huggingface-hub
hf download ConwayResearch/pii-30M-mlx-4bit-v1.2 --local-dir pii-model
cd pii-model
python -m pip install -r requirements.txt
python pii.py --text "Hi, I am Alice Smith. Call me at (510) 555-0123."
Keep the model loaded across requests:
from pii import PIIDetector
model = PIIDetector()
text = "Hi, I am Alice Smith, a nurse in Oakland. Call me at (510) 555-0123."
model.detect(text) # [{'start': 9, 'end': 20, 'label': 'PERSON'}, ...]
model.redact(text) # default set: "Hi, I am [PERSON], a nurse in Oakland. Call me at [PHONE]."
model.redact(text, labels=None) # every label
model.redact(text, labels={"PERSON"}, replacement="***")
detect() returns start, end and label for each span. Offsets use Unicode characters with an exclusive end: text[start:end]. Inference runs locally after download.
License
CC BY-NC 4.0 (see LICENSE). You can use, share and adapt it for non-commercial purposes with credit to Underdog. Commercial use needs a separate license: write to license@conway.tech.
Upstream components keep their original licenses: the base model under Apache-2.0 (see LICENSE-APACHE), and the pattern rules, adapted from Microsoft Presidio, under MIT (see LICENSE-MIT).
- Downloads last month
- 18
Quantized