PII 30M Core ML (Neural Engine) v1.1

PII 30M MLX 4-bit v1.1 as a Core ML program for the Apple Neural Engine: the same four-layer BERT token classifier, which labels each span of personal information with one of 21 classes, for local detection and redaction.

Model details

  • Source: the MLX release at revision d7d419e83f8f2e4b403bfafedb9dcd860d53f80b, written directly in Core ML's MIL with coremltools 9.
  • Weights: the embedding tables keep the release's 4-bit weights exactly (blockwise, 64-element blocks, its scales and offsets). The linear layers are the release's weights dequantized to float16, because the Neural Engine runs only per-channel weights. Activations are float16.
  • Size: about 33 MB.
  • Requires: macOS 15 or iOS 18 (ML program, Core ML 8).
  • Runs on: the Neural Engine with cpuAndNeuralEngine, except the embedding lookups, which run on the CPU; also on the GPU with cpuAndGPU.

Inputs and output

Every input has a fixed shape: four rows of 512 tokens. A row may hold several windows of several texts one after another; a window doesn't cross rows.

Name Shape Type Meaning
ids 4 ร— 512 int32 WordPiece token ids (the MLX release's tokenizer.json), each window [CLS] โ€ฆ [SEP]; padding [PAD] (0)
positions 4 ร— 512 int32 each token's position in its own window, from 0
segments 4 ร— 512 int32 each token's window, any number unique in its row; a token attends only to the tokens of its segment
logits (output) 4 ร— 512 ร— 43 float32 each token's scores for O, then B- and I- of each label, in the order of the MLX release's config.json (id2label)

Tokenize with the MLX release's tokenizer: windows of 512 tokens that share 64 tokens with the window before. Decode as its runtime does; bio_decode.py and pii_rules.py here are the same files:

  1. bio_decode.char_classes: each token's label, the first window's where windows overlap, gives its characters a class; an I- token continuing the same class also covers the whitespace before it.
  2. pii_rules.apply: email addresses, payment card numbers (Luhn), IBANs (country format and mod-97), IP addresses and US social security numbers. A rule match the model missed, or labeled only in part, takes the rule's label.
  3. bio_decode.join_whitespace and bio_decode.spans: same-class runs separated only by whitespace join, then each run is one span.

Labels

Redacted by default in the MLX release: PERSON, EMAIL, PHONE, STREET_ADDRESS, COORDINATE, DATE_OF_BIRTH, GOV_ID, HEALTH_ID, FINANCIAL, CREDENTIAL, USERNAME, ACCOUNT_ID, NETWORK_ID, SENSITIVE_TRAIT. Detected and kept by default: DATE_TIME, LOCATION, ORGANIZATION, TITLE, URL, DEMOGRAPHIC, OCCUPATION.

Evaluation

Against the MLX release's runtime (4-bit weights, float32 compute), both with the decoding and rules above, on a held-out set of 10,000 texts (plain text, JSON, HTML, XML and SQL, in 25 languages):

  • 98.6% of texts get exactly the same spans and labels.
  • Of the characters the MLX release labels, 0.078% are missed and 0.025% get another label; 245 characters are labeled that it doesn't. The differences come from float16 arithmetic.
  • Speed: with one 512-token window per row, the 11,821 windows took 75.5 s on an M5 Max's Neural Engine from Python (about 26 ms per call of four rows, including Python overhead).

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. The same terms as the MLX release.

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
13
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for LoyalAI/pii-30M-coreml-ane-v1.1

Quantized
(1)
this model