1.58 GB
12 files
Updated 5 days ago
Name
Size
onnx
.gitattributes1.57 kB
xet
LICENSE11.4 kB
xet
NOTICE3.86 kB
xet
README.md10.6 kB
xet
config.json15.8 kB
xet
model.safetensors563 MB
xet
piily_onnx.py6.51 kB
xet
tokenizer.json34.4 MB
xet
tokenizer_config.json572 Bytes
xet
README.md

PiiLy

Finds personal data (PII) in text, so that you can mask it: names, e-mails, phone numbers, addresses, IDs, bank data, passwords, health facts and more.

  • 70 classes, 6 languages: English, French, Spanish, German, Italian, Portuguese.
  • Small: mmBERT-small, 22 layers. Runs on a CPU. The smallest file is 141.8 MB.
  • Apache-2.0.

Need a smaller and faster model? See PiiLy small: about 2 times faster, a bit less accurate.

Quick start

pip install onnxruntime==1.32.0 tokenizers==0.23.3 numpy==2.5.5 huggingface_hub
hf download julienwuthrich-anthropic/piily --local-dir piily
cd piily
from piily_onnx import PiiLy, mask

piily = PiiLy(".")
text = "Dear Ms Keller, we will call +41 44 555 01 23 or write to anna.keller@example.com."
spans = piily.detect(text)   # [(start, end, class), ...]
print(spans)
print(mask(text, spans))
[(8, 14, 'PERSON_NAME'), (29, 45, 'PHONE'), (58, 81, 'EMAIL')]
Dear Ms [PERSON_NAME], we will call [PHONE] or write to [EMAIL].

Choose what to mask

The model knows 70 classes. If you change nothing, it masks 38 of them: the classes that point to one person or give access to something (names, contact data, ID numbers, bank data, passwords). This is what masked by default means. The other 32 classes (for example ORGANIZATION, DATE, AMOUNT, HEALTH_CONDITION) are found too, but they are masked only when you ask for them:

PiiLy(".", add=["ORGANIZATION", "DATE"])    # the default classes + these two
PiiLy(".", remove=["POSTAL_CODE"])          # the default classes without this one
PiiLy(".", classes="all")                   # all 70 classes
PiiLy(".", classes=["EMAIL", "PHONE"])      # only these classes
PiiLy(".", threshold=0.3)                   # default 0.5. Lower = misses less, masks more ordinary text
PiiLy(".", onnx_file="onnx/model.onnx")     # another file of the table below

The two tables under "Scores per class" list all 70 classes.

Files

file size for P R F1 time per document
onnx/model.onnx 563.4 MB CPU, best accuracy 95.6 96.6 96.1 88 ms
onnx/model_fp16.onnx 282.3 MB GPU 95.6 96.7 96.1 -
onnx/model_int8.onnx 141.8 MB CPU, smallest file 95.9 95.7 95.8 89 ms
bardsai (INT8), for comparison 308.6 MB CPU 95.4 92.5 94.0 67 ms
  • P (precision): of the text that the model masked, the share that was personal data. R (recall): of the personal data, the share that the model masked. F1: both in one number. All in %, higher is better.
  • Scores: 5 test sets that the model never saw in training (4 public, 1 of ours), default threshold 0.5.
  • Time: median of 200 real documents (about 270 tokens each), 4 CPU threads, Intel Xeon Platinum 8570.
  • bardsai = bardsai/eu-pii-anonimization-multilang-v3, run by us on the same tests.
  • model.safetensors holds the same weights for PyTorch / transformers.

Scores per class

Test: 3,048 documents in the 6 languages with all 70 classes, threshold 0.5, file onnx/model.onnx. With the default classes the model masks 98.5% of the personal data of this test. The documents were written by an AI model for this project. They are not real documents, so real text can score lower.

P, R and F1 are for the class itself, in %. bardsai = the share of the values of the class that bardsai masks. bardsai has other classes than ours, so a value counts when bardsai masks it with any of its labels, and there is no P for it.

Masked by default (38 classes)

