seongyeon1 commited on
Commit
9d83044
·
verified ·
1 Parent(s): fb05fac

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - fr
5
+ - de
6
+ - it
7
+ license: apache-2.0
8
+ library_name: transformers
9
+ tags:
10
+ - pii
11
+ - ner
12
+ - token-classification
13
+ - privacy
14
+ - deberta-v3
15
+ datasets:
16
+ - ai4privacy/pii-masking-200k
17
+ - nvidia/Nemotron-PII
18
+ metrics:
19
+ - f1
20
+ - precision
21
+ - recall
22
+ pipeline_tag: token-classification
23
+ model-index:
24
+ - name: pii-deberta-v3-base-multi
25
+ results:
26
+ - task:
27
+ type: token-classification
28
+ name: PII Detection (NER)
29
+ metrics:
30
+ - type: f1
31
+ value: 0.9766
32
+ name: Entity-level F1
33
+ - type: precision
34
+ value: 0.9703
35
+ name: Entity-level Precision
36
+ - type: recall
37
+ value: 0.9830
38
+ name: Entity-level Recall
39
+ ---
40
+
41
+ # PII Detection — DeBERTa-v3-base (Multi-Dataset)
42
+
43
+ A token classification (NER) model for **Personally Identifiable Information (PII) detection**, fine-tuned on a combination of [ai4privacy/pii-masking-200k](https://huggingface.co/datasets/ai4privacy/pii-masking-200k) and [nvidia/Nemotron-PII](https://huggingface.co/datasets/nvidia/Nemotron-PII) datasets.
44
+
45
+ ## Model Description
46
+
47
+ - **Base model**: [microsoft/deberta-v3-base](https://huggingface.co/microsoft/deberta-v3-base)
48
+ - **Task**: Token Classification (BIO tagging)
49
+ - **Loss**: Focal Loss (alpha=1.0, gamma=2.0)
50
+ - **Parameters**: 183M
51
+
52
+ ## Supported Entity Types (7 types, Kaggle PII standard)
53
+
54
+ | Entity | Description | F1 |
55
+ |--------|-------------|-----|
56
+ | `NAME_STUDENT` | Person names | 0.979 |
57
+ | `EMAIL` | Email addresses | 0.992 |
58
+ | `USERNAME` | Usernames | 0.980 |
59
+ | `ID_NUM` | ID numbers (SSN, credit card, passport, etc.) | 0.980 |
60
+ | `PHONE_NUM` | Phone numbers | 0.992 |
61
+ | `URL_PERSONAL` | Personal URLs | 0.992 |
62
+ | `STREET_ADDRESS` | Street addresses | 0.958 |
63
+
64
+ ## Usage
65
+
66
+ ```python
67
+ from transformers import AutoModelForTokenClassification, AutoTokenizer
68
+ import torch
69
+
70
+ model_name = "seongyeon1/pii-deberta-v3-base-multi"
71
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
72
+ model = AutoModelForTokenClassification.from_pretrained(model_name)
73
+
74
+ text = "My name is John Smith and my email is john@example.com"
75
+ inputs = tokenizer(text, return_tensors="pt", return_offsets_mapping=True)
76
+ offset_mapping = inputs.pop("offset_mapping")
77
+
78
+ with torch.no_grad():
79
+ outputs = model(**inputs)
80
+ predictions = torch.argmax(outputs.logits, dim=-1)[0]
81
+
82
+ for idx, (pred, (start, end)) in enumerate(zip(predictions, offset_mapping[0])):
83
+ label = model.config.id2label[pred.item()]
84
+ if label != "O" and start != 0 and end != 0:
85
+ print(f"{text[start:end]} -> {label}")
86
+ ```
87
+
88
+ ## Training Details
89
+
90
+ | Setting | Value |
91
+ |---------|-------|
92
+ | Epochs | 3 |
93
+ | Learning Rate | 2e-5 |
94
+ | Batch Size | 8 |
95
+ | Max Length | 256 |
96
+ | Warmup Steps | 200 |
97
+ | Optimizer | AdamW |
98
+ | Training Data | ~9,000 samples (ai4privacy 5K + Nemotron 5K) |
99
+ | Training Time | ~29 minutes (Apple MPS) |
100
+
101
+ ### Label Merge Strategy
102
+
103
+ 54+ entity types from source datasets are merged into 7 standard Kaggle PII types:
104
+ - `FIRSTNAME`, `LASTNAME`, `GIVENNAME`, `SURNAME` → `NAME_STUDENT`
105
+ - `SSN`, `CREDITCARDNUMBER`, `IBAN`, `PASSPORT`, ... → `ID_NUM`
106
+ - `PHONENUMBER`, `TEL`, `TELEPHONENUM` → `PHONE_NUM`
107
+ - `CITY`, `STATE`, `ZIPCODE`, `STREET` → `STREET_ADDRESS`
108
+
109
+ ## Evaluation Results
110
+
111
+ | Metric | Score |
112
+ |--------|-------|
113
+ | **F1 (entity-level)** | **0.9766** |
114
+ | Precision | 0.9703 |
115
+ | Recall | 0.9830 |
116
+ | F5 (recall-weighted) | 0.9825 |
117
+ | Eval Loss | 0.0014 |
118
+
119
+ ## Training Loss Curve
120
+
121
+ | Epoch | Train Loss | Eval F1 | Eval F5 |
122
+ |-------|-----------|---------|---------|
123
+ | 1 | 0.0039 | 0.9434 | 0.9560 |
124
+ | 2 | 0.0023 | 0.9738 | 0.9777 |
125
+ | 3 | 0.0012 | 0.9766 | 0.9825 |
126
+
127
+ ## Framework
128
+
129
+ Built with [PolyBed-Pipeline](https://github.com/teddynote-lab/PolyBed-Pipeline) PII Channel.
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "[MASK]": 128000
3
+ }
config.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "microsoft/deberta-v3-base",
3
+ "architectures": [
4
+ "DebertaV2ForTokenClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "id2label": {
11
+ "0": "O",
12
+ "1": "B-NAME_STUDENT",
13
+ "2": "I-NAME_STUDENT",
14
+ "3": "B-EMAIL",
15
+ "4": "I-EMAIL",
16
+ "5": "B-USERNAME",
17
+ "6": "I-USERNAME",
18
+ "7": "B-ID_NUM",
19
+ "8": "I-ID_NUM",
20
+ "9": "B-PHONE_NUM",
21
+ "10": "I-PHONE_NUM",
22
+ "11": "B-URL_PERSONAL",
23
+ "12": "I-URL_PERSONAL",
24
+ "13": "B-STREET_ADDRESS",
25
+ "14": "I-STREET_ADDRESS"
26
+ },
27
+ "initializer_range": 0.02,
28
+ "intermediate_size": 3072,
29
+ "label2id": {
30
+ "B-EMAIL": 3,
31
+ "B-ID_NUM": 7,
32
+ "B-NAME_STUDENT": 1,
33
+ "B-PHONE_NUM": 9,
34
+ "B-STREET_ADDRESS": 13,
35
+ "B-URL_PERSONAL": 11,
36
+ "B-USERNAME": 5,
37
+ "I-EMAIL": 4,
38
+ "I-ID_NUM": 8,
39
+ "I-NAME_STUDENT": 2,
40
+ "I-PHONE_NUM": 10,
41
+ "I-STREET_ADDRESS": 14,
42
+ "I-URL_PERSONAL": 12,
43
+ "I-USERNAME": 6,
44
+ "O": 0
45
+ },
46
+ "layer_norm_eps": 1e-07,
47
+ "max_position_embeddings": 512,
48
+ "max_relative_positions": -1,
49
+ "model_type": "deberta-v2",
50
+ "norm_rel_ebd": "layer_norm",
51
+ "num_attention_heads": 12,
52
+ "num_hidden_layers": 12,
53
+ "pad_token_id": 0,
54
+ "pooler_dropout": 0,
55
+ "pooler_hidden_act": "gelu",
56
+ "pooler_hidden_size": 768,
57
+ "pos_att_type": [
58
+ "p2c",
59
+ "c2p"
60
+ ],
61
+ "position_biased_input": false,
62
+ "position_buckets": 256,
63
+ "relative_attention": true,
64
+ "share_att_key": true,
65
+ "torch_dtype": "float32",
66
+ "transformers_version": "4.45.2",
67
+ "type_vocab_size": 0,
68
+ "vocab_size": 128100
69
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:15b29afa36ae49d95cb49f6593446f5b1d9391b4cf3e1e196ab95af2978dd149
3
+ size 735396724
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "[CLS]",
3
+ "cls_token": "[CLS]",
4
+ "eos_token": "[SEP]",
5
+ "mask_token": "[MASK]",
6
+ "pad_token": "[PAD]",
7
+ "sep_token": "[SEP]",
8
+ "unk_token": {
9
+ "content": "[UNK]",
10
+ "lstrip": false,
11
+ "normalized": true,
12
+ "rstrip": false,
13
+ "single_word": false
14
+ }
15
+ }
spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c679fbf93643d19aab7ee10c0b99e460bdbc02fedf34b92b05af343b4af586fd
3
+ size 2464616
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "1": {
12
+ "content": "[CLS]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[SEP]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[UNK]",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "128000": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "[CLS]",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "[CLS]",
47
+ "do_lower_case": false,
48
+ "eos_token": "[SEP]",
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "pad_token": "[PAD]",
52
+ "sep_token": "[SEP]",
53
+ "sp_model_kwargs": {},
54
+ "split_by_punct": false,
55
+ "tokenizer_class": "DebertaV2Tokenizer",
56
+ "unk_token": "[UNK]",
57
+ "vocab_type": "spm"
58
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d40987a7feeea80402039315e6f3712bf13c8d003305d6bd97f639807b80d03
3
+ size 5777