Upload folder using huggingface_hub
Browse files- README.md +123 -0
- config.json +124 -0
- model.safetensors +3 -0
README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- it
|
| 4 |
license: apache-2.0
|
| 5 |
+
library_name: opf
|
| 6 |
+
base_model: openai/privacy-filter
|
| 7 |
+
pipeline_tag: token-classification
|
| 8 |
+
tags:
|
| 9 |
+
- privacy-filter
|
| 10 |
+
- pii-detection
|
| 11 |
+
- italian
|
| 12 |
+
- anonymization
|
| 13 |
+
- ner
|
| 14 |
+
- opf
|
| 15 |
---
|
| 16 |
+
|
| 17 |
+
# pii-ita
|
| 18 |
+
|
| 19 |
+
Fine-tuning di [openai/privacy-filter](https://huggingface.co/openai/privacy-filter) su documenti italiani sintetici per il riconoscimento di PII (Personally Identifiable Information).
|
| 20 |
+
|
| 21 |
+
Modello addestrato su dataset sintetico italiano (checkpoint_step1_italian_docs_v2).
|
| 22 |
+
|
| 23 |
+
## ⚠️ Come caricare il modello
|
| 24 |
+
|
| 25 |
+
Questo modello usa un'architettura **custom** (`model_type: privacy_filter`) **non** registrata in `transformers`. NON funziona con `AutoModel` / `transformers.pipeline`.
|
| 26 |
+
|
| 27 |
+
Per usarlo serve la libreria `opf`:
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
pip install git+https://github.com/openai/privacy-filter.git
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
import os
|
| 35 |
+
os.environ['OPF_MOE_TRITON'] = '0' # disabilita kernel CUDA-only su MPS/CPU
|
| 36 |
+
|
| 37 |
+
from opf import OPF
|
| 38 |
+
from huggingface_hub import snapshot_download
|
| 39 |
+
|
| 40 |
+
# Scarica il modello (viene messo in cache locale)
|
| 41 |
+
local_path = snapshot_download(repo_id='basah/pii-ita')
|
| 42 |
+
|
| 43 |
+
model = OPF(
|
| 44 |
+
model=local_path,
|
| 45 |
+
device='cuda', # oppure 'mps' (Apple Silicon) o 'cpu'
|
| 46 |
+
output_mode='typed',
|
| 47 |
+
decode_mode='viterbi',
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
text = 'Il sottoscritto Mario Rossi, CF RSSMRA80A01H501U, residente in Via Roma 10, Milano.'
|
| 51 |
+
result = model.redact(text)
|
| 52 |
+
|
| 53 |
+
print(result.redacted_text)
|
| 54 |
+
# -> Il sottoscritto <PRIVATE_PERSON>, <CODICE_FISCALE>, residente in <PRIVATE_ADDRESS>.
|
| 55 |
+
|
| 56 |
+
for span in result.detected_spans:
|
| 57 |
+
print(f'{span.label:25s} "{span.text}" [{span.start}:{span.end}]')
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## 📋 Categorie riconosciute
|
| 61 |
+
|
| 62 |
+
Il modello riconosce **18** categorie di PII italiane:
|
| 63 |
+
|
| 64 |
+
| Categoria | Descrizione |
|
| 65 |
+
|---|---|
|
| 66 |
+
| `private_person` | Nomi di persone fisiche |
|
| 67 |
+
| `private_address` | Indirizzi (vie, città, numeri civici) |
|
| 68 |
+
| `private_email` | Indirizzi email |
|
| 69 |
+
| `private_phone` | Numeri di telefono italiani |
|
| 70 |
+
| `private_url` | URL contenenti dati personali |
|
| 71 |
+
| `private_date` | Date (nascita, scadenze, eventi) |
|
| 72 |
+
| `account_number` | Numeri di conto (generici) |
|
| 73 |
+
| `secret` | Credenziali, password, token |
|
| 74 |
+
| `codice_fiscale` | Codice Fiscale italiano (16 caratteri) |
|
| 75 |
+
| `carta_identita` | Numero Carta d'Identità italiana |
|
| 76 |
+
| `patente` | Numero Patente di guida |
|
| 77 |
+
| `passaporto` | Numero Passaporto |
|
| 78 |
+
| `partita_iva` | Partita IVA italiana (11 cifre) |
|
| 79 |
+
| `iban` | IBAN italiano (27 caratteri) |
|
| 80 |
+
| `tessera_sanitaria` | Tessera Sanitaria |
|
| 81 |
+
| `numero_procedimento` | Numero procedimento legale (RG) |
|
| 82 |
+
| `riferimento_catastale` | Riferimento catastale (foglio/mappale) |
|
| 83 |
+
| `parte_in_causa` | Parti in procedimento giudiziario |
|
| 84 |
+
|
| 85 |
+
## 📊 Dettagli training
|
| 86 |
+
|
| 87 |
+
- **Base model**: `openai/privacy-filter`
|
| 88 |
+
- **Dati**: **7500** esempi di training, **1250** di validation, **(held-out, non usato in training)** di test (held-out)
|
| 89 |
+
- **Epoche**: 14
|
| 90 |
+
- **Batch size**: 1
|
| 91 |
+
- **Grad accum steps**: 4
|
| 92 |
+
- **Learning rate**: 1e-05
|
| 93 |
+
- **Hardware training**: cuda
|
| 94 |
+
- **Best epoch**: 14 (validation loss: 0.0000)
|
| 95 |
+
- **Param dtype**: bfloat16
|
| 96 |
+
|
| 97 |
+
## 🎯 Metriche (validation set)
|
| 98 |
+
|
| 99 |
+
- **Token accuracy** (best): 1.0000
|
| 100 |
+
- **Validation loss** (best): 0.0000
|
| 101 |
+
|
| 102 |
+
## 🎨 Esempi di output
|
| 103 |
+
|
| 104 |
+
**Input**: `Per bonifici IBAN IT60X0542811101000000123456 intestato a Luigi Bianchi. luigi.bianchi@studio.it`
|
| 105 |
+
|
| 106 |
+
**Output**: `Per bonifici <IBAN> intestato a <PRIVATE_PERSON>. <PRIVATE_EMAIL>`
|
| 107 |
+
|
| 108 |
+
## ⚖️ Licenza & limitazioni
|
| 109 |
+
|
| 110 |
+
- **Licenza**: Apache 2.0 (ereditata dal base model)
|
| 111 |
+
- **Limiti**: il dataset è sintetico — il modello potrebbe avere pattern overfitted su formati tipici (es. "CF RSSMRA80A01H501U" preceduto da prefisso). Testa con i tuoi testi prima dell'uso in produzione.
|
| 112 |
+
- **Contesto**: addestrato su testo italiano generico (email, CV, news, chat, business). Non ottimizzato per domini specifici (medico, scientifico, etc.).
|
| 113 |
+
- **Dati sintetici**: nessun dato reale di terze parti usato nel training. Tutti gli esempi sono generati programmaticamente con formati italiani validi ma valori casuali.
|
| 114 |
+
|
| 115 |
+
## 📎 Citazione
|
| 116 |
+
|
| 117 |
+
Se usi questo modello, per favore cita il lavoro originale di OpenAI:
|
| 118 |
+
|
| 119 |
+
```
|
| 120 |
+
@misc{openai-privacy-filter,
|
| 121 |
+
title = {Privacy Filter},
|
| 122 |
+
author = {OpenAI},
|
| 123 |
+
year = {2024},
|
| 124 |
+
url = {https://github.com/openai/privacy-filter}
|
| 125 |
+
}
|
| 126 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bidirectional_context": true,
|
| 3 |
+
"bidirectional_left_context": 128,
|
| 4 |
+
"bidirectional_right_context": 128,
|
| 5 |
+
"category_version": "pii-ita-v1",
|
| 6 |
+
"default_n_ctx": 128000,
|
| 7 |
+
"encoding": "o200k_base",
|
| 8 |
+
"experts_per_token": 4,
|
| 9 |
+
"head_dim": 64,
|
| 10 |
+
"hidden_size": 640,
|
| 11 |
+
"inference_contract_version": 1,
|
| 12 |
+
"initial_context_length": 4096,
|
| 13 |
+
"intermediate_size": 640,
|
| 14 |
+
"max_position_embeddings": 131072,
|
| 15 |
+
"model_type": "privacy_filter",
|
| 16 |
+
"ner_class_names": [
|
| 17 |
+
"O",
|
| 18 |
+
"B-private_person",
|
| 19 |
+
"I-private_person",
|
| 20 |
+
"E-private_person",
|
| 21 |
+
"S-private_person",
|
| 22 |
+
"B-private_address",
|
| 23 |
+
"I-private_address",
|
| 24 |
+
"E-private_address",
|
| 25 |
+
"S-private_address",
|
| 26 |
+
"B-private_email",
|
| 27 |
+
"I-private_email",
|
| 28 |
+
"E-private_email",
|
| 29 |
+
"S-private_email",
|
| 30 |
+
"B-private_phone",
|
| 31 |
+
"I-private_phone",
|
| 32 |
+
"E-private_phone",
|
| 33 |
+
"S-private_phone",
|
| 34 |
+
"B-private_url",
|
| 35 |
+
"I-private_url",
|
| 36 |
+
"E-private_url",
|
| 37 |
+
"S-private_url",
|
| 38 |
+
"B-private_date",
|
| 39 |
+
"I-private_date",
|
| 40 |
+
"E-private_date",
|
| 41 |
+
"S-private_date",
|
| 42 |
+
"B-account_number",
|
| 43 |
+
"I-account_number",
|
| 44 |
+
"E-account_number",
|
| 45 |
+
"S-account_number",
|
| 46 |
+
"B-secret",
|
| 47 |
+
"I-secret",
|
| 48 |
+
"E-secret",
|
| 49 |
+
"S-secret",
|
| 50 |
+
"B-codice_fiscale",
|
| 51 |
+
"I-codice_fiscale",
|
| 52 |
+
"E-codice_fiscale",
|
| 53 |
+
"S-codice_fiscale",
|
| 54 |
+
"B-carta_identita",
|
| 55 |
+
"I-carta_identita",
|
| 56 |
+
"E-carta_identita",
|
| 57 |
+
"S-carta_identita",
|
| 58 |
+
"B-patente",
|
| 59 |
+
"I-patente",
|
| 60 |
+
"E-patente",
|
| 61 |
+
"S-patente",
|
| 62 |
+
"B-passaporto",
|
| 63 |
+
"I-passaporto",
|
| 64 |
+
"E-passaporto",
|
| 65 |
+
"S-passaporto",
|
| 66 |
+
"B-partita_iva",
|
| 67 |
+
"I-partita_iva",
|
| 68 |
+
"E-partita_iva",
|
| 69 |
+
"S-partita_iva",
|
| 70 |
+
"B-iban",
|
| 71 |
+
"I-iban",
|
| 72 |
+
"E-iban",
|
| 73 |
+
"S-iban",
|
| 74 |
+
"B-tessera_sanitaria",
|
| 75 |
+
"I-tessera_sanitaria",
|
| 76 |
+
"E-tessera_sanitaria",
|
| 77 |
+
"S-tessera_sanitaria",
|
| 78 |
+
"B-numero_procedimento",
|
| 79 |
+
"I-numero_procedimento",
|
| 80 |
+
"E-numero_procedimento",
|
| 81 |
+
"S-numero_procedimento",
|
| 82 |
+
"B-riferimento_catastale",
|
| 83 |
+
"I-riferimento_catastale",
|
| 84 |
+
"E-riferimento_catastale",
|
| 85 |
+
"S-riferimento_catastale",
|
| 86 |
+
"B-parte_in_causa",
|
| 87 |
+
"I-parte_in_causa",
|
| 88 |
+
"E-parte_in_causa",
|
| 89 |
+
"S-parte_in_causa"
|
| 90 |
+
],
|
| 91 |
+
"num_attention_heads": 14,
|
| 92 |
+
"num_experts": 128,
|
| 93 |
+
"num_hidden_layers": 8,
|
| 94 |
+
"num_key_value_heads": 2,
|
| 95 |
+
"num_labels": 73,
|
| 96 |
+
"param_dtype": "bfloat16",
|
| 97 |
+
"rope_ntk_alpha": 1.0,
|
| 98 |
+
"rope_ntk_beta": 32.0,
|
| 99 |
+
"rope_scaling_factor": 32.0,
|
| 100 |
+
"rope_theta": 150000,
|
| 101 |
+
"sliding_window": 257,
|
| 102 |
+
"span_class_names": [
|
| 103 |
+
"O",
|
| 104 |
+
"private_person",
|
| 105 |
+
"private_address",
|
| 106 |
+
"private_email",
|
| 107 |
+
"private_phone",
|
| 108 |
+
"private_url",
|
| 109 |
+
"private_date",
|
| 110 |
+
"account_number",
|
| 111 |
+
"secret",
|
| 112 |
+
"codice_fiscale",
|
| 113 |
+
"carta_identita",
|
| 114 |
+
"patente",
|
| 115 |
+
"passaporto",
|
| 116 |
+
"partita_iva",
|
| 117 |
+
"iban",
|
| 118 |
+
"tessera_sanitaria",
|
| 119 |
+
"numero_procedimento",
|
| 120 |
+
"riferimento_catastale",
|
| 121 |
+
"parte_in_causa"
|
| 122 |
+
],
|
| 123 |
+
"vocab_size": 200064
|
| 124 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:420e24586f4776bba6fefd91d57e1875ddcd3c6040f674ded6c172a1048b1f0a
|
| 3 |
+
size 2799035176
|