class what it is P R F1 bardsai
API_KEY_TOKEN API key or access token 63.7 98.1 77.3 80.2
BANK_ACCOUNT IBAN or bank account number 96.6 99.0 97.8 94.3
BANK_ROUTING_CODE BIC, routing number or sort code 88.7 98.8 93.5 48.2
BIOMETRIC_ID id of a fingerprint, face or iris record 94.8 83.9 89.0 65.2
CARD_EXPIRY card expiry date 99.2 94.0 96.6 33.6
CARD_SECURITY_CODE card security code (CVV) 97.3 77.6 86.3 24.4
COMPANY_ID company register or VAT number 97.0 93.7 95.3 85.7
CRYPTO_WALLET crypto wallet address 96.8 97.5 97.1 55.2
CUSTOMER_ID customer, member or policy number 79.9 71.2 75.3 62.6
DATE_OF_BIRTH date of birth 99.5 99.2 99.3 94.1
DEVICE_ID MAC address, IMEI or serial number 94.2 76.1 84.2 76.8
DRIVING_LICENCE_NUMBER driving licence number 90.8 98.4 94.5 99.6
EMAIL e-mail address 99.9 99.7 99.8 95.3
EMPLOYEE_STUDENT_ID employee or student number 87.1 86.7 86.9 70.6
GEO_COORDINATES latitude and longitude 98.9 99.8 99.4 62.4
HEALTH_ID health insurance or patient number 83.0 73.7 78.1 76.2
IP_ADDRESS IP address 98.5 99.6 99.1 92.0
NATIONAL_ID national identity number 87.1 88.5 87.8 97.4
ONLINE_ID cookie, advertising or app id 96.5 53.8 69.1 46.3
PASSPORT_NUMBER passport number 86.4 100.0 92.7 100.0
PASSWORD password or passphrase 98.6 85.4 91.5 82.5
PAYMENT_CARD payment card number 96.4 99.8 98.1 100.0
PERSON_NAME name of a person 99.7 99.3 99.5 97.6
PHONE phone or fax number 98.4 99.4 98.9 99.0
PIN_OR_CODE PIN, one-time code or door code 91.0 85.3 88.0 63.3
PLACE_OF_BIRTH place of birth 98.1 97.5 97.8 94.3
POSTAL_CODE postal code written alone 90.6 94.3 92.4 87.5
PRIVATE_KEY private key or seed phrase 98.0 98.1 98.1 21.2
PROFESSIONAL_LICENCE licence number of a doctor, lawyer, ... 96.6 85.2 90.5 76.2
PROFILE_URL link to the profile of one person 99.7 98.8 99.2 19.5
PROPERTY_ID meter, land parcel or supply point number 99.6 71.7 83.4 94.5
RESIDENCE_PERMIT visa or residence permit number 94.3 73.3 82.5 90.1
SOCIAL_SECURITY_NUMBER social security number 91.9 89.8 90.8 99.1
STREET_ADDRESS street address 99.3 99.1 99.2 97.9
TAX_ID personal tax number 82.6 96.0 88.8 98.3
TRAVEL_BOOKING_REFERENCE flight, rail or hotel booking reference 96.7 68.0 79.8 83.7
USERNAME login or handle 91.7 97.8 94.7 84.1
VEHICLE_ID number plate or VIN 90.6 97.8 94.1 88.3

Masked only when you ask (32 classes)

class what it is P R F1 bardsai
AGE age of a person 94.9 97.3 96.1 33.0
AMOUNT amount of money 97.9 94.8 96.4 31.7
CASE_NUMBER court case, police report or claim number 89.1 63.9 74.4 20.8
CRIMINAL_RECORD offence, charge, conviction or sentence 88.0 55.2 67.8 0.2
DATE date that is not a date of birth 99.0 99.3 99.1 82.8
EDUCATION degree, school level or grade 93.0 70.8 80.4 24.3
ETHNICITY ethnic origin 92.1 77.4 84.1 21.5
GENDER sex or gender 98.8 91.8 95.2 63.2
GENETIC_DATA gene, variant or genetic test 93.9 47.1 62.7 4.4
HEALTH_CONDITION diagnosis, symptom, allergy or disability 83.4 79.8 81.5 0.3
HOSTNAME internal computer or network name 91.1 79.9 85.1 32.0
INCOME salary, pension or account balance 91.0 72.8 80.9 47.1
LOCATION town, district or named place 92.4 91.6 92.0 79.2
MARITAL_STATUS marital status 91.8 81.9 86.5 19.2
MEDICAL_CODE diagnosis or drug code (ICD-10, ATC) 96.8 77.7 86.2 12.6
MEDICAL_PROCEDURE surgery, examination or therapy 83.9 42.6 56.5 0.3
MEDICAL_TEST_RESULT lab value, blood pressure, blood type 94.0 60.5 73.6 0.9
MEDICATION drug that a person takes, with its dose 87.6 85.2 86.4 1.4
MENTAL_HEALTH psychiatric condition or therapy 90.6 75.8 82.5 0.7
NATIONALITY nationality or citizenship 87.6 83.3 85.4 21.2
OCCUPATION job or job title 92.7 79.8 85.8 26.4
ORGANIZATION name of a company or institution 88.3 93.4 90.8 55.7
PARTIAL_IDENTIFIER partly hidden value (**** 4417) 94.4 97.0 95.7 35.2
PHYSICAL_DESCRIPTION height, weight, hair, scar, tattoo 97.5 47.3 63.7 0.6
POLITICAL_OR_UNION political opinion, party or union membership 76.5 88.7 82.1 38.6
REFERENCE_NUMBER order, invoice or ticket number 73.0 69.9 71.4 53.5
REGION_OR_COUNTRY country, state or region 93.1 86.7 89.8 50.3
RELIGION religion or belief 88.8 60.9 72.2 45.9
SEXUAL_ORIENTATION sexual orientation 95.5 33.4 49.5 23.7
SUBSTANCE_USE use of tobacco, alcohol or drugs 88.4 61.4 72.5 1.0
TIMESTAMP date with clock time (log line) 99.8 98.3 99.0 75.1
URL web address 97.0 99.0 98.0 28.8

Good to know

  • Six languages only. Other languages were not tested.
  • The training data is public: piily-dataset, 72,461 documents.
  • The model was trained on synthetic text only (no real personal data): documents written by Claude models for this project, and rows of OpenPII 1M and Nemotron-PII.
  • The INT8 file can give slightly different spans on another CPU type. The FP32 and FP16 files do not.
  • A detector is not a guarantee. Add a human check where a miss causes harm.

Licence

Apache-2.0 (LICENSE). Credits for the base model mmBERT-small (MIT) and the training data (OpenPII 1M by Ai4Privacy, Nemotron-PII by NVIDIA, both CC BY 4.0) are in NOTICE.

Total size
1.58 GB
Files
12
Last updated
Nov 29
Pre-warmed CDN
US EU US EU

Contributors