vadimbelsky commited on
Commit
79673b1
·
verified ·
1 Parent(s): edc22a0

scnsoft-pii-encoder-pruned-6l: int8 ONNX, tokenizer, config and model card (training seed 1234)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: proprietary-sciencesoft
4
+ license_link: https://huggingface.co/ScienceSoft/scnsoft-pii-encoder-pruned-6l/blob/main/README.md#licence
5
+ language: [en, de, fr, it, es, ru, ar]
6
+ pipeline_tag: token-classification
7
+ tags: [pii, ner, privacy, dlp, onnx, xlm-roberta, pruning, distillation]
8
+ library_name: onnxruntime
9
+ base_model: ScienceSoft/scnsoft-pii-encoder
10
+ base_model_relation: finetune
11
+ model-index:
12
+ - name: scnsoft-pii-encoder-pruned-6l
13
+ results:
14
+ - task:
15
+ type: token-classification
16
+ name: PII detection (format-less entities)
17
+ dataset:
18
+ type: ScienceSoft/piibench
19
+ name: PII Bench (piibench)
20
+ metrics:
21
+ - type: f1
22
+ value: 0.6887
23
+ name: F1, character-level, label-agnostic, averaged over 7 datasets (production engine, before post-filters)
24
+ - type: precision
25
+ value: 0.5730
26
+ name: Precision
27
+ - type: recall
28
+ value: 0.9064
29
+ name: Recall
30
+ ---
31
+
32
+ # ScienceSoft PII encoder — pruned to 6 layers
33
+
34
+ [`ScienceSoft/scnsoft-pii-encoder`](https://huggingface.co/ScienceSoft/scnsoft-pii-encoder)
35
+ with its top six transformer layers removed and the remaining six retrained. The full model is
36
+ used as teacher. It detects personal data **without a fixed format** (names of people and
37
+ organisations, locations, addresses and dates) in seven languages, and it runs **1.8× faster**
38
+ than the full model on CPU.
39
+
40
+ **It is less accurate than the full model.** Its recall matches the full model's, but its
41
+ precision does not: on real text it marks more words that are not personal data. Before training,
42
+ a bar was set for releasing a faster model:
43
+
44
+ - average PII Bench F1 of at least 0.72;
45
+ - no language more than 0.08 below the full model;
46
+ - at least 2× the full model's speed.
47
+
48
+ **This model meets none of the three.** It reaches 0.689 average F1 and 1.8× the speed. It is
49
+ published with those results stated, so the trade between speed and accuracy can be judged on the
50
+ numbers.
51
+
52
+ Architecture: `xlm-roberta-base` with 6 layers (the full model's layers 0–5), 768 wide, same
53
+ tokenizer, labels and classifier head as the full model. Exported to ONNX and quantised to int8;
54
+ the file is **235 MB** (most of it the 250,002-token embedding table), and inference runs on CPU.
55
+
56
+ ## Labels
57
+
58
+ `PERSON` `ORGANIZATION` `LOCATION` `ADDRESS` `DATE_TIME` (BIO tagging, 11 classes), the same set
59
+ and order as the full model. Identifiers with a fixed format (email addresses, telephone,
60
+ payment-card, IBAN and passport numbers) are not labels. See *touch rate* below for how often this
61
+ model marks them anyway.
62
+
63
+ ## Speed
64
+
65
+ Measured on 300 PII Bench rows:
66
+
67
+ - int8 ONNX Runtime 1.19.2 on CPU, batch size 1;
68
+ - all three models interleaved row by row;
69
+ - an Apple M4 Max with 16 cores, a shared workstation with a 1-minute load average of 18–19.
70
+
71
+ Absolute milliseconds depend on the host; the ratio is the informative part.
72
+
73
+ | model | layers × width | int8 size | median ms per row | 95th percentile | speed-up |
74
+ |---|---|---|---|---|---|
75
+ | `scnsoft-pii-encoder` | 12 × 768 | 278 MB | 22.2 | 36.0 | 1.0× |
76
+ | **this model** | 6 × 768 | 235 MB | **12.2** | **20.7** | **1.8×** |
77
+ | [`scnsoft-pii-encoder-small`](https://huggingface.co/ScienceSoft/scnsoft-pii-encoder-small) | 6 × 384 | 107 MB | 5.7 | 8.5 | 3.9× |
78
+
79
+ Halving the depth roughly halves the compute per token. The width stays at 768, which is why the
80
+ 6 × 384 model is faster still.
81
+
82
+ ## Evaluation on PII Bench
83
+
84
+ [PII Bench](https://huggingface.co/datasets/ScienceSoft/piibench) (piibench) scores detection
85
+ of the five entity types above in text serialised the way outbound traffic carries it (JSON,
86
+ XML, SQL, CSV, key=value, log lines, Markdown tables, OCR output) as well as prose.
87
+
88
+ - It comprises 3,500 rows, 500 from each of seven third-party datasets.
89
+ - Precision, recall and F1 are computed over characters and are label-agnostic.
90
+ - Scores are micro-averaged within each dataset and then averaged across the seven.
91
+ - Leaderboard: [ScienceSoft/piibench-leaderboard](https://huggingface.co/spaces/ScienceSoft/piibench-leaderboard).
92
+
93
+ **How these numbers were produced.** All models below are scored the same way: by the production
94
+ Rust inference engine, before its post-filters. That is the same path as the leaderboard's
95
+ `scnsoft-pii-encoder-engine-raw` row, which this scoring reproduces exactly (0.7725). The
96
+ intervals are 95 % percentile bootstrap intervals over rows, resampled within each dataset
97
+ (1,000 resamples).
98
+
99
+ **Conflict of interest.** PII Bench is built and published by ScienceSoft, the developer of
100
+ this model. Four of its seven datasets (TAB, FactRuEval, MEDDOCAN, IAHLT) informed changes to the
101
+ training corpus this model shares with the full model.
102
+
103
+ | | this model | `scnsoft-pii-encoder` | bar set before training |
104
+ |---|---|---|---|
105
+ | F1 | **0.689** [0.681, 0.697] | 0.773 [0.765, 0.780] | ≥ 0.72 |
106
+ | precision | 0.573 | 0.685 | |
107
+ | recall | 0.906 | 0.908 | |
108
+ | touch rate (lower is better) | 0.160 | 0.020 | |
109
+
110
+ | language | this model | `scnsoft-pii-encoder` | bar (full model − 0.08) | |
111
+ |---|---|---|---|---|
112
+ | ar | 0.6012 | 0.6812 | 0.6012 | at the bar |
113
+ | de | 0.5378 | 0.6573 | 0.5773 | below |
114
+ | en | 0.7317 | 0.8040 | 0.7240 | above |
115
+ | es | 0.7736 | 0.8437 | 0.7637 | above |
116
+ | ru | 0.6776 | 0.7543 | 0.6743 | above |
117
+
118
+ **Where the accuracy is lost.**
119
+
120
+ - Recall is the full model's (0.906 against 0.908). The loss is in **precision** (0.573 against
121
+ 0.685), across every dataset (−0.05 to −0.12 F1) and every free-text format.
122
+ - On an in-distribution synthetic evaluation, drawn from the training generator, the model scores
123
+ F1 0.982, close to the full model's 0.993. It fires too often on real text, which its training
124
+ data never showed it.
125
+ - **Touch rate**, the share of characters belonging to format-fixed identifiers that a model marks
126
+ anyway, is 0.160 here, against 0.020 for the full model.
127
+
128
+ ### Variability across training seeds
129
+
130
+ Two training runs of the same recipe, differing only in the random seed:
131
+
132
+ | training seed | F1 | 95 % CI | precision | recall |
133
+ |---|---|---|---|---|
134
+ | 1234 — **this model** (`main`) | 0.6887 | [0.6809, 0.6966] | 0.573 | 0.906 |
135
+ | 4321 (branch `seed-4321`) | 0.6870 | [0.6792, 0.6952] | 0.580 | 0.890 |
136
+
137
+ Seed 1234 is published on `main` by convention, not selected by score.
138
+
139
+ ## Training
140
+
141
+ - **Initialisation:** the full model's embeddings, transformer layers 0–5 and classifier head.
142
+ Keeping the lower layers follows the finding that dropping the top layers of a pretrained
143
+ transformer holds up best after retraining (Sajjad et al., 2020, *On the Effect of Dropping
144
+ Layers of Pre-trained Transformer Models*).
145
+ - **Corpus:** the same synthetic corpus as `scnsoft-pii-encoder` (v23), rebuilt from that run's
146
+ own generator snapshot and configuration and verified by count: 155,141 training and 5,300
147
+ evaluation rows.
148
+ - **Distillation from `scnsoft-pii-encoder`:** 0.5 × cross-entropy on the gold labels plus
149
+ 0.5 × T² × KL(teacher ‖ student) at T = 2, over non-padding tokens.
150
+ - **Schedule:** two epochs, 31 minutes on one GPU.
151
+ - **Stack:** `transformers==4.57.1`, `tokenizers==0.22.1`, `torch==2.9.0a0`, `faker==37.12.0`.
152
+ - **int8 against fp32:** +0.0036 F1 on the synthetic evaluation, 95 % CI [+0.0020, +0.0052]. The
153
+ int8 file scored slightly higher here.
154
+
155
+ ## Limitations
156
+
157
+ - **Below the release bar** on average F1, on German, and on speed (see above). Where accuracy
158
+ matters, use [`scnsoft-pii-encoder`](https://huggingface.co/ScienceSoft/scnsoft-pii-encoder).
159
+ Where speed matters most, [`scnsoft-pii-encoder-small`](https://huggingface.co/ScienceSoft/scnsoft-pii-encoder-small)
160
+ is 2× faster again, at lower accuracy.
161
+ - **Lower precision on real text** than the full model, and more format-fixed identifiers marked.
162
+ - **Trained only on synthetic data**, like the full model. Its other limitations apply too: Arabic
163
+ is the weakest language; Arabizi is a reconstruction; `DATE_TIME` is kept by the product only
164
+ next to a birth-date cue.
165
+
166
+ ## Use
167
+
168
+ Required files: `config.json`, `tokenizer.json`, `onnx/model_quantized.onnx`.
169
+
170
+ ```python
171
+ import json, onnxruntime as ort
172
+ from transformers import AutoTokenizer
173
+
174
+ tok = AutoTokenizer.from_pretrained("ScienceSoft/scnsoft-pii-encoder-pruned-6l")
175
+ cfg = json.load(open("config.json"))
176
+ id2label = {int(k): v for k, v in cfg["id2label"].items()}
177
+ sess = ort.InferenceSession("onnx/model_quantized.onnx",
178
+ providers=["CPUExecutionProvider"])
179
+
180
+ enc = tok(text, return_offsets_mapping=True, return_tensors="np",
181
+ truncation=True, max_length=256)
182
+ offsets = enc.pop("offset_mapping")[0]
183
+ logits = sess.run(None, {i.name: enc[i.name] for i in sess.get_inputs()})[0]
184
+ # argmax -> id2label -> merge BIO spans using `offsets` for character positions
185
+ ```
186
+
187
+ Encode with the special tokens `<s>` and `</s>`, as the model was trained;
188
+ `AutoTokenizer.__call__` adds them by default.
189
+
190
+ ## Provenance
191
+
192
+ The training corpus is synthetic text produced by ScienceSoft's own generator; no production
193
+ traffic and no scraped text is used for training. Entity values come from project-written lists
194
+ and from Faker (person, company and city names), libpostal (address vocabulary) and GeoNames
195
+ (Arabic-script city names).
196
+
197
+ ## Licence
198
+
199
+ Proprietary to ScienceSoft. The weights are published so that the results on this page can be
200
+ evaluated and reproduced; no licence to use them in production, to modify them or to redistribute
201
+ them is granted. For licensing, contact ScienceSoft (https://www.scnsoft.com).
202
+
203
+ **Basis for these terms.**
204
+
205
+ - **Derived from** ScienceSoft's own `scnsoft-pii-encoder`, which is derived from
206
+ [`FacebookAI/xlm-roberta-base`](https://huggingface.co/FacebookAI/xlm-roberta-base) (MIT licence).
207
+ - **Training corpus** includes entity values from Faker (MIT), libpostal (MIT) and GeoNames
208
+ (CC BY 4.0).
209
+
210
+ All of these licences permit a derivative work to be distributed under proprietary terms,
211
+ provided their notices are retained and GeoNames is attributed. None is share-alike, and none
212
+ restricts commercial use. The notices and the attribution are in
213
+ [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
THIRD_PARTY_NOTICES.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Third-party notices
2
+
3
+ This model is proprietary to ScienceSoft. It is derived from, or was trained with material
4
+ drawn from, the third-party works below. Each is used under its own licence, all of which
5
+ permit distribution of derivative works under different terms provided the notices below are
6
+ retained and the attributions given. None is share-alike and none restricts commercial use.
7
+
8
+ ## Base model — XLM-RoBERTa
9
+
10
+ `FacebookAI/xlm-roberta-base` (https://huggingface.co/FacebookAI/xlm-roberta-base), including
11
+ its tokenizer. Licensed under the MIT License:
12
+
13
+ ```
14
+ MIT License
15
+
16
+ Copyright (c) Facebook, Inc. and its affiliates.
17
+
18
+ Permission is hereby granted, free of charge, to any person obtaining a copy
19
+ of this software and associated documentation files (the "Software"), to deal
20
+ in the Software without restriction, including without limitation the rights
21
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ copies of the Software, and to permit persons to whom the Software is
23
+ furnished to do so, subject to the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be included in all
26
+ copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
+ SOFTWARE.
35
+ ```
36
+
37
+ ## Training-data sources
38
+
39
+ The training corpus is synthetic text produced by ScienceSoft's own generator. Entity values
40
+ inserted into that text were drawn in part from the following sources.
41
+
42
+ **Faker** (https://github.com/joke2k/faker), version 37.12.0 — person, company and city name
43
+ pools. MIT License, Copyright (c) 2012 Daniele Faraglia; the MIT permission notice above
44
+ applies with that copyright line.
45
+
46
+ **libpostal** (https://github.com/openvenues/libpostal), `resources/dictionaries/` — address
47
+ sub-building vocabulary. MIT License, Copyright (c) 2015 openvenues; the MIT permission notice
48
+ above applies with that copyright line.
49
+
50
+ **GeoNames** (https://www.geonames.org/) — Arabic-script city names from the per-country
51
+ exports (https://download.geonames.org/export/dump/). Licensed under Creative Commons
52
+ Attribution 4.0 International (https://creativecommons.org/licenses/by/4.0/). Changes made:
53
+ names were filtered to populated places of at least 5,000 inhabitants and to Arabic-script
54
+ text, then inserted as entity values into generated training sentences; no GeoNames record is
55
+ reproduced in this model repository.
config.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "XLMRobertaForTokenClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "dtype": "float32",
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "id2label": {
14
+ "0": "O",
15
+ "1": "B-PERSON",
16
+ "2": "I-PERSON",
17
+ "3": "B-ORGANIZATION",
18
+ "4": "I-ORGANIZATION",
19
+ "5": "B-LOCATION",
20
+ "6": "I-LOCATION",
21
+ "7": "B-ADDRESS",
22
+ "8": "I-ADDRESS",
23
+ "9": "B-DATE_TIME",
24
+ "10": "I-DATE_TIME"
25
+ },
26
+ "initializer_range": 0.02,
27
+ "intermediate_size": 3072,
28
+ "label2id": {
29
+ "B-ADDRESS": 7,
30
+ "B-DATE_TIME": 9,
31
+ "B-LOCATION": 5,
32
+ "B-ORGANIZATION": 3,
33
+ "B-PERSON": 1,
34
+ "I-ADDRESS": 8,
35
+ "I-DATE_TIME": 10,
36
+ "I-LOCATION": 6,
37
+ "I-ORGANIZATION": 4,
38
+ "I-PERSON": 2,
39
+ "O": 0
40
+ },
41
+ "layer_norm_eps": 1e-05,
42
+ "max_position_embeddings": 514,
43
+ "model_type": "xlm-roberta",
44
+ "num_attention_heads": 12,
45
+ "num_hidden_layers": 6,
46
+ "output_past": true,
47
+ "pad_token_id": 1,
48
+ "position_embedding_type": "absolute",
49
+ "transformers_version": "4.57.1",
50
+ "type_vocab_size": 1,
51
+ "use_cache": true,
52
+ "vocab_size": 250002
53
+ }
onnx/model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20883bcc40b21b7c30287bd000b18b4a62bd585becdfa2aade38f7f1bb9234c3
3
+ size 235332276
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a514807cffabd8abaf028cfaffe7ff0c4f60b97ea2db80c41f14172ae6b018ca
3
+ size 17082987
tokenizer_config.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
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": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "250001": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<s>",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "<s>",
47
+ "eos_token": "</s>",
48
+ "extra_special_tokens": {},
49
+ "mask_token": "<mask>",
50
+ "max_length": 256,
51
+ "model_max_length": 512,
52
+ "pad_to_multiple_of": null,
53
+ "pad_token": "<pad>",
54
+ "pad_token_type_id": 0,
55
+ "padding_side": "right",
56
+ "sep_token": "</s>",
57
+ "stride": 0,
58
+ "tokenizer_class": "XLMRobertaTokenizer",
59
+ "truncation_side": "right",
60
+ "truncation_strategy": "longest_first",
61
+ "unk_token": "<unk>"
62
+ }