Feature Extraction
Transformers
Safetensors
English
dual_head_bert
bert
data-governance
schema-matching
pii-detection
custom_code
Instructions to use sairaamv1/small-lm-data-element with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sairaamv1/small-lm-data-element with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="sairaamv1/small-lm-data-element", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("sairaamv1/small-lm-data-element", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- README.md +12 -12
- __pycache__/modeling_dual_head.cpython-314.pyc +0 -0
- config.json +442 -437
- model.safetensors +2 -2
- modeling_dual_head.py +15 -4
README.md
CHANGED
|
@@ -27,21 +27,21 @@ and wrong predictions have overlapping confidence distributions, so no cutoff cl
|
|
| 27 |
|
| 28 |
## Benchmarks
|
| 29 |
|
| 30 |
-
- End-to-end accuracy (gate right, and type right if PII): **
|
| 31 |
-
- PII gate: accuracy **
|
| 32 |
-
- Type accuracy given true PII: **
|
| 33 |
-
- CPU inference latency: **
|
| 34 |
-
- Best epoch:
|
| 35 |
|
| 36 |
Lowest-accuracy categories on the test set (PII rows only):
|
| 37 |
|
| 38 |
| Category | Accuracy |
|
| 39 |
|---|---|
|
| 40 |
-
|
|
| 41 |
-
|
|
| 42 |
-
|
|
| 43 |
-
|
|
| 44 |
-
|
|
| 45 |
|
| 46 |
## Out-of-distribution benchmark
|
| 47 |
|
|
@@ -57,8 +57,8 @@ HubSpot, GitHub, DMV) added only after the training data below was finalized, an
|
|
| 57 |
not-PII** batch (24 rows) of system/infra field names (AWS, Kafka,
|
| 58 |
Datadog, Segment) added the same way, to get an uncontaminated read on the gate.
|
| 59 |
|
| 60 |
-
**Combined:
|
| 61 |
-
|
| 62 |
**100.0%** on the four sources). Take the first two
|
| 63 |
with a grain of salt — some of their miss-words ended up in this model's training vocabulary, so
|
| 64 |
part of that score is memorization. **The two fresh sources are the honest numbers**: real
|
|
|
|
| 27 |
|
| 28 |
## Benchmarks
|
| 29 |
|
| 30 |
+
- End-to-end accuracy (gate right, and type right if PII): **93.90%** (4440 held-out examples)
|
| 31 |
+
- PII gate: accuracy **99.10%**, precision 99.20%, recall 99.61%, F1 99.40%
|
| 32 |
+
- Type accuracy given true PII: **92.70%** (3343 PII rows)
|
| 33 |
+
- CPU inference latency: **2.12 ms/example** (single thread, batch size 1)
|
| 34 |
+
- Best epoch: 90, validation end-to-end accuracy 94.27%
|
| 35 |
|
| 36 |
Lowest-accuracy categories on the test set (PII rows only):
|
| 37 |
|
| 38 |
| Category | Accuracy |
|
| 39 |
|---|---|
|
| 40 |
+
| Health & Biometric Data | 38.5% |
|
| 41 |
+
| Transaction Data | 87.7% |
|
| 42 |
+
| Authentication Data | 88.1% |
|
| 43 |
+
| Cookies & Tracking | 88.5% |
|
| 44 |
+
| Communication & Behavioral Data | 88.5% |
|
| 45 |
|
| 46 |
## Out-of-distribution benchmark
|
| 47 |
|
|
|
|
| 57 |
not-PII** batch (24 rows) of system/infra field names (AWS, Kafka,
|
| 58 |
Datadog, Segment) added the same way, to get an uncontaminated read on the gate.
|
| 59 |
|
| 60 |
+
**Combined: 91.3%** (84.4% /
|
| 61 |
+
100.0% / **96.2%** /
|
| 62 |
**100.0%** on the four sources). Take the first two
|
| 63 |
with a grain of salt — some of their miss-words ended up in this model's training vocabulary, so
|
| 64 |
part of that score is memorization. **The two fresh sources are the honest numbers**: real
|
__pycache__/modeling_dual_head.cpython-314.pyc
CHANGED
|
Binary files a/__pycache__/modeling_dual_head.cpython-314.pyc and b/__pycache__/modeling_dual_head.cpython-314.pyc differ
|
|
|
config.json
CHANGED
|
@@ -53,224 +53,226 @@
|
|
| 53 |
"37": "Check-in Data",
|
| 54 |
"38": "Children Information",
|
| 55 |
"39": "Churn Prediction Data",
|
| 56 |
-
"40": "
|
| 57 |
-
"41": "
|
| 58 |
-
"42": "
|
| 59 |
-
"43": "
|
| 60 |
-
"44": "
|
| 61 |
-
"45": "
|
| 62 |
-
"46": "
|
| 63 |
-
"47": "
|
| 64 |
-
"48": "
|
| 65 |
-
"49": "
|
| 66 |
-
"50": "Credit
|
| 67 |
-
"51": "Credit
|
| 68 |
-
"52": "Credit Score (
|
| 69 |
-
"53": "Credit Score (
|
| 70 |
-
"54": "Credit
|
| 71 |
-
"55": "
|
| 72 |
-
"56": "
|
| 73 |
-
"57": "Customer
|
| 74 |
-
"58": "
|
| 75 |
-
"59": "
|
| 76 |
-
"60": "
|
| 77 |
-
"61": "Degree
|
| 78 |
-
"62": "
|
| 79 |
-
"63": "Delivery
|
| 80 |
-
"64": "Delivery
|
| 81 |
-
"65": "Delivery
|
| 82 |
-
"66": "Delivery
|
| 83 |
-
"67": "
|
| 84 |
-
"68": "
|
| 85 |
-
"69": "Device
|
| 86 |
-
"70": "Device
|
| 87 |
-
"71": "
|
| 88 |
-
"72": "
|
| 89 |
-
"73": "
|
| 90 |
-
"74": "
|
| 91 |
-
"75": "
|
| 92 |
-
"76": "Disability
|
| 93 |
-
"77": "
|
| 94 |
-
"78": "
|
| 95 |
-
"79": "
|
| 96 |
-
"80": "
|
| 97 |
-
"81": "
|
| 98 |
-
"82": "
|
| 99 |
-
"83": "
|
| 100 |
-
"84": "
|
| 101 |
-
"85": "
|
| 102 |
-
"86": "
|
| 103 |
-
"87": "
|
| 104 |
-
"88": "
|
| 105 |
-
"89": "
|
| 106 |
-
"90": "
|
| 107 |
-
"91": "
|
| 108 |
-
"92": "
|
| 109 |
-
"93": "
|
| 110 |
-
"94": "
|
| 111 |
-
"95": "
|
| 112 |
-
"96": "
|
| 113 |
-
"97": "
|
| 114 |
-
"98": "
|
| 115 |
-
"99": "
|
| 116 |
-
"100": "
|
| 117 |
-
"101": "
|
| 118 |
-
"102": "
|
| 119 |
-
"103": "
|
| 120 |
-
"104": "
|
| 121 |
-
"105": "
|
| 122 |
-
"106": "
|
| 123 |
-
"107": "
|
| 124 |
-
"108": "
|
| 125 |
-
"109": "
|
| 126 |
-
"110": "
|
| 127 |
-
"111": "
|
| 128 |
-
"112": "
|
| 129 |
-
"113": "
|
| 130 |
-
"114": "
|
| 131 |
-
"115": "
|
| 132 |
-
"116": "
|
| 133 |
-
"117": "
|
| 134 |
-
"118": "
|
| 135 |
-
"119": "
|
| 136 |
-
"120": "
|
| 137 |
-
"121": "
|
| 138 |
-
"122": "
|
| 139 |
-
"123": "
|
| 140 |
-
"124": "
|
| 141 |
-
"125": "
|
| 142 |
-
"126": "
|
| 143 |
-
"127": "
|
| 144 |
-
"128": "
|
| 145 |
-
"129": "
|
| 146 |
-
"130": "
|
| 147 |
-
"131": "
|
| 148 |
-
"132": "
|
| 149 |
-
"133": "
|
| 150 |
-
"134": "
|
| 151 |
-
"135": "
|
| 152 |
-
"136": "
|
| 153 |
-
"137": "
|
| 154 |
-
"138": "
|
| 155 |
-
"139": "
|
| 156 |
-
"140": "
|
| 157 |
-
"141": "
|
| 158 |
-
"142": "
|
| 159 |
-
"143": "
|
| 160 |
-
"144": "
|
| 161 |
-
"145": "
|
| 162 |
-
"146": "
|
| 163 |
-
"147": "
|
| 164 |
-
"148": "
|
| 165 |
-
"149": "
|
| 166 |
-
"150": "
|
| 167 |
-
"151": "
|
| 168 |
-
"152": "Nominee
|
| 169 |
-
"153": "Nominee
|
| 170 |
-
"154": "
|
| 171 |
-
"155": "
|
| 172 |
-
"156": "
|
| 173 |
-
"157": "
|
| 174 |
-
"158": "
|
| 175 |
-
"159": "
|
| 176 |
-
"160": "
|
| 177 |
-
"161": "
|
| 178 |
-
"162": "
|
| 179 |
-
"163": "
|
| 180 |
-
"164": "
|
| 181 |
-
"165": "
|
| 182 |
-
"166": "
|
| 183 |
-
"167": "
|
| 184 |
-
"168": "
|
| 185 |
-
"169": "
|
| 186 |
-
"170": "
|
| 187 |
-
"171": "
|
| 188 |
-
"172": "
|
| 189 |
-
"173": "
|
| 190 |
-
"174": "
|
| 191 |
-
"175": "
|
| 192 |
-
"176": "
|
| 193 |
-
"177": "
|
| 194 |
-
"178": "
|
| 195 |
-
"179": "
|
| 196 |
-
"180": "
|
| 197 |
-
"181": "
|
| 198 |
-
"182": "
|
| 199 |
-
"183": "
|
| 200 |
-
"184": "
|
| 201 |
-
"185": "
|
| 202 |
-
"186": "
|
| 203 |
-
"187": "
|
| 204 |
-
"188": "
|
| 205 |
-
"189": "
|
| 206 |
-
"190": "
|
| 207 |
-
"191": "
|
| 208 |
-
"192": "
|
| 209 |
-
"193": "
|
| 210 |
-
"194": "
|
| 211 |
-
"195": "
|
| 212 |
-
"196": "
|
| 213 |
-
"197": "
|
| 214 |
-
"198": "
|
| 215 |
-
"199": "
|
| 216 |
-
"200": "Risk
|
| 217 |
-
"201": "
|
| 218 |
-
"202": "
|
| 219 |
-
"203": "
|
| 220 |
-
"204": "
|
| 221 |
-
"205": "
|
| 222 |
-
"206": "
|
| 223 |
-
"207": "
|
| 224 |
-
"208": "
|
| 225 |
-
"209": "
|
| 226 |
-
"210": "
|
| 227 |
-
"211": "Service
|
| 228 |
-
"212": "
|
| 229 |
-
"213": "
|
| 230 |
-
"214": "
|
| 231 |
-
"215": "
|
| 232 |
-
"216": "
|
| 233 |
-
"217": "
|
| 234 |
-
"218": "
|
| 235 |
-
"219": "
|
| 236 |
-
"220": "
|
| 237 |
-
"221": "
|
| 238 |
-
"222": "Social
|
| 239 |
-
"223": "Social
|
| 240 |
-
"224": "
|
| 241 |
-
"225": "
|
| 242 |
-
"226": "
|
| 243 |
-
"227": "
|
| 244 |
-
"228": "
|
| 245 |
-
"229": "
|
| 246 |
-
"230": "
|
| 247 |
-
"231": "
|
| 248 |
-
"232": "
|
| 249 |
-
"233": "
|
| 250 |
-
"234": "
|
| 251 |
-
"235": "
|
| 252 |
-
"236": "
|
| 253 |
-
"237": "
|
| 254 |
-
"238": "
|
| 255 |
-
"239": "
|
| 256 |
-
"240": "
|
| 257 |
-
"241": "
|
| 258 |
-
"242": "
|
| 259 |
-
"243": "
|
| 260 |
-
"244": "
|
| 261 |
-
"245": "
|
| 262 |
-
"246": "Vehicle
|
| 263 |
-
"247": "
|
| 264 |
-
"248": "
|
| 265 |
-
"249": "
|
| 266 |
-
"250": "
|
| 267 |
-
"251": "
|
| 268 |
-
"252": "
|
| 269 |
-
"253": "
|
| 270 |
-
"254": "
|
| 271 |
-
"255": "
|
| 272 |
-
"256": "
|
| 273 |
-
"257": "
|
|
|
|
|
|
|
| 274 |
},
|
| 275 |
"initializer_range": 0.02,
|
| 276 |
"intermediate_size": 1536,
|
|
@@ -280,7 +282,7 @@
|
|
| 280 |
"model_type": "dual_head_bert",
|
| 281 |
"num_attention_heads": 12,
|
| 282 |
"num_hidden_layers": 6,
|
| 283 |
-
"num_type_labels":
|
| 284 |
"pad_token_id": 0,
|
| 285 |
"pii_loss_weight": 1.0,
|
| 286 |
"position_embedding_type": "absolute",
|
|
@@ -327,228 +329,231 @@
|
|
| 327 |
"Check-in Data": 37,
|
| 328 |
"Children Information": 38,
|
| 329 |
"Churn Prediction Data": 39,
|
| 330 |
-
"
|
| 331 |
-
"
|
| 332 |
-
"
|
| 333 |
-
"
|
| 334 |
-
"
|
| 335 |
-
"
|
| 336 |
-
"
|
| 337 |
-
"
|
| 338 |
-
"
|
| 339 |
-
"
|
| 340 |
-
"Credit
|
| 341 |
-
"Credit
|
| 342 |
-
"Credit Score (
|
| 343 |
-
"Credit Score (
|
| 344 |
-
"Credit
|
| 345 |
-
"
|
| 346 |
-
"
|
| 347 |
-
"Customer
|
| 348 |
-
"
|
| 349 |
-
"
|
| 350 |
-
"
|
| 351 |
-
"Degree
|
| 352 |
-
"
|
| 353 |
-
"Delivery
|
| 354 |
-
"Delivery
|
| 355 |
-
"Delivery
|
| 356 |
-
"Delivery
|
| 357 |
-
"
|
| 358 |
-
"
|
| 359 |
-
"Device
|
| 360 |
-
"Device
|
| 361 |
-
"
|
| 362 |
-
"
|
| 363 |
-
"
|
| 364 |
-
"
|
| 365 |
-
"
|
| 366 |
-
"Disability
|
| 367 |
-
"
|
| 368 |
-
"
|
| 369 |
-
"
|
| 370 |
-
"
|
| 371 |
-
"
|
| 372 |
-
"
|
| 373 |
-
"
|
| 374 |
-
"
|
| 375 |
-
"
|
| 376 |
-
"
|
| 377 |
-
"
|
| 378 |
-
"
|
| 379 |
-
"
|
| 380 |
-
"
|
| 381 |
-
"
|
| 382 |
-
"
|
| 383 |
-
"
|
| 384 |
-
"
|
| 385 |
-
"
|
| 386 |
-
"
|
| 387 |
-
"
|
| 388 |
-
"
|
| 389 |
-
"
|
| 390 |
-
"
|
| 391 |
-
"
|
| 392 |
-
"
|
| 393 |
-
"
|
| 394 |
-
"
|
| 395 |
-
"
|
| 396 |
-
"
|
| 397 |
-
"
|
| 398 |
-
"
|
| 399 |
-
"
|
| 400 |
-
"
|
| 401 |
-
"
|
| 402 |
-
"
|
| 403 |
-
"
|
| 404 |
-
"
|
| 405 |
-
"
|
| 406 |
-
"
|
| 407 |
-
"
|
| 408 |
-
"
|
| 409 |
-
"
|
| 410 |
-
"
|
| 411 |
-
"
|
| 412 |
-
"
|
| 413 |
-
"
|
| 414 |
-
"
|
| 415 |
-
"
|
| 416 |
-
"
|
| 417 |
-
"
|
| 418 |
-
"
|
| 419 |
-
"
|
| 420 |
-
"
|
| 421 |
-
"
|
| 422 |
-
"
|
| 423 |
-
"
|
| 424 |
-
"
|
| 425 |
-
"
|
| 426 |
-
"
|
| 427 |
-
"
|
| 428 |
-
"
|
| 429 |
-
"
|
| 430 |
-
"
|
| 431 |
-
"
|
| 432 |
-
"
|
| 433 |
-
"
|
| 434 |
-
"
|
| 435 |
-
"
|
| 436 |
-
"
|
| 437 |
-
"
|
| 438 |
-
"
|
| 439 |
-
"
|
| 440 |
-
"
|
| 441 |
-
"
|
| 442 |
-
"Nominee
|
| 443 |
-
"Nominee
|
| 444 |
-
"
|
| 445 |
-
"
|
| 446 |
-
"
|
| 447 |
-
"
|
| 448 |
-
"
|
| 449 |
-
"
|
| 450 |
-
"
|
| 451 |
-
"
|
| 452 |
-
"
|
| 453 |
-
"
|
| 454 |
-
"
|
| 455 |
-
"
|
| 456 |
-
"
|
| 457 |
-
"
|
| 458 |
-
"
|
| 459 |
-
"
|
| 460 |
-
"
|
| 461 |
-
"
|
| 462 |
-
"
|
| 463 |
-
"
|
| 464 |
-
"
|
| 465 |
-
"
|
| 466 |
-
"
|
| 467 |
-
"
|
| 468 |
-
"
|
| 469 |
-
"
|
| 470 |
-
"
|
| 471 |
-
"
|
| 472 |
-
"
|
| 473 |
-
"
|
| 474 |
-
"
|
| 475 |
-
"
|
| 476 |
-
"
|
| 477 |
-
"
|
| 478 |
-
"
|
| 479 |
-
"
|
| 480 |
-
"
|
| 481 |
-
"
|
| 482 |
-
"
|
| 483 |
-
"
|
| 484 |
-
"
|
| 485 |
-
"
|
| 486 |
-
"
|
| 487 |
-
"
|
| 488 |
-
"
|
| 489 |
-
"
|
| 490 |
-
"Risk
|
| 491 |
-
"
|
| 492 |
-
"
|
| 493 |
-
"
|
| 494 |
-
"
|
| 495 |
-
"
|
| 496 |
-
"
|
| 497 |
-
"
|
| 498 |
-
"
|
| 499 |
-
"
|
| 500 |
-
"
|
| 501 |
-
"Service
|
| 502 |
-
"
|
| 503 |
-
"
|
| 504 |
-
"
|
| 505 |
-
"
|
| 506 |
-
"
|
| 507 |
-
"
|
| 508 |
-
"
|
| 509 |
-
"
|
| 510 |
-
"
|
| 511 |
-
"
|
| 512 |
-
"Social
|
| 513 |
-
"Social
|
| 514 |
-
"
|
| 515 |
-
"
|
| 516 |
-
"
|
| 517 |
-
"
|
| 518 |
-
"
|
| 519 |
-
"
|
| 520 |
-
"
|
| 521 |
-
"
|
| 522 |
-
"
|
| 523 |
-
"
|
| 524 |
-
"
|
| 525 |
-
"
|
| 526 |
-
"
|
| 527 |
-
"
|
| 528 |
-
"
|
| 529 |
-
"
|
| 530 |
-
"
|
| 531 |
-
"
|
| 532 |
-
"
|
| 533 |
-
"
|
| 534 |
-
"
|
| 535 |
-
"
|
| 536 |
-
"Vehicle
|
| 537 |
-
"
|
| 538 |
-
"
|
| 539 |
-
"
|
| 540 |
-
"
|
| 541 |
-
"
|
| 542 |
-
"
|
| 543 |
-
"
|
| 544 |
-
"
|
| 545 |
-
"
|
| 546 |
-
"
|
| 547 |
-
"
|
|
|
|
|
|
|
| 548 |
},
|
| 549 |
"type_loss_weight": 1.0,
|
| 550 |
"type_vocab_size": 2,
|
| 551 |
"vocab_size": 30522,
|
|
|
|
| 552 |
"auto_map": {
|
| 553 |
"AutoConfig": "modeling_dual_head.DualHeadConfig",
|
| 554 |
"AutoModel": "modeling_dual_head.DualHeadBertForPIIClassification"
|
|
|
|
| 53 |
"37": "Check-in Data",
|
| 54 |
"38": "Children Information",
|
| 55 |
"39": "Churn Prediction Data",
|
| 56 |
+
"40": "City",
|
| 57 |
+
"41": "Claim History",
|
| 58 |
+
"42": "Collateral Information",
|
| 59 |
+
"43": "Communication Records",
|
| 60 |
+
"44": "Consent Records",
|
| 61 |
+
"45": "Content Creation Data",
|
| 62 |
+
"46": "Continuing Education",
|
| 63 |
+
"47": "Cookie ID",
|
| 64 |
+
"48": "Courses Completed",
|
| 65 |
+
"49": "Coverage Details",
|
| 66 |
+
"50": "Credit History",
|
| 67 |
+
"51": "Credit Limit",
|
| 68 |
+
"52": "Credit Score (CIBIL)",
|
| 69 |
+
"53": "Credit Score (Equifax)",
|
| 70 |
+
"54": "Credit Score (Experian)",
|
| 71 |
+
"55": "Credit Utilization Ratio",
|
| 72 |
+
"56": "Criminal History",
|
| 73 |
+
"57": "Customer Lifetime Value",
|
| 74 |
+
"58": "Customer Support Interactions",
|
| 75 |
+
"59": "Date of Birth",
|
| 76 |
+
"60": "Default Records",
|
| 77 |
+
"61": "Degree Certificate",
|
| 78 |
+
"62": "Degree Number",
|
| 79 |
+
"63": "Delivery Address",
|
| 80 |
+
"64": "Delivery History",
|
| 81 |
+
"65": "Delivery Instructions",
|
| 82 |
+
"66": "Delivery Preferences",
|
| 83 |
+
"67": "Delivery Time Slots",
|
| 84 |
+
"68": "Deposit Amount",
|
| 85 |
+
"69": "Device Brand",
|
| 86 |
+
"70": "Device ID",
|
| 87 |
+
"71": "Device Model",
|
| 88 |
+
"72": "Device-bound Credentials",
|
| 89 |
+
"73": "Dietary Preferences",
|
| 90 |
+
"74": "Digital Signature",
|
| 91 |
+
"75": "Digital Wallet ID",
|
| 92 |
+
"76": "Disability Severity / Level",
|
| 93 |
+
"77": "Disability Status",
|
| 94 |
+
"78": "Disability Type",
|
| 95 |
+
"79": "Discount Usage",
|
| 96 |
+
"80": "Dividend History",
|
| 97 |
+
"81": "Download History",
|
| 98 |
+
"82": "Drinking Habits",
|
| 99 |
+
"83": "Driver\u2019s License Number",
|
| 100 |
+
"84": "EPF Number",
|
| 101 |
+
"85": "Email Address",
|
| 102 |
+
"86": "Emergency Contact Details",
|
| 103 |
+
"87": "Employee ID",
|
| 104 |
+
"88": "Employer Name",
|
| 105 |
+
"89": "Employment Contract",
|
| 106 |
+
"90": "Employment History",
|
| 107 |
+
"91": "Ethnic Origin",
|
| 108 |
+
"92": "Expense Categories",
|
| 109 |
+
"93": "Failed Delivery Attempts",
|
| 110 |
+
"94": "Family Information",
|
| 111 |
+
"95": "Feedback & Reviews",
|
| 112 |
+
"96": "Financial Goals",
|
| 113 |
+
"97": "First Name",
|
| 114 |
+
"98": "Fraud Alerts",
|
| 115 |
+
"99": "Full Name",
|
| 116 |
+
"100": "Functional Cookies",
|
| 117 |
+
"101": "GST Number",
|
| 118 |
+
"102": "Game Progress",
|
| 119 |
+
"103": "Gaming Device Information",
|
| 120 |
+
"104": "Gaming Preferences",
|
| 121 |
+
"105": "Gender",
|
| 122 |
+
"106": "Genetic Data",
|
| 123 |
+
"107": "Graduation Years",
|
| 124 |
+
"108": "Graphical Password Data",
|
| 125 |
+
"109": "Group Memberships",
|
| 126 |
+
"110": "Guarantor Details",
|
| 127 |
+
"111": "HSC Document",
|
| 128 |
+
"112": "Health Insurance Details",
|
| 129 |
+
"113": "Health Records",
|
| 130 |
+
"114": "Horoscope Data",
|
| 131 |
+
"115": "IBAN",
|
| 132 |
+
"116": "IFSC Code",
|
| 133 |
+
"117": "IP Address",
|
| 134 |
+
"118": "Identity Verification Status",
|
| 135 |
+
"119": "In-game Purchases",
|
| 136 |
+
"120": "Income Details",
|
| 137 |
+
"121": "Industry Type",
|
| 138 |
+
"122": "Institution Names",
|
| 139 |
+
"123": "Insurance Policy Number",
|
| 140 |
+
"124": "Interest in Children",
|
| 141 |
+
"125": "Investment Advisor Details",
|
| 142 |
+
"126": "Investment Portfolio",
|
| 143 |
+
"127": "Investment Preferences",
|
| 144 |
+
"128": "Job Title",
|
| 145 |
+
"129": "KYC Documents",
|
| 146 |
+
"130": "LPG / Gas Consumer Number",
|
| 147 |
+
"131": "Last Name",
|
| 148 |
+
"132": "Lead Scoring",
|
| 149 |
+
"133": "Leaderboard Rankings",
|
| 150 |
+
"134": "Learning Progress",
|
| 151 |
+
"135": "Lifestyle Choices",
|
| 152 |
+
"136": "Listening History",
|
| 153 |
+
"137": "Live Stream Participation",
|
| 154 |
+
"138": "Loan Details",
|
| 155 |
+
"139": "Location History",
|
| 156 |
+
"140": "MAC Address",
|
| 157 |
+
"141": "MFA Tokens",
|
| 158 |
+
"142": "Marital Status",
|
| 159 |
+
"143": "Marriage Certificate Date",
|
| 160 |
+
"144": "Marriage Certificate Number",
|
| 161 |
+
"145": "Medical History",
|
| 162 |
+
"146": "Mental Health Data",
|
| 163 |
+
"147": "Middle Name",
|
| 164 |
+
"148": "Multiplayer Interactions",
|
| 165 |
+
"149": "Mutual Fund Holdings",
|
| 166 |
+
"150": "Nationality",
|
| 167 |
+
"151": "Network Information",
|
| 168 |
+
"152": "Nominee Contact Details",
|
| 169 |
+
"153": "Nominee Identifier",
|
| 170 |
+
"154": "Nominee Name",
|
| 171 |
+
"155": "Nominee Relationship",
|
| 172 |
+
"156": "Nominee Share Percentage",
|
| 173 |
+
"157": "OAuth Tokens",
|
| 174 |
+
"158": "Office Address",
|
| 175 |
+
"159": "Operating System",
|
| 176 |
+
"160": "Operating System Version",
|
| 177 |
+
"161": "Order Details",
|
| 178 |
+
"162": "PAN",
|
| 179 |
+
"163": "PIN",
|
| 180 |
+
"164": "PRAN",
|
| 181 |
+
"165": "Packaging Preferences",
|
| 182 |
+
"166": "Partner Preferences",
|
| 183 |
+
"167": "Passport Number",
|
| 184 |
+
"168": "Password (Hashed)",
|
| 185 |
+
"169": "Payment Records",
|
| 186 |
+
"170": "Performance Reviews",
|
| 187 |
+
"171": "Permanent Address",
|
| 188 |
+
"172": "Philosophical Beliefs",
|
| 189 |
+
"173": "Phone Number",
|
| 190 |
+
"174": "Physical Attributes",
|
| 191 |
+
"175": "Place of Birth",
|
| 192 |
+
"176": "Playlist",
|
| 193 |
+
"177": "Policy Modifications",
|
| 194 |
+
"178": "Political Opinions",
|
| 195 |
+
"179": "Portfolio Holdings",
|
| 196 |
+
"180": "Precise Location",
|
| 197 |
+
"181": "Preferences",
|
| 198 |
+
"182": "Preferred Service Areas",
|
| 199 |
+
"183": "Premium Payments",
|
| 200 |
+
"184": "Price Sensitivity",
|
| 201 |
+
"185": "Professional Development",
|
| 202 |
+
"186": "Professional License Numbers",
|
| 203 |
+
"187": "Professional Qualifications",
|
| 204 |
+
"188": "Profile Photo",
|
| 205 |
+
"189": "Promotional Offers Used",
|
| 206 |
+
"190": "Purchase History",
|
| 207 |
+
"191": "Ration Card Number",
|
| 208 |
+
"192": "Recurring Payments",
|
| 209 |
+
"193": "Refund History",
|
| 210 |
+
"194": "Relationship Status",
|
| 211 |
+
"195": "Religious Beliefs",
|
| 212 |
+
"196": "Renewal History",
|
| 213 |
+
"197": "Rescheduling Patterns",
|
| 214 |
+
"198": "Residential Address",
|
| 215 |
+
"199": "Return History",
|
| 216 |
+
"200": "Risk Assessment",
|
| 217 |
+
"201": "Risk Rating",
|
| 218 |
+
"202": "Risk Tolerance",
|
| 219 |
+
"203": "Route Information",
|
| 220 |
+
"204": "Routing Number",
|
| 221 |
+
"205": "SSC Document",
|
| 222 |
+
"206": "SSN (Social Security Number) (US)",
|
| 223 |
+
"207": "Salary",
|
| 224 |
+
"208": "Search History",
|
| 225 |
+
"209": "Security Questions & Answers",
|
| 226 |
+
"210": "Segmentation Data",
|
| 227 |
+
"211": "Service Completion Status",
|
| 228 |
+
"212": "Service Location",
|
| 229 |
+
"213": "Service Usage History",
|
| 230 |
+
"214": "Session IDs",
|
| 231 |
+
"215": "Sexual Orientation",
|
| 232 |
+
"216": "Shared Content",
|
| 233 |
+
"217": "Sharing Behavior",
|
| 234 |
+
"218": "Shipping Address",
|
| 235 |
+
"219": "Shopping Cart Contents",
|
| 236 |
+
"220": "Skills Assessment",
|
| 237 |
+
"221": "Smoking Habits",
|
| 238 |
+
"222": "Social Connections",
|
| 239 |
+
"223": "Social Influence Score",
|
| 240 |
+
"224": "Social Media Activity",
|
| 241 |
+
"225": "Social Media Profiles",
|
| 242 |
+
"226": "Special Handling Instructions",
|
| 243 |
+
"227": "Standing Instructions",
|
| 244 |
+
"228": "Strictly Necessary Cookies",
|
| 245 |
+
"229": "Subscription Data",
|
| 246 |
+
"230": "Survey Responses",
|
| 247 |
+
"231": "Tax Identification Number",
|
| 248 |
+
"232": "Tax Records",
|
| 249 |
+
"233": "Terms Acceptance",
|
| 250 |
+
"234": "Third-party Account ID",
|
| 251 |
+
"235": "Time Spent Gaming",
|
| 252 |
+
"236": "Tracking Information",
|
| 253 |
+
"237": "Trading History",
|
| 254 |
+
"238": "Training Records",
|
| 255 |
+
"239": "Transaction Records",
|
| 256 |
+
"240": "UPI ID",
|
| 257 |
+
"241": "Underwriting Information",
|
| 258 |
+
"242": "Union Membership",
|
| 259 |
+
"243": "Usage Patterns",
|
| 260 |
+
"244": "User Agent",
|
| 261 |
+
"245": "Username / User ID",
|
| 262 |
+
"246": "Vehicle Ownership Details",
|
| 263 |
+
"247": "Vehicle Registration Number",
|
| 264 |
+
"248": "Vehicle Type",
|
| 265 |
+
"249": "Verification Metadata",
|
| 266 |
+
"250": "Verified Identity Data",
|
| 267 |
+
"251": "Viewing History",
|
| 268 |
+
"252": "Virtual Currency",
|
| 269 |
+
"253": "Virtual Items Owned",
|
| 270 |
+
"254": "Voter ID",
|
| 271 |
+
"255": "Watchlist",
|
| 272 |
+
"256": "WiFi Connections",
|
| 273 |
+
"257": "Wishlist Items",
|
| 274 |
+
"258": "Work Email",
|
| 275 |
+
"259": "Work Phone Number"
|
| 276 |
},
|
| 277 |
"initializer_range": 0.02,
|
| 278 |
"intermediate_size": 1536,
|
|
|
|
| 282 |
"model_type": "dual_head_bert",
|
| 283 |
"num_attention_heads": 12,
|
| 284 |
"num_hidden_layers": 6,
|
| 285 |
+
"num_type_labels": 260,
|
| 286 |
"pad_token_id": 0,
|
| 287 |
"pii_loss_weight": 1.0,
|
| 288 |
"position_embedding_type": "absolute",
|
|
|
|
| 329 |
"Check-in Data": 37,
|
| 330 |
"Children Information": 38,
|
| 331 |
"Churn Prediction Data": 39,
|
| 332 |
+
"City": 40,
|
| 333 |
+
"Claim History": 41,
|
| 334 |
+
"Collateral Information": 42,
|
| 335 |
+
"Communication Records": 43,
|
| 336 |
+
"Consent Records": 44,
|
| 337 |
+
"Content Creation Data": 45,
|
| 338 |
+
"Continuing Education": 46,
|
| 339 |
+
"Cookie ID": 47,
|
| 340 |
+
"Courses Completed": 48,
|
| 341 |
+
"Coverage Details": 49,
|
| 342 |
+
"Credit History": 50,
|
| 343 |
+
"Credit Limit": 51,
|
| 344 |
+
"Credit Score (CIBIL)": 52,
|
| 345 |
+
"Credit Score (Equifax)": 53,
|
| 346 |
+
"Credit Score (Experian)": 54,
|
| 347 |
+
"Credit Utilization Ratio": 55,
|
| 348 |
+
"Criminal History": 56,
|
| 349 |
+
"Customer Lifetime Value": 57,
|
| 350 |
+
"Customer Support Interactions": 58,
|
| 351 |
+
"Date of Birth": 59,
|
| 352 |
+
"Default Records": 60,
|
| 353 |
+
"Degree Certificate": 61,
|
| 354 |
+
"Degree Number": 62,
|
| 355 |
+
"Delivery Address": 63,
|
| 356 |
+
"Delivery History": 64,
|
| 357 |
+
"Delivery Instructions": 65,
|
| 358 |
+
"Delivery Preferences": 66,
|
| 359 |
+
"Delivery Time Slots": 67,
|
| 360 |
+
"Deposit Amount": 68,
|
| 361 |
+
"Device Brand": 69,
|
| 362 |
+
"Device ID": 70,
|
| 363 |
+
"Device Model": 71,
|
| 364 |
+
"Device-bound Credentials": 72,
|
| 365 |
+
"Dietary Preferences": 73,
|
| 366 |
+
"Digital Signature": 74,
|
| 367 |
+
"Digital Wallet ID": 75,
|
| 368 |
+
"Disability Severity / Level": 76,
|
| 369 |
+
"Disability Status": 77,
|
| 370 |
+
"Disability Type": 78,
|
| 371 |
+
"Discount Usage": 79,
|
| 372 |
+
"Dividend History": 80,
|
| 373 |
+
"Download History": 81,
|
| 374 |
+
"Drinking Habits": 82,
|
| 375 |
+
"Driver\u2019s License Number": 83,
|
| 376 |
+
"EPF Number": 84,
|
| 377 |
+
"Email Address": 85,
|
| 378 |
+
"Emergency Contact Details": 86,
|
| 379 |
+
"Employee ID": 87,
|
| 380 |
+
"Employer Name": 88,
|
| 381 |
+
"Employment Contract": 89,
|
| 382 |
+
"Employment History": 90,
|
| 383 |
+
"Ethnic Origin": 91,
|
| 384 |
+
"Expense Categories": 92,
|
| 385 |
+
"Failed Delivery Attempts": 93,
|
| 386 |
+
"Family Information": 94,
|
| 387 |
+
"Feedback & Reviews": 95,
|
| 388 |
+
"Financial Goals": 96,
|
| 389 |
+
"First Name": 97,
|
| 390 |
+
"Fraud Alerts": 98,
|
| 391 |
+
"Full Name": 99,
|
| 392 |
+
"Functional Cookies": 100,
|
| 393 |
+
"GST Number": 101,
|
| 394 |
+
"Game Progress": 102,
|
| 395 |
+
"Gaming Device Information": 103,
|
| 396 |
+
"Gaming Preferences": 104,
|
| 397 |
+
"Gender": 105,
|
| 398 |
+
"Genetic Data": 106,
|
| 399 |
+
"Graduation Years": 107,
|
| 400 |
+
"Graphical Password Data": 108,
|
| 401 |
+
"Group Memberships": 109,
|
| 402 |
+
"Guarantor Details": 110,
|
| 403 |
+
"HSC Document": 111,
|
| 404 |
+
"Health Insurance Details": 112,
|
| 405 |
+
"Health Records": 113,
|
| 406 |
+
"Horoscope Data": 114,
|
| 407 |
+
"IBAN": 115,
|
| 408 |
+
"IFSC Code": 116,
|
| 409 |
+
"IP Address": 117,
|
| 410 |
+
"Identity Verification Status": 118,
|
| 411 |
+
"In-game Purchases": 119,
|
| 412 |
+
"Income Details": 120,
|
| 413 |
+
"Industry Type": 121,
|
| 414 |
+
"Institution Names": 122,
|
| 415 |
+
"Insurance Policy Number": 123,
|
| 416 |
+
"Interest in Children": 124,
|
| 417 |
+
"Investment Advisor Details": 125,
|
| 418 |
+
"Investment Portfolio": 126,
|
| 419 |
+
"Investment Preferences": 127,
|
| 420 |
+
"Job Title": 128,
|
| 421 |
+
"KYC Documents": 129,
|
| 422 |
+
"LPG / Gas Consumer Number": 130,
|
| 423 |
+
"Last Name": 131,
|
| 424 |
+
"Lead Scoring": 132,
|
| 425 |
+
"Leaderboard Rankings": 133,
|
| 426 |
+
"Learning Progress": 134,
|
| 427 |
+
"Lifestyle Choices": 135,
|
| 428 |
+
"Listening History": 136,
|
| 429 |
+
"Live Stream Participation": 137,
|
| 430 |
+
"Loan Details": 138,
|
| 431 |
+
"Location History": 139,
|
| 432 |
+
"MAC Address": 140,
|
| 433 |
+
"MFA Tokens": 141,
|
| 434 |
+
"Marital Status": 142,
|
| 435 |
+
"Marriage Certificate Date": 143,
|
| 436 |
+
"Marriage Certificate Number": 144,
|
| 437 |
+
"Medical History": 145,
|
| 438 |
+
"Mental Health Data": 146,
|
| 439 |
+
"Middle Name": 147,
|
| 440 |
+
"Multiplayer Interactions": 148,
|
| 441 |
+
"Mutual Fund Holdings": 149,
|
| 442 |
+
"Nationality": 150,
|
| 443 |
+
"Network Information": 151,
|
| 444 |
+
"Nominee Contact Details": 152,
|
| 445 |
+
"Nominee Identifier": 153,
|
| 446 |
+
"Nominee Name": 154,
|
| 447 |
+
"Nominee Relationship": 155,
|
| 448 |
+
"Nominee Share Percentage": 156,
|
| 449 |
+
"OAuth Tokens": 157,
|
| 450 |
+
"Office Address": 158,
|
| 451 |
+
"Operating System": 159,
|
| 452 |
+
"Operating System Version": 160,
|
| 453 |
+
"Order Details": 161,
|
| 454 |
+
"PAN": 162,
|
| 455 |
+
"PIN": 163,
|
| 456 |
+
"PRAN": 164,
|
| 457 |
+
"Packaging Preferences": 165,
|
| 458 |
+
"Partner Preferences": 166,
|
| 459 |
+
"Passport Number": 167,
|
| 460 |
+
"Password (Hashed)": 168,
|
| 461 |
+
"Payment Records": 169,
|
| 462 |
+
"Performance Reviews": 170,
|
| 463 |
+
"Permanent Address": 171,
|
| 464 |
+
"Philosophical Beliefs": 172,
|
| 465 |
+
"Phone Number": 173,
|
| 466 |
+
"Physical Attributes": 174,
|
| 467 |
+
"Place of Birth": 175,
|
| 468 |
+
"Playlist": 176,
|
| 469 |
+
"Policy Modifications": 177,
|
| 470 |
+
"Political Opinions": 178,
|
| 471 |
+
"Portfolio Holdings": 179,
|
| 472 |
+
"Precise Location": 180,
|
| 473 |
+
"Preferences": 181,
|
| 474 |
+
"Preferred Service Areas": 182,
|
| 475 |
+
"Premium Payments": 183,
|
| 476 |
+
"Price Sensitivity": 184,
|
| 477 |
+
"Professional Development": 185,
|
| 478 |
+
"Professional License Numbers": 186,
|
| 479 |
+
"Professional Qualifications": 187,
|
| 480 |
+
"Profile Photo": 188,
|
| 481 |
+
"Promotional Offers Used": 189,
|
| 482 |
+
"Purchase History": 190,
|
| 483 |
+
"Ration Card Number": 191,
|
| 484 |
+
"Recurring Payments": 192,
|
| 485 |
+
"Refund History": 193,
|
| 486 |
+
"Relationship Status": 194,
|
| 487 |
+
"Religious Beliefs": 195,
|
| 488 |
+
"Renewal History": 196,
|
| 489 |
+
"Rescheduling Patterns": 197,
|
| 490 |
+
"Residential Address": 198,
|
| 491 |
+
"Return History": 199,
|
| 492 |
+
"Risk Assessment": 200,
|
| 493 |
+
"Risk Rating": 201,
|
| 494 |
+
"Risk Tolerance": 202,
|
| 495 |
+
"Route Information": 203,
|
| 496 |
+
"Routing Number": 204,
|
| 497 |
+
"SSC Document": 205,
|
| 498 |
+
"SSN (Social Security Number) (US)": 206,
|
| 499 |
+
"Salary": 207,
|
| 500 |
+
"Search History": 208,
|
| 501 |
+
"Security Questions & Answers": 209,
|
| 502 |
+
"Segmentation Data": 210,
|
| 503 |
+
"Service Completion Status": 211,
|
| 504 |
+
"Service Location": 212,
|
| 505 |
+
"Service Usage History": 213,
|
| 506 |
+
"Session IDs": 214,
|
| 507 |
+
"Sexual Orientation": 215,
|
| 508 |
+
"Shared Content": 216,
|
| 509 |
+
"Sharing Behavior": 217,
|
| 510 |
+
"Shipping Address": 218,
|
| 511 |
+
"Shopping Cart Contents": 219,
|
| 512 |
+
"Skills Assessment": 220,
|
| 513 |
+
"Smoking Habits": 221,
|
| 514 |
+
"Social Connections": 222,
|
| 515 |
+
"Social Influence Score": 223,
|
| 516 |
+
"Social Media Activity": 224,
|
| 517 |
+
"Social Media Profiles": 225,
|
| 518 |
+
"Special Handling Instructions": 226,
|
| 519 |
+
"Standing Instructions": 227,
|
| 520 |
+
"Strictly Necessary Cookies": 228,
|
| 521 |
+
"Subscription Data": 229,
|
| 522 |
+
"Survey Responses": 230,
|
| 523 |
+
"Tax Identification Number": 231,
|
| 524 |
+
"Tax Records": 232,
|
| 525 |
+
"Terms Acceptance": 233,
|
| 526 |
+
"Third-party Account ID": 234,
|
| 527 |
+
"Time Spent Gaming": 235,
|
| 528 |
+
"Tracking Information": 236,
|
| 529 |
+
"Trading History": 237,
|
| 530 |
+
"Training Records": 238,
|
| 531 |
+
"Transaction Records": 239,
|
| 532 |
+
"UPI ID": 240,
|
| 533 |
+
"Underwriting Information": 241,
|
| 534 |
+
"Union Membership": 242,
|
| 535 |
+
"Usage Patterns": 243,
|
| 536 |
+
"User Agent": 244,
|
| 537 |
+
"Username / User ID": 245,
|
| 538 |
+
"Vehicle Ownership Details": 246,
|
| 539 |
+
"Vehicle Registration Number": 247,
|
| 540 |
+
"Vehicle Type": 248,
|
| 541 |
+
"Verification Metadata": 249,
|
| 542 |
+
"Verified Identity Data": 250,
|
| 543 |
+
"Viewing History": 251,
|
| 544 |
+
"Virtual Currency": 252,
|
| 545 |
+
"Virtual Items Owned": 253,
|
| 546 |
+
"Voter ID": 254,
|
| 547 |
+
"Watchlist": 255,
|
| 548 |
+
"WiFi Connections": 256,
|
| 549 |
+
"Wishlist Items": 257,
|
| 550 |
+
"Work Email": 258,
|
| 551 |
+
"Work Phone Number": 259
|
| 552 |
},
|
| 553 |
"type_loss_weight": 1.0,
|
| 554 |
"type_vocab_size": 2,
|
| 555 |
"vocab_size": 30522,
|
| 556 |
+
"gate_temperature": 1.0620299577713013,
|
| 557 |
"auto_map": {
|
| 558 |
"AutoConfig": "modeling_dual_head.DualHeadConfig",
|
| 559 |
"AutoModel": "modeling_dual_head.DualHeadBertForPIIClassification"
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a9f0231c63b82306042221284813282bce2d86682c89a1cc31353a34bbb11de1
|
| 3 |
+
size 91268520
|
modeling_dual_head.py
CHANGED
|
@@ -24,13 +24,19 @@ class DualHeadConfig(PretrainedConfig):
|
|
| 24 |
model_type = "dual_head_bert"
|
| 25 |
|
| 26 |
def __init__(self, num_type_labels=258, id2type_label=None, type_label2id=None,
|
| 27 |
-
pii_loss_weight=1.0, type_loss_weight=1.0, **kwargs):
|
| 28 |
super().__init__(**kwargs)
|
| 29 |
self.num_type_labels = num_type_labels
|
| 30 |
self.id2type_label = id2type_label or {}
|
| 31 |
self.type_label2id = type_label2id or {}
|
| 32 |
self.pii_loss_weight = pii_loss_weight
|
| 33 |
self.type_loss_weight = type_loss_weight
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
@dataclass
|
|
@@ -38,6 +44,7 @@ class DualHeadOutput(ModelOutput):
|
|
| 38 |
loss: Optional[torch.Tensor] = None
|
| 39 |
pii_logits: Optional[torch.Tensor] = None
|
| 40 |
type_logits: Optional[torch.Tensor] = None
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
class DualHeadBertForPIIClassification(PreTrainedModel):
|
|
@@ -68,16 +75,20 @@ class DualHeadBertForPIIClassification(PreTrainedModel):
|
|
| 68 |
def forward(self, input_ids, attention_mask=None, pii_labels=None, type_labels=None, **kwargs):
|
| 69 |
out = self.bert(input_ids=input_ids, attention_mask=attention_mask)
|
| 70 |
pooled = self.dropout(out.pooler_output)
|
| 71 |
-
|
|
|
|
| 72 |
type_logits = self.type_head(pooled)
|
| 73 |
|
| 74 |
loss = None
|
| 75 |
if pii_labels is not None:
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
if type_labels is not None and (type_labels != -100).any():
|
| 78 |
type_loss = F.cross_entropy(type_logits, type_labels, ignore_index=-100)
|
| 79 |
loss = loss + self.config.type_loss_weight * type_loss
|
| 80 |
-
return DualHeadOutput(loss=loss, pii_logits=pii_logits, type_logits=type_logits
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
def load_dual_head_model(name, type_labels, pii_loss_weight=1.0, type_loss_weight=1.0):
|
|
|
|
| 24 |
model_type = "dual_head_bert"
|
| 25 |
|
| 26 |
def __init__(self, num_type_labels=258, id2type_label=None, type_label2id=None,
|
| 27 |
+
pii_loss_weight=1.0, type_loss_weight=1.0, gate_temperature=1.0, **kwargs):
|
| 28 |
super().__init__(**kwargs)
|
| 29 |
self.num_type_labels = num_type_labels
|
| 30 |
self.id2type_label = id2type_label or {}
|
| 31 |
self.type_label2id = type_label2id or {}
|
| 32 |
self.pii_loss_weight = pii_loss_weight
|
| 33 |
self.type_loss_weight = type_loss_weight
|
| 34 |
+
# post-hoc temperature scaling (Guo et al. 2017) for the PII gate's confidence, fit by
|
| 35 |
+
# scripts/calibrate_gate.py *after* training on frozen logits -- never touched during
|
| 36 |
+
# training itself (fixed at 1.0 = no-op there). Dividing logits by T before softmax doesn't
|
| 37 |
+
# change argmax, so it recalibrates what "90% confident" means without changing any
|
| 38 |
+
# accuracy/precision/recall number anywhere else in this repo.
|
| 39 |
+
self.gate_temperature = gate_temperature
|
| 40 |
|
| 41 |
|
| 42 |
@dataclass
|
|
|
|
| 44 |
loss: Optional[torch.Tensor] = None
|
| 45 |
pii_logits: Optional[torch.Tensor] = None
|
| 46 |
type_logits: Optional[torch.Tensor] = None
|
| 47 |
+
pii_logits_raw: Optional[torch.Tensor] = None # pre-temperature-scaling, for calibration fitting
|
| 48 |
|
| 49 |
|
| 50 |
class DualHeadBertForPIIClassification(PreTrainedModel):
|
|
|
|
| 75 |
def forward(self, input_ids, attention_mask=None, pii_labels=None, type_labels=None, **kwargs):
|
| 76 |
out = self.bert(input_ids=input_ids, attention_mask=attention_mask)
|
| 77 |
pooled = self.dropout(out.pooler_output)
|
| 78 |
+
pii_logits_raw = self.pii_head(pooled)
|
| 79 |
+
pii_logits = pii_logits_raw / self.config.gate_temperature
|
| 80 |
type_logits = self.type_head(pooled)
|
| 81 |
|
| 82 |
loss = None
|
| 83 |
if pii_labels is not None:
|
| 84 |
+
# trains on the raw (unscaled) logits -- gate_temperature is a post-hoc, post-training
|
| 85 |
+
# fit and must never affect gradients
|
| 86 |
+
loss = self.config.pii_loss_weight * F.cross_entropy(pii_logits_raw, pii_labels)
|
| 87 |
if type_labels is not None and (type_labels != -100).any():
|
| 88 |
type_loss = F.cross_entropy(type_logits, type_labels, ignore_index=-100)
|
| 89 |
loss = loss + self.config.type_loss_weight * type_loss
|
| 90 |
+
return DualHeadOutput(loss=loss, pii_logits=pii_logits, type_logits=type_logits,
|
| 91 |
+
pii_logits_raw=pii_logits_raw)
|
| 92 |
|
| 93 |
|
| 94 |
def load_dual_head_model(name, type_labels, pii_loss_weight=1.0, type_loss_weight=1.0):
|