PiiLy small
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, 11 layers. Runs on a CPU. The smallest file is 72.9 MB.
- Apache-2.0.
Need the best accuracy? See PiiLy: about 2 times slower, more accurate.
Quick start
pip install onnxruntime==1.32.0 tokenizers==0.23.3 numpy==2.5.5 huggingface_hub
hf download Jwuthrich/piily-small --local-dir piily-small
cd piily-small
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 |
478.7 MB | CPU, best accuracy | 94.9 | 96.0 | 95.4 | 49 ms |
onnx/model_fp16.onnx |
239.7 MB | GPU | 94.9 | 96.0 | 95.4 | - |
onnx/model_int8.onnx |
72.9 MB | CPU, smallest file | 94.8 | 94.7 | 94.7 | 47 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.safetensorsholds 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.4% 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 | 62.9 | 97.2 | 76.4 | 80.2 |
BANK_ACCOUNT |
IBAN or bank account number | 95.1 | 98.3 | 96.7 | 94.3 |
BANK_ROUTING_CODE |
BIC, routing number or sort code | 91.8 | 97.0 | 94.3 | 48.2 |
BIOMETRIC_ID |
id of a fingerprint, face or iris record | 90.8 | 81.7 | 86.0 | 65.2 |
CARD_EXPIRY |
card expiry date | 99.2 | 92.2 | 95.6 | 33.6 |
CARD_SECURITY_CODE |
card security code (CVV) | 99.3 | 76.1 | 86.1 | 24.4 |
COMPANY_ID |
company register or VAT number | 95.6 | 88.6 | 92.0 | 85.7 |
CRYPTO_WALLET |
crypto wallet address | 94.9 | 95.9 | 95.4 | 55.2 |
CUSTOMER_ID |
customer, member or policy number | 74.3 | 57.7 | 65.0 | 62.6 |
DATE_OF_BIRTH |
date of birth | 99.8 | 98.9 | 99.4 | 94.1 |
DEVICE_ID |
MAC address, IMEI or serial number | 92.3 | 70.2 | 79.7 | 76.8 |
DRIVING_LICENCE_NUMBER |
driving licence number | 80.8 | 97.6 | 88.4 | 99.6 |
EMAIL |
e-mail address | 99.8 | 99.9 | 99.8 | 95.3 |
EMPLOYEE_STUDENT_ID |
employee or student number | 89.4 | 74.0 | 81.0 | 70.6 |
GEO_COORDINATES |
latitude and longitude | 98.6 | 99.3 | 98.9 | 62.4 |
HEALTH_ID |
health insurance or patient number | 75.3 | 72.8 | 74.0 | 76.2 |
IP_ADDRESS |
IP address | 98.1 | 99.5 | 98.8 | 92.0 |
NATIONAL_ID |
national identity number | 72.6 | 85.5 | 78.5 | 97.4 |
ONLINE_ID |
cookie, advertising or app id | 97.9 | 49.7 | 65.9 | 46.3 |
PASSPORT_NUMBER |
passport number | 81.7 | 99.2 | 89.6 | 100.0 |
PASSWORD |
password or passphrase | 93.9 | 79.2 | 85.9 | 82.5 |
PAYMENT_CARD |
payment card number | 93.2 | 99.7 | 96.3 | 100.0 |
PERSON_NAME |
name of a person | 99.4 | 99.1 | 99.3 | 97.6 |
PHONE |
phone or fax number | 97.2 | 99.1 | 98.1 | 99.0 |
PIN_OR_CODE |
PIN, one-time code or door code | 80.9 | 80.6 | 80.8 | 63.3 |
PLACE_OF_BIRTH |
place of birth | 97.9 | 96.4 | 97.1 | 94.3 |
POSTAL_CODE |
postal code written alone | 80.4 | 90.5 | 85.1 | 87.5 |
PRIVATE_KEY |
private key or seed phrase | 96.4 | 96.4 | 96.4 | 21.2 |
PROFESSIONAL_LICENCE |
licence number of a doctor, lawyer, ... | 92.3 | 75.6 | 83.1 | 76.2 |
PROFILE_URL |
link to the profile of one person | 99.5 | 98.3 | 98.9 | 19.5 |
PROPERTY_ID |
meter, land parcel or supply point number | 95.6 | 71.5 | 81.8 | 94.5 |
RESIDENCE_PERMIT |
visa or residence permit number | 93.9 | 69.4 | 79.8 | 90.1 |
SOCIAL_SECURITY_NUMBER |
social security number | 84.9 | 85.0 | 84.9 | 99.1 |
STREET_ADDRESS |
street address | 99.3 | 98.8 | 99.1 | 97.9 |
TAX_ID |
personal tax number | 75.4 | 95.0 | 84.1 | 98.3 |
TRAVEL_BOOKING_REFERENCE |
flight, rail or hotel booking reference | 93.7 | 72.5 | 81.8 | 83.7 |
USERNAME |
login or handle | 83.8 | 93.4 | 88.3 | 84.1 |
VEHICLE_ID |
number plate or VIN | 93.6 | 94.6 | 94.1 | 88.3 |
Masked only when you ask (32 classes)
| class | what it is | P | R | F1 | bardsai |
|---|---|---|---|---|---|
AGE |
age of a person | 93.3 | 96.6 | 94.9 | 33.0 |
AMOUNT |
amount of money | 96.6 | 94.2 | 95.4 | 31.7 |
CASE_NUMBER |
court case, police report or claim number | 88.5 | 58.9 | 70.7 | 20.8 |
CRIMINAL_RECORD |
offence, charge, conviction or sentence | 86.1 | 53.0 | 65.6 | 0.2 |
DATE |
date that is not a date of birth | 98.7 | 99.4 | 99.0 | 82.8 |
EDUCATION |
degree, school level or grade | 87.1 | 68.1 | 76.4 | 24.3 |
ETHNICITY |
ethnic origin | 89.7 | 74.6 | 81.4 | 21.5 |
GENDER |
sex or gender | 99.1 | 89.5 | 94.1 | 63.2 |
GENETIC_DATA |
gene, variant or genetic test | 92.4 | 48.6 | 63.7 | 4.4 |
HEALTH_CONDITION |
diagnosis, symptom, allergy or disability | 80.5 | 78.6 | 79.5 | 0.3 |
HOSTNAME |
internal computer or network name | 90.7 | 79.4 | 84.6 | 32.0 |
INCOME |
salary, pension or account balance | 89.4 | 70.5 | 78.8 | 47.1 |
LOCATION |
town, district or named place | 90.5 | 91.8 | 91.1 | 79.2 |
MARITAL_STATUS |
marital status | 90.9 | 73.7 | 81.4 | 19.2 |
MEDICAL_CODE |
diagnosis or drug code (ICD-10, ATC) | 97.6 | 81.4 | 88.8 | 12.6 |
MEDICAL_PROCEDURE |
surgery, examination or therapy | 78.0 | 42.4 | 55.0 | 0.3 |
MEDICAL_TEST_RESULT |
lab value, blood pressure, blood type | 88.5 | 59.6 | 71.3 | 0.9 |
MEDICATION |
drug that a person takes, with its dose | 80.2 | 83.5 | 81.8 | 1.4 |
MENTAL_HEALTH |
psychiatric condition or therapy | 89.0 | 73.4 | 80.4 | 0.7 |
NATIONALITY |
nationality or citizenship | 86.2 | 75.5 | 80.5 | 21.2 |
OCCUPATION |
job or job title | 90.5 | 77.6 | 83.5 | 26.4 |
ORGANIZATION |
name of a company or institution | 85.8 | 91.8 | 88.7 | 55.7 |
PARTIAL_IDENTIFIER |
partly hidden value (**** 4417) |
94.3 | 97.6 | 95.9 | 35.2 |
PHYSICAL_DESCRIPTION |
height, weight, hair, scar, tattoo | 97.0 | 47.4 | 63.7 | 0.6 |
POLITICAL_OR_UNION |
political opinion, party or union membership | 78.3 | 78.1 | 78.2 | 38.6 |
REFERENCE_NUMBER |
order, invoice or ticket number | 72.4 | 69.5 | 70.9 | 53.5 |
REGION_OR_COUNTRY |
country, state or region | 92.2 | 85.0 | 88.5 | 50.3 |
RELIGION |
religion or belief | 82.0 | 50.1 | 62.2 | 45.9 |
SEXUAL_ORIENTATION |
sexual orientation | 92.9 | 27.2 | 42.1 | 23.7 |
SUBSTANCE_USE |
use of tobacco, alcohol or drugs | 85.2 | 58.1 | 69.1 | 1.0 |
TIMESTAMP |
date with clock time (log line) | 99.8 | 98.1 | 98.9 | 75.1 |
URL |
web address | 95.9 | 99.0 | 97.4 | 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.
- The INT8 file is so small because it keeps only the word pieces seen in training (51% of the word table). For text with other scripts (Cyrillic, Greek, Arabic, Chinese), use the FP32 or FP16 file.
- 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.
- Downloads last month
- 28
Model tree for Jwuthrich/piily-small
Base model
jhu-clsp/mmBERT-small