hanneshapke commited on
Commit
6d35bc0
·
verified ·
1 Parent(s): df7d65b

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,3 +1,146 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - da
4
+ - de
5
+ - en
6
+ - es
7
+ - fr
8
+ - nl
9
+ license: apache-2.0
10
+ library_name: transformers
11
+ pipeline_tag: token-classification
12
+ tags:
13
+ - pii
14
+ - privacy
15
+ - ner
16
+ - coreference-resolution
17
+ - distilbert
18
+ - multi-task
19
+ base_model: distilbert-base-cased
20
+ ---
21
+
22
+ # Kiji PII Detection Model
23
+
24
+ Multi-task DistilBERT model for detecting Personally Identifiable Information (PII) in text with coreference resolution. Fine-tuned from [`distilbert-base-cased`](https://huggingface.co/distilbert-base-cased).
25
+
26
+ ## Model Summary
27
+
28
+ | | |
29
+ |---|---|
30
+ | **Base model** | [distilbert-base-cased](https://huggingface.co/distilbert-base-cased) |
31
+ | **Architecture** | Shared DistilBERT encoder + two linear classification heads |
32
+ | **Parameters** | ~66M |
33
+ | **Model size** | 249 MB (SafeTensors) |
34
+ | **Tasks** | PII token classification (53 labels) + coreference detection (7 labels) |
35
+ | **PII entity types** | 26 |
36
+ | **Max sequence length** | 512 tokens |
37
+
38
+ ## Architecture
39
+
40
+ ```
41
+ Input (input_ids, attention_mask)
42
+ |
43
+ DistilBERT Encoder (shared, hidden_size=768)
44
+ |
45
+ +----+----+
46
+ | |
47
+ PII Head Coref Head
48
+ (768->53) (768->7)
49
+ ```
50
+
51
+ The model uses multi-task learning: a shared DistilBERT encoder feeds into two independent linear classification heads. Both tasks are trained simultaneously with equal loss weighting, which acts as regularization and improves PII detection generalization.
52
+
53
+ ## Usage
54
+
55
+ ```python
56
+ import torch
57
+ from transformers import AutoTokenizer
58
+
59
+ # Load tokenizer
60
+ tokenizer = AutoTokenizer.from_pretrained("DataikuNLP/kiji-pii-model")
61
+
62
+ # The model uses a custom MultiTaskPIIDetectionModel architecture.
63
+ # Load weights manually:
64
+ from safetensors.torch import load_file
65
+ weights = load_file("DataikuNLP/kiji-pii-model/model.safetensors") # or local path
66
+
67
+ # Tokenize
68
+ text = "Contact John Smith at john.smith@example.com or call +1-555-123-4567."
69
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
70
+
71
+ # See the label_mappings.json file for PII label definitions
72
+ ```
73
+
74
+ ## PII Labels (BIO tagging)
75
+
76
+ The model uses BIO tagging with 26 entity types:
77
+
78
+ | Label | Description |
79
+ |-------|-------------|
80
+ | `AGE` | Age |
81
+ | `BUILDINGNUM` | Building number |
82
+ | `CITY` | City |
83
+ | `COMPANYNAME` | Company name |
84
+ | `COUNTRY` | Country |
85
+ | `CREDITCARDNUMBER` | Credit Card Number |
86
+ | `DATEOFBIRTH` | Date of birth |
87
+ | `DRIVERLICENSENUM` | Driver's License Number |
88
+ | `EMAIL` | Email |
89
+ | `FIRSTNAME` | First name |
90
+ | `IBAN` | IBAN |
91
+ | `IDCARDNUM` | ID Card Number |
92
+ | `LICENSEPLATENUM` | License Plate Number |
93
+ | `NATIONALID` | National ID |
94
+ | `PASSPORTID` | Passport ID |
95
+ | `PASSWORD` | Password |
96
+ | `PHONENUMBER` | Phone number |
97
+ | `SECURITYTOKEN` | API Security Tokens |
98
+ | `SSN` | Social Security Number |
99
+ | `STATE` | State |
100
+ | `STREET` | Street |
101
+ | `SURNAME` | Last name |
102
+ | `TAXNUM` | Tax Number |
103
+ | `URL` | URL |
104
+ | `USERNAME` | Username |
105
+ | `ZIP` | Zip code |
106
+
107
+
108
+ Each entity type has `B-` (beginning) and `I-` (inside) variants, plus `O` for non-PII tokens.
109
+
110
+ ## Coreference Labels
111
+
112
+ | Label | Description |
113
+ |-------|-------------|
114
+ | `NO_COREF` | Token is not part of a coreference cluster |
115
+ | `CLUSTER_0`-`CLUSTER_3` | Token belongs to coreference cluster 0-3 |
116
+
117
+ ## Training
118
+
119
+ | | |
120
+ |---|---|
121
+ | **Epochs** | 15 (with early stopping) |
122
+ | **Batch size** | 16 |
123
+ | **Learning rate** | 3e-5 |
124
+ | **Weight decay** | 0.01 |
125
+ | **Warmup steps** | 200 |
126
+ | **Early stopping** | patience=3, threshold=1% |
127
+ | **Loss** | Multi-task: PII cross-entropy + coreference cross-entropy (equal weights) |
128
+ | **Optimizer** | AdamW |
129
+ | **Metric** | Weighted F1 (PII task) |
130
+
131
+ ## Training Data
132
+
133
+ Trained on the [DataikuNLP/kiji-pii-training-data](https://huggingface.co/datasets/DataikuNLP/kiji-pii-training-data) dataset — a synthetic multilingual PII dataset with entity annotations and coreference resolution.
134
+
135
+ ## Derived Models
136
+
137
+ | Variant | Format | Repository |
138
+ |---------|--------|------------|
139
+ | Quantized (INT8) | ONNX | [DataikuNLP/kiji-pii-model-onnx](https://huggingface.co/DataikuNLP/kiji-pii-model-onnx) |
140
+
141
+ ## Limitations
142
+
143
+ - Trained on **synthetically generated** data — may not generalize to all real-world text
144
+ - Coreference head supports up to 4 clusters per sequence
145
+ - Optimized for the 6 languages in the training data (English, German, French, Spanish, Dutch, Danish)
146
+ - Max sequence length is 512 tokens
label_mappings.json ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "pii": {
3
+ "label2id": {
4
+ "O": 0,
5
+ "B-SURNAME": 1,
6
+ "I-SURNAME": 2,
7
+ "B-FIRSTNAME": 3,
8
+ "I-FIRSTNAME": 4,
9
+ "B-BUILDINGNUM": 5,
10
+ "I-BUILDINGNUM": 6,
11
+ "B-DATEOFBIRTH": 7,
12
+ "I-DATEOFBIRTH": 8,
13
+ "B-EMAIL": 9,
14
+ "I-EMAIL": 10,
15
+ "B-PHONENUMBER": 11,
16
+ "I-PHONENUMBER": 12,
17
+ "B-CITY": 13,
18
+ "I-CITY": 14,
19
+ "B-URL": 15,
20
+ "I-URL": 16,
21
+ "B-COMPANYNAME": 17,
22
+ "I-COMPANYNAME": 18,
23
+ "B-STATE": 19,
24
+ "I-STATE": 20,
25
+ "B-ZIP": 21,
26
+ "I-ZIP": 22,
27
+ "B-STREET": 23,
28
+ "I-STREET": 24,
29
+ "B-COUNTRY": 25,
30
+ "I-COUNTRY": 26,
31
+ "B-SSN": 27,
32
+ "I-SSN": 28,
33
+ "B-DRIVERLICENSENUM": 29,
34
+ "I-DRIVERLICENSENUM": 30,
35
+ "B-PASSPORTID": 31,
36
+ "I-PASSPORTID": 32,
37
+ "B-NATIONALID": 33,
38
+ "I-NATIONALID": 34,
39
+ "B-IDCARDNUM": 35,
40
+ "I-IDCARDNUM": 36,
41
+ "B-TAXNUM": 37,
42
+ "I-TAXNUM": 38,
43
+ "B-LICENSEPLATENUM": 39,
44
+ "I-LICENSEPLATENUM": 40,
45
+ "B-PASSWORD": 41,
46
+ "I-PASSWORD": 42,
47
+ "B-IBAN": 43,
48
+ "I-IBAN": 44,
49
+ "B-AGE": 45,
50
+ "I-AGE": 46,
51
+ "B-SECURITYTOKEN": 47,
52
+ "I-SECURITYTOKEN": 48,
53
+ "B-CREDITCARDNUMBER": 49,
54
+ "I-CREDITCARDNUMBER": 50,
55
+ "B-USERNAME": 51,
56
+ "I-USERNAME": 52
57
+ },
58
+ "id2label": {
59
+ "0": "O",
60
+ "1": "B-SURNAME",
61
+ "2": "I-SURNAME",
62
+ "3": "B-FIRSTNAME",
63
+ "4": "I-FIRSTNAME",
64
+ "5": "B-BUILDINGNUM",
65
+ "6": "I-BUILDINGNUM",
66
+ "7": "B-DATEOFBIRTH",
67
+ "8": "I-DATEOFBIRTH",
68
+ "9": "B-EMAIL",
69
+ "10": "I-EMAIL",
70
+ "11": "B-PHONENUMBER",
71
+ "12": "I-PHONENUMBER",
72
+ "13": "B-CITY",
73
+ "14": "I-CITY",
74
+ "15": "B-URL",
75
+ "16": "I-URL",
76
+ "17": "B-COMPANYNAME",
77
+ "18": "I-COMPANYNAME",
78
+ "19": "B-STATE",
79
+ "20": "I-STATE",
80
+ "21": "B-ZIP",
81
+ "22": "I-ZIP",
82
+ "23": "B-STREET",
83
+ "24": "I-STREET",
84
+ "25": "B-COUNTRY",
85
+ "26": "I-COUNTRY",
86
+ "27": "B-SSN",
87
+ "28": "I-SSN",
88
+ "29": "B-DRIVERLICENSENUM",
89
+ "30": "I-DRIVERLICENSENUM",
90
+ "31": "B-PASSPORTID",
91
+ "32": "I-PASSPORTID",
92
+ "33": "B-NATIONALID",
93
+ "34": "I-NATIONALID",
94
+ "35": "B-IDCARDNUM",
95
+ "36": "I-IDCARDNUM",
96
+ "37": "B-TAXNUM",
97
+ "38": "I-TAXNUM",
98
+ "39": "B-LICENSEPLATENUM",
99
+ "40": "I-LICENSEPLATENUM",
100
+ "41": "B-PASSWORD",
101
+ "42": "I-PASSWORD",
102
+ "43": "B-IBAN",
103
+ "44": "I-IBAN",
104
+ "45": "B-AGE",
105
+ "46": "I-AGE",
106
+ "47": "B-SECURITYTOKEN",
107
+ "48": "I-SECURITYTOKEN",
108
+ "49": "B-CREDITCARDNUMBER",
109
+ "50": "I-CREDITCARDNUMBER",
110
+ "51": "B-USERNAME",
111
+ "52": "I-USERNAME",
112
+ "-100": "IGNORE"
113
+ }
114
+ },
115
+ "coref": {
116
+ "id2label": {
117
+ "0": "NO_COREF",
118
+ "1": "CLUSTER_0",
119
+ "2": "CLUSTER_1",
120
+ "3": "CLUSTER_2",
121
+ "4": "CLUSTER_3",
122
+ "5": "CLUSTER_4",
123
+ "6": "CLUSTER_5"
124
+ }
125
+ }
126
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:246b7e3f3f1e0369155ad84c55efa9769ddd149861f9ce7f93a8f293ab58ee7e
3
+ size 260960440
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": false,
45
+ "cls_token": "[CLS]",
46
+ "do_lower_case": false,
47
+ "extra_special_tokens": {},
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 512,
50
+ "pad_token": "[PAD]",
51
+ "sep_token": "[SEP]",
52
+ "strip_accents": null,
53
+ "tokenize_chinese_chars": true,
54
+ "tokenizer_class": "DistilBertTokenizer",
55
+ "unk_token": "[UNK]"
56
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff