Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- beki/privy
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
base_model:
|
| 8 |
+
- prajjwal1/bert-small
|
| 9 |
+
pipeline_tag: token-classification
|
| 10 |
+
---
|
| 11 |
+
# gravitee-io/bert-small-pii-detection 🚀
|
| 12 |
+
|
| 13 |
+
**A more accurate PII detector** fine-tuned from [`prajjwal1/bert-small`](https://huggingface.co/prajjwal1/bert-small) on the [`beki/privy`](https://huggingface.co/datasets/beki/privy) dataset.
|
| 14 |
+
Compared to the [`bert-tiny`](https://huggingface.co/gravitee-io/bert-tiny-pii-detection) variant, this model is larger and slower, but significantly improves precision and recall across most entity types.
|
| 15 |
+
|
| 16 |
+
### Label Set
|
| 17 |
+
|
| 18 |
+
```
|
| 19 |
+
AGE, COORDINATE, CREDIT_CARD, DATE_TIME, EMAIL_ADDRESS, FINANCIAL, IBAN_CODE, IMEI,
|
| 20 |
+
IP_ADDRESS, LOCATION, MAC_ADDRESS, NRP, ORGANIZATION, PASSWORD, PERSON, PHONE_NUMBER,
|
| 21 |
+
TITLE, URL, US_BANK_NUMBER, US_DRIVER_LICENSE, US_ITIN, US_LICENSE_PLATE, US_PASSPORT, US_SSN
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## How to Use
|
| 27 |
+
|
| 28 |
+
### Quick start (pipeline)
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
|
| 32 |
+
|
| 33 |
+
repo = "gravitee-io/bert-small-pii-detection"
|
| 34 |
+
tok = AutoTokenizer.from_pretrained(repo)
|
| 35 |
+
model = AutoModelForTokenClassification.from_pretrained(repo)
|
| 36 |
+
|
| 37 |
+
pipe = pipeline("token-classification", model=model, tokenizer=tok, aggregation_strategy="simple")
|
| 38 |
+
text = ""
|
| 39 |
+
pipe(text)
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
## Evaluation
|
| 45 |
+
|
| 46 |
+
**Test set:** `beki/privy` held-out split
|
| 47 |
+
**Metric:** precision / recall / F1 per entity, micro/macro averages
|
| 48 |
+
|
| 49 |
+
| Entity | Precision | Recall | F1-score | Support |
|
| 50 |
+
|--------------------|-----------|--------|----------|---------|
|
| 51 |
+
| AGE | 0.9898 | 0.8858 | 0.9349 | 219 |
|
| 52 |
+
| COORDINATE | 0.9627 | 0.8738 | 0.9161 | 325 |
|
| 53 |
+
| CREDIT_CARD | 0.9273 | 0.8870 | 0.9067 | 115 |
|
| 54 |
+
| DATE_TIME | 0.8598 | 0.7364 | 0.7933 | 3255 |
|
| 55 |
+
| EMAIL_ADDRESS | 0.9428 | 0.8941 | 0.9178 | 387 |
|
| 56 |
+
| FINANCIAL | 0.9862 | 0.9565 | 0.9711 | 299 |
|
| 57 |
+
| IBAN_CODE | 0.9577 | 0.9252 | 0.9412 | 147 |
|
| 58 |
+
| IMEI | 0.9885 | 0.9663 | 0.9773 | 89 |
|
| 59 |
+
| IP_ADDRESS | 0.9338 | 0.8812 | 0.9068 | 160 |
|
| 60 |
+
| LOCATION | 0.8849 | 0.8222 | 0.8524 | 4264 |
|
| 61 |
+
| MAC_ADDRESS | 0.9889 | 1.0000 | 0.9944 | 89 |
|
| 62 |
+
| NRP | 1.0000 | 0.9818 | 0.9908 | 494 |
|
| 63 |
+
| ORGANIZATION | 0.7454 | 0.6688 | 0.7051 | 3551 |
|
| 64 |
+
| PASSWORD | 0.8384 | 0.8137 | 0.8259 | 102 |
|
| 65 |
+
| PERSON | 0.9123 | 0.8826 | 0.8972 | 4454 |
|
| 66 |
+
| PHONE_NUMBER | 0.9462 | 0.8199 | 0.8785 | 322 |
|
| 67 |
+
| TITLE | 0.9887 | 0.9734 | 0.9810 | 451 |
|
| 68 |
+
| URL | 1.0000 | 0.9787 | 0.9892 | 188 |
|
| 69 |
+
| US_BANK_NUMBER | 1.0000 | 0.9579 | 0.9785 | 95 |
|
| 70 |
+
| US_DRIVER_LICENSE | 0.9167 | 0.9167 | 0.9167 | 120 |
|
| 71 |
+
| US_ITIN | 0.9659 | 0.8763 | 0.9189 | 97 |
|
| 72 |
+
| US_LICENSE_PLATE | 1.0000 | 0.9000 | 0.9474 | 90 |
|
| 73 |
+
| US_PASSPORT | 0.9200 | 0.9200 | 0.9200 | 100 |
|
| 74 |
+
| US_SSN | 0.9744 | 0.9580 | 0.9661 | 119 |
|
| 75 |
+
| **micro avg** | 0.8804 | 0.8141 | 0.8460 | 19532 |
|
| 76 |
+
| **macro avg** | 0.9429 | 0.8948 | 0.9178 | 19532 |
|
| 77 |
+
| **weighted avg** | 0.8785 | 0.8141 | 0.8446 | 19532 |
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## Intended Uses & Limitations
|
| 83 |
+
|
| 84 |
+
**Use this model for:**
|
| 85 |
+
|
| 86 |
+
* Redacting PII in customer support logs, dev/test environments, API traces and articles
|
| 87 |
+
* Pre-screening documents before storage or external sharing
|
| 88 |
+
* Real-time hints in form fields or data entry systems
|
| 89 |
+
|
| 90 |
+
**Limitations:**
|
| 91 |
+
|
| 92 |
+
* English-focused; other languages will degrade
|
| 93 |
+
* Domain drift is real: audit on your own data
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
## Citation
|
| 99 |
+
|
| 100 |
+
If you use the model, please consider citing the papers:
|
| 101 |
+
|
| 102 |
+
```
|
| 103 |
+
@misc{bhargava2021generalization,
|
| 104 |
+
title={Generalization in NLI: Ways (Not) To Go Beyond Simple Heuristics},
|
| 105 |
+
author={Prajjwal Bhargava and Aleksandr Drozd and Anna Rogers},
|
| 106 |
+
year={2021},
|
| 107 |
+
eprint={2110.01518},
|
| 108 |
+
archivePrefix={arXiv},
|
| 109 |
+
primaryClass={cs.CL}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
@article{DBLP:journals/corr/abs-1908-08962,
|
| 113 |
+
author = {Iulia Turc and
|
| 114 |
+
Ming{-}Wei Chang and
|
| 115 |
+
Kenton Lee and
|
| 116 |
+
Kristina Toutanova},
|
| 117 |
+
title = {Well-Read Students Learn Better: The Impact of Student Initialization
|
| 118 |
+
on Knowledge Distillation},
|
| 119 |
+
journal = {CoRR},
|
| 120 |
+
volume = {abs/1908.08962},
|
| 121 |
+
year = {2019},
|
| 122 |
+
url = {http://arxiv.org/abs/1908.08962},
|
| 123 |
+
eprinttype = {arXiv},
|
| 124 |
+
eprint = {1908.08962},
|
| 125 |
+
timestamp = {Thu, 29 Aug 2019 16:32:34 +0200},
|
| 126 |
+
biburl = {https://dblp.org/rec/journals/corr/abs-1908-08962.bib},
|
| 127 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
| 128 |
+
|
| 129 |
+
@online{WinNT,
|
| 130 |
+
author = {Benjamin Kilimnik},
|
| 131 |
+
title = {{Privy} Synthetic PII Protocol Trace Dataset},
|
| 132 |
+
year = 2022,
|
| 133 |
+
url = {https://huggingface.co/datasets/beki/privy},
|
| 134 |
+
}
|
| 135 |
+
```
|