Update README.md
Browse files
README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
---
|
| 2 |
license: openrail
|
|
|
|
| 3 |
datasets:
|
| 4 |
- ai4privacy/open-pii-masking-500k-ai4privacy
|
| 5 |
language:
|
|
@@ -17,114 +18,107 @@ base_model:
|
|
| 17 |
- microsoft/deberta-v3-base
|
| 18 |
pipeline_tag: token-classification
|
| 19 |
tags:
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
---
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
**Base Architecture:** `DeBERTa-v3-base` (435M parameters)
|
| 29 |
-
**Context:** Master's Thesis, University of Verona (Department of Computer Science)
|
| 30 |
-
**License:** Academic/Research Use
|
| 31 |
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
| 39 |
-
* **Tokenization:** `DeBERTa-v3 Fast Tokenizer` (Max sequence: 512 tokens).
|
| 40 |
-
* **Tagging Scheme:** `IOB2` (Inside-Outside-Beginning).
|
| 41 |
-
* **Inference Latency:** `~25.21 ms` (Average per request on CUDA).
|
| 42 |
-
* **Training Strategy:** Full fine-tuning (3 epochs, AdamW, `2e^-5` LR) on AI4Privacy-v2.
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
* **Location:** `STREET`, `BUILDINGNUM`, `CITY`, `ZIPCODE`
|
| 53 |
-
* **Temporal:** `DATE`, `TIME`
|
| 54 |
|
| 55 |
-
##
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
| Metric | Validation Set (In-Domain) | NVIDIA Nemotron (Out-of-Domain) |
|
| 61 |
-
| :--- | :--- | :--- |
|
| 62 |
-
| **Accuracy** | **99.29%** | **93.42%** |
|
| 63 |
-
| **Weighted Precision** | 0.9930 | 0.9755 |
|
| 64 |
-
| **Weighted Recall** | 0.9929 | 0.9342 |
|
| 65 |
-
| **Weighted `F1`** | **0.9929** | **0.9529** |
|
| 66 |
-
| **Macro `F1`** | 0.9499 | 0.3491* |
|
| 67 |
-
|
| 68 |
-
*\*Note: Lower Macro `F1` on the NVIDIA dataset reflects class imbalance and the absence of specific rare entity types (e.g., Building Numbers) in the test set.*
|
| 69 |
-
|
| 70 |
-
### Benchmark Comparison
|
| 71 |
-
NerGuard-0.3B establishes a new baseline compared to existing PII solutions.
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
| **`NerGuard-0.3B`** | **0.9037** | **25.21** | **Baseline** |
|
| 76 |
-
| `Gliner` | 0.4463 | 24.68 | -50.6% |
|
| 77 |
-
| `Microsoft Presidio` | 0.3158 | 13.53 | -65.1% |
|
| 78 |
-
| `Spacy (en_core_web_trf)` | 0.1423 | 9.35 | -84.2% |
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
* **Challenges:** Context-heavy entities (Street addresses without numbers) and rare classes (Gender, Tax IDs) exhibit lower recall in out-of-domain settings.
|
| 84 |
|
| 85 |
-
##
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
# Initialize Pipeline
|
| 97 |
-
nlp = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
|
| 98 |
-
|
| 99 |
-
# Inference
|
| 100 |
-
multilingual_cases = [
|
| 101 |
-
"Please send the report to Mr. John Smith at j.smith@company.com immediately.",
|
| 102 |
-
"J'habite au 15 Rue de la Paix, Paris. Mon nom est Pierre Martin.",
|
| 103 |
-
"Mein Name ist Thomas Müller und ich lebe in der Berliner Straße 5, München.",
|
| 104 |
-
"La doctora Ana María González López trabaja en el Hospital Central de Madrid.",
|
| 105 |
-
"Il codice fiscale di Mario Rossi è RSSMRA80A01H501U.",
|
| 106 |
-
"Ik ben Sven van der Berg en mijn e-mailadres is sven.berg@example.nl."
|
| 107 |
-
]
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
for text in multilingual_cases:
|
| 111 |
-
results = nlp(text)
|
| 112 |
-
print(f"\n--- Sample: {text} ---")
|
| 113 |
-
pprint(results)
|
| 114 |
-
```
|
| 115 |
|
| 116 |
-
##
|
| 117 |
-
- **Domain Specificity**: Optimized for general prose; may require fine-tuning for specialized medical or legal jargon.
|
| 118 |
-
- **Context Sensitivity**: High recall on numeric identifiers (e.g., `SSN`) may result in false positives if context is ambiguous.
|
| 119 |
|
| 120 |
-
## Citations
|
| 121 |
```bibtex
|
| 122 |
-
@mastersthesis{
|
| 123 |
-
title={NerGuard
|
| 124 |
-
author={
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
type={Master's Thesis},
|
| 128 |
-
url={[https://huggingface.co/exdsgift/NerGuard-0.3B](https://github.com/exdsgift/NerGuard)}
|
| 129 |
}
|
| 130 |
```
|
|
|
|
| 1 |
---
|
| 2 |
license: openrail
|
| 3 |
+
library_name: transformers
|
| 4 |
datasets:
|
| 5 |
- ai4privacy/open-pii-masking-500k-ai4privacy
|
| 6 |
language:
|
|
|
|
| 18 |
- microsoft/deberta-v3-base
|
| 19 |
pipeline_tag: token-classification
|
| 20 |
tags:
|
| 21 |
+
- ner
|
| 22 |
+
- pii
|
| 23 |
+
- token-classification
|
| 24 |
+
- privacy
|
| 25 |
+
- mdeberta
|
| 26 |
+
model-index:
|
| 27 |
+
- name: NerGuard-0.3B
|
| 28 |
+
results:
|
| 29 |
+
- task:
|
| 30 |
+
type: token-classification
|
| 31 |
+
name: PII Detection
|
| 32 |
+
dataset:
|
| 33 |
+
name: AI4Privacy (validation)
|
| 34 |
+
type: ai4privacy/open-pii-masking-500k-ai4privacy
|
| 35 |
+
metrics:
|
| 36 |
+
- type: f1
|
| 37 |
+
value: 0.9597
|
| 38 |
+
name: F1 (macro)
|
| 39 |
+
- type: f1
|
| 40 |
+
value: 0.9926
|
| 41 |
+
name: F1 (weighted)
|
| 42 |
+
- type: accuracy
|
| 43 |
+
value: 0.9926
|
| 44 |
+
name: Accuracy
|
| 45 |
+
- task:
|
| 46 |
+
type: token-classification
|
| 47 |
+
name: PII Detection
|
| 48 |
+
dataset:
|
| 49 |
+
name: NVIDIA Nemotron-PII
|
| 50 |
+
type: nvidia/Nemotron-PII
|
| 51 |
+
metrics:
|
| 52 |
+
- type: f1
|
| 53 |
+
value: 0.9543
|
| 54 |
+
name: F1 (weighted)
|
| 55 |
+
- type: accuracy
|
| 56 |
+
value: 0.9350
|
| 57 |
+
name: Accuracy
|
| 58 |
---
|
| 59 |
+
[](https://huggingface.co/exdsgift/NerGuard-0.3B)
|
| 60 |
+
[](https://github.com/exdsgift/NerGuard)
|
| 61 |
+
[](https://huggingface.co/exdsgift/NerGuard-0.3B)
|
| 62 |
+
[](https://opensource.org/licenses/MIT)
|
| 63 |
+
[](https://huggingface.co/exdsgift/NerGuard-0.3B)
|
| 64 |
|
| 65 |
+
# NerGuard-0.3B
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
**NerGuard-0.3B** is a multilingual transformer model for Personally Identifiable Information (PII) detection, built on [mDeBERTa-v3-base](https://huggingface.co/microsoft/mdeberta-v3-base). It performs token-level classification across **21 PII entity types** using BIO tagging, covering names, addresses, government IDs, financial data, and contact information.
|
| 68 |
|
| 69 |
+
Trained on 500K+ samples from [AI4Privacy](https://huggingface.co/datasets/ai4privacy/open-pii-masking-500k-ai4privacy), the model achieves **F1 95.97%** on validation and **2x higher F1** than the best open-source alternative (GLiNER, Presidio, SpaCy) on a 3,000-sample benchmark. It supports cross-lingual transfer to 8 European languages without additional fine-tuning.
|
| 70 |
|
| 71 |
+
This is the standalone NER model. For the full hybrid system with entropy-based LLM routing, see the [NerGuard GitHub repository](https://github.com/exdsgift/NerGuard).
|
| 72 |
|
| 73 |
+
## Supported Entities
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
| Category | Entity Types |
|
| 76 |
+
|---|---|
|
| 77 |
+
| **Person** | `GIVENNAME`, `SURNAME`, `TITLE` |
|
| 78 |
+
| **Location** | `CITY`, `STREET`, `BUILDINGNUM`, `ZIPCODE` |
|
| 79 |
+
| **Government ID** | `IDCARDNUM`, `PASSPORTNUM`, `DRIVERLICENSENUM`, `SOCIALNUM`, `TAXNUM` |
|
| 80 |
+
| **Financial** | `CREDITCARDNUMBER` |
|
| 81 |
+
| **Contact** | `EMAIL`, `TELEPHONENUM` |
|
| 82 |
+
| **Temporal** | `DATE`, `TIME` |
|
| 83 |
+
| **Demographic** | `AGE`, `SEX`, `GENDER` |
|
| 84 |
|
| 85 |
+
## Evaluation Results
|
| 86 |
|
| 87 |
+
| Dataset | Accuracy | F1 (macro) | F1 (weighted) |
|
| 88 |
+
|---|---|---|---|
|
| 89 |
+
| AI4Privacy (validation) | 99.26% | 95.97% | 99.26% |
|
| 90 |
+
| NVIDIA Nemotron-PII | 93.50% | — | 95.43% |
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
## Usage
|
| 93 |
|
| 94 |
+
```python
|
| 95 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
ner = pipeline("token-classification", model="exdsgift/NerGuard-0.3B", aggregation_strategy="simple")
|
| 98 |
+
results = ner("My name is John Smith and my email is john@gmail.com")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
+
for entity in results:
|
| 101 |
+
print(f"{entity['word']} -> {entity['entity_group']} ({entity['score']:.2f})")
|
| 102 |
+
```
|
|
|
|
| 103 |
|
| 104 |
+
## Training
|
| 105 |
|
| 106 |
+
| Parameter | Value |
|
| 107 |
+
|---|---|
|
| 108 |
+
| Base model | `microsoft/mdeberta-v3-base` |
|
| 109 |
+
| Dataset | AI4Privacy Open PII Masking 500K |
|
| 110 |
+
| Max sequence length | 512 (stride 382) |
|
| 111 |
+
| Learning rate | 2e-5 |
|
| 112 |
+
| Batch size | 32 |
|
| 113 |
+
| Epochs | 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
## Citation
|
|
|
|
|
|
|
| 116 |
|
|
|
|
| 117 |
```bibtex
|
| 118 |
+
@mastersthesis{nerguard2026,
|
| 119 |
+
title={NerGuard: Hybrid PII Detection with Entropy-Based LLM Routing},
|
| 120 |
+
author={Exdsgift},
|
| 121 |
+
school={University of Verona},
|
| 122 |
+
year={2026}
|
|
|
|
|
|
|
| 123 |
}
|
| 124 |
```
|