LukasKunhardt commited on
Commit
2e538e6
·
verified ·
1 Parent(s): 2b52b50

v1.0.3: Neue ONNX-Dateien für transformers.js: model.onnx und ein int8-File mi

Browse files
README.md CHANGED
@@ -4,108 +4,123 @@ language: [en, de, fr, es, it, nl, pt, sv, da, "no", fi, pl, cs, ro, tr, ru, ar,
4
  library_name: transformers
5
  pipeline_tag: token-classification
6
  base_model: jhu-clsp/mmBERT-small
7
- tags: [pii, privacy, token-classification, de-identification, redaction, distillation, onnx]
 
 
 
 
8
  ---
9
 
10
  # pii-filter-small
11
 
12
  A small multilingual model that finds personal information in text. It uses exactly the 33 labels of [openai/privacy-filter](https://huggingface.co/openai/privacy-filter), so code that runs privacy-filter through `transformers` works with this one, at 141 million instead of 1.4 billion parameters.
13
 
14
- On four public test sets it reaches about the same character F1 as privacy-filter with its official decoder (0.809 against 0.811), with less exact span boundaries (span F1 0.538 against 0.601). On a CPU the int8 file is about ten times faster than privacy-filter run through `transformers` (121 against 1,281 ms per 1,000 characters).
15
 
16
- I trained it by distillation from openai/privacy-filter. It is not from OpenAI and not affiliated with OpenAI.
17
 
18
  ## Quick start
19
 
20
  ```python
21
  from transformers import pipeline
22
 
23
- ner = pipeline("token-classification", model="LukasKunhardt/pii-filter-small")
24
- text = "Hi, I'm Maria Keller, born 12 May 1984. Call me at +49 151 2345 6789 or write to maria.keller@example.org."
25
- spans = []
26
- for t in ner(text): # one entry per token, with the BIOES labels of openai/privacy-filter
27
- tag, cat = t["entity"].split("-", 1)
28
- last = spans[-1] if spans else None
29
- if tag in "BS" or not last or last["label"] != cat or last["index"] != t["index"] - 1 or last["done"]:
30
- spans.append(last := {"label": cat, "start": t["start"]})
31
- last.update(end=t["end"], index=t["index"], done=tag in "ES")
32
- print([(s["label"], text[s["start"]:s["end"]].strip()) for s in spans])
33
  ```
34
 
35
  ```
36
- [('private_person', 'Maria Keller'), ('private_date', '12 May 1984'), ('private_phone', '+49 151 2345 6789'), ('private_email', 'maria.keller@example.org')]
 
 
 
 
 
37
  ```
38
 
39
- The loop joins BIOES tokens into spans; `aggregation_strategy="simple"` does not know E- and S- labels and splits spans. For texts over 500 tokens, use `read()` from the [code](code/) in this repository (also on [GitHub](https://github.com/lukaskunhardt/pii-filter-small)), which reads in windows of 512 tokens as in training and testing. It also runs `onnx/model_int8.onnx` with ONNX Runtime.
40
 
41
- ## What it finds
42
 
43
- Eight categories, each with B-, I-, E- and S- labels, plus O: `account_number` (bank, card, ID, passport and tax numbers), `private_address`, `private_date`, `private_email`, `private_person` (names and user names), `private_phone`, `private_url` (also IP addresses) and `secret` (passwords, PINs, API keys).
 
44
 
45
- ## Results
 
 
46
 
47
- Test data: fixed random samples of ai4privacy/pii-masking-300k validation (1,200 documents, 6 languages), nvidia/Nemotron-PII test (1,000, English), DataikuNLP/kiji-pii-training-data test (900, 6 languages) and gretelai/synthetic_pii_finance_multilingual test (1,050, 7 languages). Character F1 asks for every character whether it is personal, regardless of category. Span F1 needs start, end and category to match.
 
 
 
 
48
 
49
- Character F1:
50
 
51
- | Model | ai4privacy | Nemotron | Kiji | Gretel | Mean |
52
- |---|---|---|---|---|---|
53
- | pii-filter-small (seed 43, these weights) | 0.929 | 0.817 | 0.830 | **0.661** | 0.809 |
54
- | pii-filter-small, mean of 3 seeds | 0.931 | 0.813 | **0.833** | 0.660 | 0.809 |
55
- | pii-filter-small, int8 ONNX file | 0.915 | 0.791 | 0.815 | 0.645 | 0.791 |
56
- | privacy-filter, official `opf` decoder | **0.952** | **0.823** | 0.832 | 0.637 | **0.811** |
57
- | privacy-filter through `transformers` (argmax) | 0.868 | 0.696 | 0.737 | 0.606 | 0.726 |
58
 
59
- Span F1:
60
 
61
- | Model | ai4privacy | Nemotron | Kiji | Gretel | Mean |
62
- |---|---|---|---|---|---|
63
- | pii-filter-small (seed 43) | 0.735 | 0.613 | 0.374 | 0.429 | 0.538 |
64
- | pii-filter-small, int8 ONNX file | 0.686 | 0.583 | 0.352 | 0.388 | 0.502 |
65
- | privacy-filter, official `opf` decoder | **0.883** | **0.661** | **0.397** | **0.465** | **0.601** |
66
- | privacy-filter through `transformers` (argmax) | 0.735 | 0.471 | 0.327 | 0.353 | 0.471 |
67
 
68
  ![Mean character F1 against model size](pareto_size.png)
69
 
70
- The chart shows mean character F1 against parameters; [pareto_speed.png](pareto_speed.png) shows it against CPU time.
71
 
72
- I read my model with the argmax label per token. privacy-filter loses a lot when read that way, so I also ran it through its own package `opf` (Viterbi decoder, default settings) and compare against that row. My model is not better than privacy-filter: it wins on Gretel, loses on ai4privacy, and its span boundaries are worse on every set.
73
 
74
- Speed on the same 50 Nemotron documents with 3 CPU threads: int8 file 121 ms per 1,000 characters, PyTorch weights 225 ms, privacy-filter through `opf` 16,894 ms. Tables per language, all seeds and development numbers are in [RESULTS.md](RESULTS.md).
75
 
76
- ## How I tested
 
 
 
 
 
 
 
77
 
78
- The test samples, the label mapping and a gate were fixed in writing before training (`rules/`). The gate had four points. Quality and speed passed. One condition failed: the int8 file was allowed to lose at most 0.01 mean character F1 against the PyTorch weights, and it lost 0.018. So the safetensors weights are the main file and the int8 file is an optional extra. I published under a decision rule I wrote before seeing the `opf` result; it is also in `rules/`.
79
 
80
- I opened the test samples once for my models, after choosing seed and checkpoint on my own development texts. privacy-filter was measured twice: through `transformers` before training, and through `opf` afterwards.
81
 
82
- I mapped each test set's labels to the eight categories (ai4privacy as in OpenAI's model card, the others in the same way; `rules/abbildung.json`). Gold labels without a match (7,345 of 29,203 labelled spans) are ignored: they are not gold, and a prediction on them alone is not an error.
83
 
84
  ## Limits
85
 
86
- - Not tested on clinical notes, on languages outside the eight test languages, or on real data. All four test sets are synthetic.
87
- - In my own tries, long numbers with spaces, such as IBANs, were sometimes split into pieces of different categories.
88
- - Both models score lowest on Gretel (financial documents), below 0.67 character F1.
89
  - This is not a medical device. Removing identifiers is not anonymisation under the GDPR: the remaining text can still identify a person.
90
 
91
  ## Training data
92
 
93
- 1. DeepSeek V4.1 Flash (open weights, MIT) wrote 24,000 documents in 22 languages, such as e-mails, tickets, invoices and chat messages, with invented people and values. About 15 % were asked for no private information, only companies and public facts.
94
- 2. I dropped 124 texts that shared a 10-word sequence with a test document; 23,876 remained.
95
- 3. openai/privacy-filter labelled every text: spans and per-character category probabilities. I ran it through `transformers` with argmax, the weaker of the two readings above, because I found the gap to `opf` only after training.
96
- 4. 1,150 texts (5 %) became my development set. No test data went into training.
97
 
98
  ## Training
99
 
100
  - Base model: jhu-clsp/mmBERT-small (MIT).
101
- - Loss: cross-entropy on the teacher's spans as BIOES labels, plus KL divergence to the teacher's category probabilities.
102
  - 3 epochs, learning rate 5e-5, batch 16, windows of 512 tokens, about 21 minutes per seed on one NVIDIA A10G.
103
- - Seeds 42, 43 and 44. I shipped seed 43, which had the best development character F1 (0.904).
104
- - The generated texts cost about 3 US dollars.
105
 
106
  ## Licenses
107
 
108
- The model is MIT. mmBERT-small is MIT, openai/privacy-filter is Apache 2.0, DeepSeek V4.1 Flash is MIT. Test sets: ai4privacy/pii-masking-300k has its own licence for academic use, which is why I used it only for testing; Nemotron-PII is CC BY 4.0; Gretel and Kiji are Apache 2.0.
 
 
 
 
109
 
110
  ## Citation
111
 
 
4
  library_name: transformers
5
  pipeline_tag: token-classification
6
  base_model: jhu-clsp/mmBERT-small
7
+ datasets: [nvidia/Nemotron-PII, gretelai/synthetic_pii_finance_multilingual, DataikuNLP/kiji-pii-training-data, ai4privacy/pii-masking-300k, piimb/pii-masking-benchmark]
8
+ tags: [pii, privacy, privacy-filter, token-classification, de-identification, redaction, distillation, onnx, transformers.js]
9
+ widget:
10
+ - text: "Hi, I am Anna Müller. Mail anna.mueller@posteo.de or call +49 30 1234567."
11
+ - text: "Rückfragen bitte an Jonas Feldmann, Tel. 0221 478 3310."
12
  ---
13
 
14
  # pii-filter-small
15
 
16
  A small multilingual model that finds personal information in text. It uses exactly the 33 labels of [openai/privacy-filter](https://huggingface.co/openai/privacy-filter), so code that runs privacy-filter through `transformers` works with this one, at 141 million instead of 1.4 billion parameters.
17
 
18
+ On four public test sets it reaches about the same character F1 as privacy-filter with its official decoder (0.809 against 0.811), with less exact span boundaries (span F1 0.538 against 0.601). On a CPU the 268 MB int8 file is about six times faster than privacy-filter through `transformers` (202 against 1,281 ms per 1,000 characters, measured in separate runs).
19
 
20
+ I distilled it from openai/privacy-filter. It is not from or affiliated with OpenAI.
21
 
22
  ## Quick start
23
 
24
  ```python
25
  from transformers import pipeline
26
 
27
+ ner = pipeline("token-classification", model="LukasKunhardt/pii-filter-small", aggregation_strategy="simple")
28
+ text = "Hi, I'm Anna Müller. Call me at +49 151 2345 6789 or write to anna.mueller@example.org."
29
+ for e in ner(text):
30
+ print(e["entity_group"], repr(e["word"]), e["start"], e["end"])
 
 
 
 
 
 
31
  ```
32
 
33
  ```
34
+ private_person ' Anna' 7 12
35
+ private_person ' Müller' 12 19
36
+ private_phone ' +49 151 2345 678' 31 48
37
+ private_phone '9' 48 49
38
+ private_email ' anna.mueller@example.' 61 83
39
+ private_email 'org' 83 86
40
  ```
41
 
42
+ The labels are BIOES; `aggregation_strategy="simple"` does not know E- and S-, so it splits an entity of several tokens before its last token, and a part can start with a space. `read()` in the [code](code/) ([GitHub](https://github.com/lukaskunhardt/pii-filter-small)) joins the parts, trims spaces and reads texts over 500 tokens in 512-token windows, as in training and testing.
43
 
44
+ With [transformers.js](https://huggingface.co/docs/transformers.js):
45
 
46
+ ```js
47
+ import { pipeline } from "@huggingface/transformers";
48
 
49
+ const ner = await pipeline("token-classification", "LukasKunhardt/pii-filter-small", { dtype: "q8" });
50
+ console.log(await ner("Hi, I am Anna Müller. Mail anna.mueller@posteo.de or call +49 30 1234567."));
51
+ ```
52
 
53
+ It returns one entry per token. `dtype: "q8"` loads `onnx/model_quantized.onnx`; in my Node test it matched fp32.
54
+
55
+ `onnx/model.onnx` (563 MB) is the fp32 export. In `onnx/model_quantized.onnx` (268 MB) only the embedding table is 8-bit. On 242 development texts they keep the PyTorch label for 100 % and 99.93 % of tokens (`onnx/quantization_check.json`).
56
+
57
+ ## What it finds
58
 
59
+ Eight categories with B-, I-, E- and S- labels, plus O: `account_number` (bank, card, ID, passport and tax numbers), `private_address`, `private_date`, `private_email`, `private_person` (also user names), `private_phone`, `private_url` (also IP addresses) and `secret` (passwords, API keys).
60
 
61
+ ## Results
 
 
 
 
 
 
62
 
63
+ Test data: fixed random samples of four public sets, 4,150 documents in 8 languages: ai4privacy/pii-masking-300k validation, and the test splits of Nemotron-PII, Kiji and Gretel finance. Character F1 (set columns) asks for every character whether it is personal, regardless of category. Span F1 needs start, end and category to match.
64
 
65
+ | Model | ai4privacy | Nemotron | Kiji | Gretel | Mean char F1 | Mean span F1 |
66
+ |---|---|---|---|---|---|---|
67
+ | pii-filter-small, PyTorch (seed 43) | 0.929 | 0.817 | 0.830 | **0.661** | 0.809 | 0.538 |
68
+ | pii-filter-small, `onnx/model_quantized.onnx` | 0.924 | **0.823** | **0.844** | 0.649 | 0.810 | 0.530 |
69
+ | privacy-filter, official `opf` decoder | **0.952** | **0.823** | 0.832 | 0.637 | **0.811** | **0.601** |
70
+ | privacy-filter through `transformers` (argmax) | 0.868 | 0.696 | 0.737 | 0.606 | 0.726 | 0.471 |
71
 
72
  ![Mean character F1 against model size](pareto_size.png)
73
 
74
+ privacy-filter loses a lot when read by argmax per token, as I read my model, so I compare with its own package `opf` (Viterbi decoder). My model is not better than privacy-filter: it wins on Gretel, loses on ai4privacy, and its span boundaries are worse on every set.
75
 
76
+ CPU time on 50 Nemotron documents with 3 threads, in ms per 1,000 characters: int8 202, `onnx/model.onnx` 231, PyTorch 225, privacy-filter through `transformers` 1,281 and through `opf` 16,894 (ONNX times from a later run; [chart](pareto_speed.png)). [RESULTS.md](RESULTS.md) has all tables.
77
 
78
+ ## PII Masking Benchmark
79
 
80
+ I ran the official evaluation of [PIIMB](https://huggingface.co/spaces/piimb/pii-masking-benchmark-leaderboard) with default settings: character masking regardless of category, mean F2 over six tasks. F2 per task: ai4privacy-en 0.901, ai4privacy-multi 0.845, gretel 0.898, mapa-eur-lex 0.290, nemotron-pii 0.616, privy 0.495. Among the 37 entries in its public results my model would rank 23rd; my leaderboard submission is pending.
81
+
82
+ | Model | Parameters | Mean F2 |
83
+ |---|---|---|
84
+ | OpenMed/privacy-filter-multilingual-v2 (best entry) | 1.4 B | **0.836** |
85
+ | OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1 (best of similar size) | 141 M | 0.816 |
86
+ | pii-filter-small | 141 M | 0.674 |
87
+ | openai/privacy-filter | 1.4 B | 0.662 |
88
 
89
+ ## How I tested
90
 
91
+ Test samples, label mapping and a gate were fixed in writing before training (`rules/`). In v1.0 one gate condition failed: the int8 file lost 0.018 mean character F1 against PyTorch, more than the allowed 0.01. This version's int8 file loses nothing there (0.810 against 0.809) and 0.008 mean span F1. I chose it on development texts by a rule written beforehand and measured it once on the test samples.
92
 
93
+ I opened the test samples once for my models, after choosing seed and checkpoint on development texts. privacy-filter was measured twice: through `transformers` before training, through `opf` afterwards. Gold spans without a match in my mapping are ignored (7,345 of 29,203).
94
 
95
  ## Limits
96
 
97
+ - Per-language tests cover nine languages, all on synthetic data. Real data and the other training languages, such as Arabic, Japanese and Chinese, are untested.
98
+ - On clinical notes it left personal information in most documents ([RESULTS.md](RESULTS.md)).
99
+ - In my tries, long numbers with spaces, such as IBANs, were sometimes split into parts of different categories.
100
  - This is not a medical device. Removing identifiers is not anonymisation under the GDPR: the remaining text can still identify a person.
101
 
102
  ## Training data
103
 
104
+ 1. DeepSeek V4.1 Flash (open weights, MIT) wrote 24,000 documents in 22 languages, such as e-mails, invoices and chats, with invented people and values. About 15 % were asked to contain no personal information.
105
+ 2. I dropped 124 texts that shared a 10-word sequence with a test document, leaving 23,876.
106
+ 3. openai/privacy-filter labelled every text (spans and per-character category probabilities), read through `transformers` with argmax; I found the gap to `opf` only after training.
107
+ 4. 1,150 texts (5 %) became my development set.
108
 
109
  ## Training
110
 
111
  - Base model: jhu-clsp/mmBERT-small (MIT).
112
+ - Loss: cross-entropy on the teacher's BIOES spans plus KL divergence to its category probabilities.
113
  - 3 epochs, learning rate 5e-5, batch 16, windows of 512 tokens, about 21 minutes per seed on one NVIDIA A10G.
114
+ - Seeds 42, 43 and 44 (test mean 0.809 character F1); I shipped seed 43, best on development character F1 (0.904).
115
+ - The texts cost about 3 US dollars.
116
 
117
  ## Licenses
118
 
119
+ The model is MIT, like mmBERT-small and DeepSeek V4.1 Flash; openai/privacy-filter is Apache 2.0. Nemotron-PII is CC BY 4.0, Gretel and Kiji are Apache 2.0. ai4privacy/pii-masking-300k (academic licence) and PIIMB (CC BY-NC 4.0) I used only for testing.
120
+
121
+ ## Versions
122
+
123
+ - v1.0.3: new files `onnx/model.onnx` and `onnx/model_quantized.onnx` (mean character F1 0.810); `onnx/model_int8.onnx` (0.791) removed.
124
 
125
  ## Citation
126
 
RESULTS.md CHANGED
@@ -11,7 +11,8 @@ Character F1 (binary: personal or not):
11
  |---|---|---|---|---|---|
12
  | pii-filter-small (seed 43, shipped) | 0.929 | 0.817 | 0.830 | 0.661 | 0.809 |
13
  | mean of 3 seeds | 0.931 | 0.813 | 0.833 | 0.660 | 0.809 |
14
- | pii-filter-small int8 file | 0.915 | 0.791 | 0.815 | 0.645 | 0.791 |
 
15
  | privacy-filter, official opf decoder | 0.952 | 0.823 | 0.832 | 0.637 | 0.811 |
16
  | privacy-filter through transformers (argmax) | 0.868 | 0.696 | 0.737 | 0.606 | 0.726 |
17
  | privacy-filter, opf argmax | 0.952 | 0.823 | 0.834 | 0.634 | 0.811 |
@@ -24,7 +25,8 @@ Span F1 (typed, exact boundaries):
24
  |---|---|---|---|---|---|
25
  | pii-filter-small (seed 43, shipped) | 0.735 | 0.613 | 0.374 | 0.429 | 0.538 |
26
  | mean of 3 seeds | 0.731 | 0.612 | 0.375 | 0.433 | 0.538 |
27
- | pii-filter-small int8 file | 0.686 | 0.583 | 0.352 | 0.388 | 0.502 |
 
28
  | privacy-filter, official opf decoder | 0.883 | 0.661 | 0.397 | 0.465 | 0.601 |
29
  | privacy-filter through transformers (argmax) | 0.735 | 0.471 | 0.327 | 0.353 | 0.471 |
30
  | privacy-filter, opf argmax | 0.873 | 0.638 | 0.393 | 0.399 | 0.576 |
@@ -32,43 +34,46 @@ Span F1 (typed, exact boundaries):
32
  | seed 44 | 0.734 | 0.608 | 0.374 | 0.438 | 0.538 |
33
 
34
  "privacy-filter, opf argmax" is the `opf` package with its argmax decoder instead of Viterbi. Seed 43 is the released model.
 
35
 
36
  ## Test per language
37
 
38
- Character F1 / span F1. Columns: my model (seed 43), my int8 file, privacy-filter with `opf` Viterbi, privacy-filter through `transformers`.
39
  Gretel names French "France" in its data.
40
 
41
- | Set / language | Documents | pii-filter-small | int8 | privacy-filter (opf) | privacy-filter (transformers) |
42
- |---|---|---|---|---|---|
43
- | ai4privacy/Dutch | 200 | 0.906 / 0.686 | 0.891 / 0.647 | 0.933 / 0.841 | 0.871 / 0.724 |
44
- | ai4privacy/English | 200 | 0.934 / 0.736 | 0.917 / 0.706 | 0.961 / 0.897 | 0.783 / 0.614 |
45
- | ai4privacy/French | 200 | 0.940 / 0.745 | 0.925 / 0.677 | 0.963 / 0.897 | 0.872 / 0.748 |
46
- | ai4privacy/German | 200 | 0.940 / 0.745 | 0.924 / 0.682 | 0.958 / 0.886 | 0.900 / 0.788 |
47
- | ai4privacy/Italian | 200 | 0.920 / 0.720 | 0.911 / 0.681 | 0.935 / 0.879 | 0.883 / 0.773 |
48
- | ai4privacy/Spanish | 200 | 0.933 / 0.779 | 0.922 / 0.726 | 0.960 / 0.903 | 0.906 / 0.790 |
49
- | gretel/Dutch | 150 | 0.652 / 0.415 | 0.634 / 0.383 | 0.620 / 0.441 | 0.592 / 0.338 |
50
- | gretel/English | 150 | 0.686 / 0.469 | 0.657 / 0.400 | 0.653 / 0.518 | 0.598 / 0.369 |
51
- | gretel/France | 150 | 0.662 / 0.429 | 0.653 / 0.397 | 0.690 / 0.493 | 0.682 / 0.422 |
52
- | gretel/German | 150 | 0.655 / 0.427 | 0.641 / 0.392 | 0.607 / 0.459 | 0.567 / 0.336 |
53
- | gretel/Italian | 150 | 0.660 / 0.418 | 0.649 / 0.376 | 0.625 / 0.421 | 0.597 / 0.312 |
54
- | gretel/Spanish | 150 | 0.686 / 0.467 | 0.671 / 0.421 | 0.669 / 0.494 | 0.651 / 0.384 |
55
- | gretel/Swedish | 150 | 0.627 / 0.384 | 0.609 / 0.351 | 0.593 / 0.433 | 0.555 / 0.322 |
56
- | kiji/Danish | 150 | 0.790 / 0.311 | 0.749 / 0.293 | 0.784 / 0.324 | 0.715 / 0.280 |
57
- | kiji/Dutch | 150 | 0.850 / 0.395 | 0.830 / 0.370 | 0.838 / 0.433 | 0.809 / 0.414 |
58
- | kiji/English | 150 | 0.840 / 0.361 | 0.836 / 0.338 | 0.834 / 0.371 | 0.669 / 0.253 |
59
- | kiji/French | 150 | 0.821 / 0.374 | 0.818 / 0.368 | 0.829 / 0.392 | 0.730 / 0.311 |
60
- | kiji/German | 150 | 0.870 / 0.390 | 0.855 / 0.361 | 0.856 / 0.391 | 0.752 / 0.331 |
61
- | kiji/Spanish | 150 | 0.805 / 0.414 | 0.793 / 0.377 | 0.846 / 0.462 | 0.767 / 0.389 |
62
- | nemotron/English | 1000 | 0.817 / 0.613 | 0.791 / 0.583 | 0.823 / 0.661 | 0.696 / 0.471 |
63
 
64
  ## Speed
65
 
66
- CPU milliseconds per 1,000 characters, 50 Nemotron test documents, 3 threads (`results/speed.json`, `results/test_mine.json`).
 
67
 
68
  | Run | pii-filter-small int8 | pii-filter-small PyTorch | privacy-filter (opf, Viterbi) | privacy-filter (transformers) |
69
  |---|---|---|---|---|
70
  | Run 1 (with the test scoring) | 120.6 | | | 1,280.6 |
71
  | Run 2 (speed only, one warm-up document) | 121.2 | 224.7 | 16,894.4 | |
 
72
 
73
  In my gate the int8 file had to be at most 240 ms and at least 5 times faster than privacy-filter in the same run: 120.6 against 1,280.6 ms (10.6 times).
74
  Before training, privacy-filter through `transformers` needed 1,198.6 ms in a separate run (`results/test_privacy_filter_transformers.json`).
@@ -85,7 +90,9 @@ Before training, privacy-filter through `transformers` needed 1,198.6 ms in a se
85
  | multilingual-e5-small seed 42 (not released, not tested) | 117,518,625 | 0.8956 | 0.6053 | 10 min |
86
 
87
  ONNX on development texts, seed 43 (`results/onnx_dev.json`): PyTorch 0.9042, ONNX fp32 0.9042, ONNX int8 0.8971 character F1.
88
- A first int8 file without the recipe in `export_onnx.py` reached only 0.389. The fp32 ONNX file is not released because I did not measure it on the test sets.
 
 
89
 
90
  ## Gate and test use
91
 
@@ -94,11 +101,74 @@ The rules are in the Hub repo under `rules/` (German), committed to my private r
94
  1. Label mapping and test sampling, then privacy-filter through `transformers` on the test samples, to set the gate (22 Nov 2026, commit d397926).
95
  2. Gate, before any training (commit dea4fab): mean character F1 at least 0.697, no set more than 0.06 below privacy-filter, mean span F1 at least 0.422, int8 at most 240 ms per 1,000 characters, 5 times faster than privacy-filter, and within 0.01 mean character F1 of PyTorch.
96
  3. Rule for the single test opening of my models (commit 5cdb42c). Result: all points passed except the last; int8 lost 0.018 (0.7915 against 0.8092, both as stored in `results/test_mine.json`).
 
97
  4. Decision rule after the failed point, before measuring privacy-filter with `opf` (commit 55d98a8): publish only if the mean of my 3 seeds stays within 0.03 of the `opf` row on average and within 0.06 on every set. It did (0.809 against 0.811; largest gap ai4privacy, 0.931 against 0.952).
98
  5. Speed run with `opf` on CPU, on 50 test documents, no scores.
 
 
99
 
100
  The overlap check in `make_texts.py` read the test texts (not their labels) and dropped 124 of 24,000 generated texts (`results/overlap_check.json`).
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  ## Licences
103
 
104
- jhu-clsp/mmBERT-small MIT, openai/privacy-filter Apache 2.0, DeepSeek V4.1 Flash MIT. ai4privacy/pii-masking-300k: own licence for academic use, test only. nvidia/Nemotron-PII CC BY 4.0, gretelai/synthetic_pii_finance_multilingual Apache 2.0, DataikuNLP/kiji-pii-training-data Apache 2.0.
 
11
  |---|---|---|---|---|---|
12
  | pii-filter-small (seed 43, shipped) | 0.929 | 0.817 | 0.830 | 0.661 | 0.809 |
13
  | mean of 3 seeds | 0.931 | 0.813 | 0.833 | 0.660 | 0.809 |
14
+ | int8 file `onnx/model_quantized.onnx` (v1.0.3) | 0.924 | 0.823 | 0.844 | 0.649 | 0.810 |
15
+ | int8 file `model_int8.onnx` (v1.0 to v1.0.2, no longer shipped) | 0.915 | 0.791 | 0.815 | 0.645 | 0.791 |
16
  | privacy-filter, official opf decoder | 0.952 | 0.823 | 0.832 | 0.637 | 0.811 |
17
  | privacy-filter through transformers (argmax) | 0.868 | 0.696 | 0.737 | 0.606 | 0.726 |
18
  | privacy-filter, opf argmax | 0.952 | 0.823 | 0.834 | 0.634 | 0.811 |
 
25
  |---|---|---|---|---|---|
26
  | pii-filter-small (seed 43, shipped) | 0.735 | 0.613 | 0.374 | 0.429 | 0.538 |
27
  | mean of 3 seeds | 0.731 | 0.612 | 0.375 | 0.433 | 0.538 |
28
+ | int8 file `onnx/model_quantized.onnx` (v1.0.3) | 0.709 | 0.621 | 0.386 | 0.404 | 0.530 |
29
+ | int8 file `model_int8.onnx` (v1.0 to v1.0.2, no longer shipped) | 0.686 | 0.583 | 0.352 | 0.388 | 0.502 |
30
  | privacy-filter, official opf decoder | 0.883 | 0.661 | 0.397 | 0.465 | 0.601 |
31
  | privacy-filter through transformers (argmax) | 0.735 | 0.471 | 0.327 | 0.353 | 0.471 |
32
  | privacy-filter, opf argmax | 0.873 | 0.638 | 0.393 | 0.399 | 0.576 |
 
34
  | seed 44 | 0.734 | 0.608 | 0.374 | 0.438 | 0.538 |
35
 
36
  "privacy-filter, opf argmax" is the `opf` package with its argmax decoder instead of Viterbi. Seed 43 is the released model.
37
+ The v1.0.3 int8 row is `results/test_onnx_quantized.json`; I did not run `onnx/model.onnx` (fp32) on the test sets.
38
 
39
  ## Test per language
40
 
41
+ Character F1 / span F1. Columns: my model (seed 43), the int8 file of v1.0, privacy-filter with `opf` Viterbi, privacy-filter through `transformers`, the int8 file of v1.0.3.
42
  Gretel names French "France" in its data.
43
 
44
+ | Set / language | Documents | pii-filter-small | int8 v1.0 | privacy-filter (opf) | privacy-filter (transformers) | int8 v1.0.3 |
45
+ |---|---|---|---|---|---|---|
46
+ | ai4privacy/Dutch | 200 | 0.906 / 0.686 | 0.891 / 0.647 | 0.933 / 0.841 | 0.871 / 0.724 | 0.904 / 0.668 |
47
+ | ai4privacy/English | 200 | 0.934 / 0.736 | 0.917 / 0.706 | 0.961 / 0.897 | 0.783 / 0.614 | 0.930 / 0.717 |
48
+ | ai4privacy/French | 200 | 0.940 / 0.745 | 0.925 / 0.677 | 0.963 / 0.897 | 0.872 / 0.748 | 0.931 / 0.708 |
49
+ | ai4privacy/German | 200 | 0.940 / 0.745 | 0.924 / 0.682 | 0.958 / 0.886 | 0.900 / 0.788 | 0.929 / 0.707 |
50
+ | ai4privacy/Italian | 200 | 0.920 / 0.720 | 0.911 / 0.681 | 0.935 / 0.879 | 0.883 / 0.773 | 0.914 / 0.691 |
51
+ | ai4privacy/Spanish | 200 | 0.933 / 0.779 | 0.922 / 0.726 | 0.960 / 0.903 | 0.906 / 0.790 | 0.933 / 0.763 |
52
+ | gretel/Dutch | 150 | 0.652 / 0.415 | 0.634 / 0.383 | 0.620 / 0.441 | 0.592 / 0.338 | 0.631 / 0.387 |
53
+ | gretel/English | 150 | 0.686 / 0.469 | 0.657 / 0.400 | 0.653 / 0.518 | 0.598 / 0.369 | 0.687 / 0.446 |
54
+ | gretel/France | 150 | 0.662 / 0.429 | 0.653 / 0.397 | 0.690 / 0.493 | 0.682 / 0.422 | 0.659 / 0.394 |
55
+ | gretel/German | 150 | 0.655 / 0.427 | 0.641 / 0.392 | 0.607 / 0.459 | 0.567 / 0.336 | 0.640 / 0.405 |
56
+ | gretel/Italian | 150 | 0.660 / 0.418 | 0.649 / 0.376 | 0.625 / 0.421 | 0.597 / 0.312 | 0.646 / 0.388 |
57
+ | gretel/Spanish | 150 | 0.686 / 0.467 | 0.671 / 0.421 | 0.669 / 0.494 | 0.651 / 0.384 | 0.668 / 0.454 |
58
+ | gretel/Swedish | 150 | 0.627 / 0.384 | 0.609 / 0.351 | 0.593 / 0.433 | 0.555 / 0.322 | 0.610 / 0.364 |
59
+ | kiji/Danish | 150 | 0.790 / 0.311 | 0.749 / 0.293 | 0.784 / 0.324 | 0.715 / 0.280 | 0.801 / 0.323 |
60
+ | kiji/Dutch | 150 | 0.850 / 0.395 | 0.830 / 0.370 | 0.838 / 0.433 | 0.809 / 0.414 | 0.859 / 0.414 |
61
+ | kiji/English | 150 | 0.840 / 0.361 | 0.836 / 0.338 | 0.834 / 0.371 | 0.669 / 0.253 | 0.855 / 0.370 |
62
+ | kiji/French | 150 | 0.821 / 0.374 | 0.818 / 0.368 | 0.829 / 0.392 | 0.730 / 0.311 | 0.839 / 0.382 |
63
+ | kiji/German | 150 | 0.870 / 0.390 | 0.855 / 0.361 | 0.856 / 0.391 | 0.752 / 0.331 | 0.881 / 0.401 |
64
+ | kiji/Spanish | 150 | 0.805 / 0.414 | 0.793 / 0.377 | 0.846 / 0.462 | 0.767 / 0.389 | 0.826 / 0.424 |
65
+ | nemotron/English | 1000 | 0.817 / 0.613 | 0.791 / 0.583 | 0.823 / 0.661 | 0.696 / 0.471 | 0.823 / 0.621 |
66
 
67
  ## Speed
68
 
69
+ CPU milliseconds per 1,000 characters, 50 Nemotron test documents, 3 threads (`results/speed.json`, `results/test_mine.json`, `results/speed_onnx.json`).
70
+ The int8 column of runs 1 and 2 is the v1.0 file. Run 3 came later, possibly on a different machine, so compare its numbers with the other runs with care.
71
 
72
  | Run | pii-filter-small int8 | pii-filter-small PyTorch | privacy-filter (opf, Viterbi) | privacy-filter (transformers) |
73
  |---|---|---|---|---|
74
  | Run 1 (with the test scoring) | 120.6 | | | 1,280.6 |
75
  | Run 2 (speed only, one warm-up document) | 121.2 | 224.7 | 16,894.4 | |
76
+ | Run 3 (v1.0.3 files, speed only, one warm-up document) | 201.7 (`model_quantized.onnx`); 230.9 (`model.onnx`) | | | |
77
 
78
  In my gate the int8 file had to be at most 240 ms and at least 5 times faster than privacy-filter in the same run: 120.6 against 1,280.6 ms (10.6 times).
79
  Before training, privacy-filter through `transformers` needed 1,198.6 ms in a separate run (`results/test_privacy_filter_transformers.json`).
 
90
  | multilingual-e5-small seed 42 (not released, not tested) | 117,518,625 | 0.8956 | 0.6053 | 10 min |
91
 
92
  ONNX on development texts, seed 43 (`results/onnx_dev.json`): PyTorch 0.9042, ONNX fp32 0.9042, ONNX int8 0.8971 character F1.
93
+ A first int8 file without that recipe reached only 0.389.
94
+
95
+ For v1.0.3 I compared several int8 recipes with PyTorch on 242 other development texts (`onnx/quantization_check.json` in the Hub repo): share of tokens with the same arg-max label, CPU time and size. The rule, written before the comparison, was to ship the smallest int8 file with at least 0.998 agreement. Only the file with an int8 embedding table and fp32 everywhere else passed (0.99926, 268 MB). The v1.0 recipe (int8 MatMul) kept 0.97614. `onnx/model.onnx` agreed on every token (1.0).
96
 
97
  ## Gate and test use
98
 
 
101
  1. Label mapping and test sampling, then privacy-filter through `transformers` on the test samples, to set the gate (22 Nov 2026, commit d397926).
102
  2. Gate, before any training (commit dea4fab): mean character F1 at least 0.697, no set more than 0.06 below privacy-filter, mean span F1 at least 0.422, int8 at most 240 ms per 1,000 characters, 5 times faster than privacy-filter, and within 0.01 mean character F1 of PyTorch.
103
  3. Rule for the single test opening of my models (commit 5cdb42c). Result: all points passed except the last; int8 lost 0.018 (0.7915 against 0.8092, both as stored in `results/test_mine.json`).
104
+ The v1.0.3 int8 file gains 0.0007 on the same measure (0.8099 against 0.8092). The gate was not decided again.
105
  4. Decision rule after the failed point, before measuring privacy-filter with `opf` (commit 55d98a8): publish only if the mean of my 3 seeds stays within 0.03 of the `opf` row on average and within 0.06 on every set. It did (0.809 against 0.811; largest gap ai4privacy, 0.931 against 0.952).
106
  5. Speed run with `opf` on CPU, on 50 test documents, no scores.
107
+ 6. v1.0.3: choice of the ONNX files on development texts only (commits 8e9ef58, 59ee73c), then one test run of the chosen int8 file and one speed run, under a rule written before (commit a6e2afc). Nothing about the files changed after that run.
108
+ 7. v1.0.3: one run of the official PIIMB evaluation (below), and one run of the `pipeline()` path on two clinical test sets (below).
109
 
110
  The overlap check in `make_texts.py` read the test texts (not their labels) and dropped 124 of 24,000 generated texts (`results/overlap_check.json`).
111
 
112
+ ## PII Masking Benchmark (PIIMB)
113
+
114
+ I ran the official `piimb evaluate` with default settings on the released weights (fp32). PIIMB scores masking per character, regardless of category, with F2 (recall counts more than precision), on six tasks. The other rows come from the public results dataset piimb/pii-masking-benchmark-results; I ranked all 37 entries by mean F2 (`results/piimb.json`). My submission to the leaderboard is pending. I removed overlap only against my own four test samples, not against the PIIMB data.
115
+
116
+ | Rank | Model | Parameters | ai4privacy-en | ai4privacy-multi | gretel | mapa-eur-lex | nemotron-pii | privy | Mean F2 |
117
+ |---|---|---|---|---|---|---|---|---|---|
118
+ | 1 | OpenMed/privacy-filter-multilingual-v2 | 1,400 M | 0.975 | 0.970 | 0.973 | 0.373 | 0.907 | 0.818 | 0.836 |
119
+ | 2 | OpenMed/OpenMed-PII-SuperClinical-Large-434M-v1 | 434 M | 0.944 | 0.899 | 0.945 | 0.524 | 0.963 | 0.734 | 0.835 |
120
+ | 3 | knowledgator/gliner-stream-pii-v1.0 | 677 M | 0.958 | 0.921 | 0.939 | 0.411 | 0.833 | 0.904 | 0.828 |
121
+ | 4 | OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1 | 141 M | 0.949 | 0.888 | 0.953 | 0.478 | 0.972 | 0.659 | 0.816 |
122
+ | 5 | OpenMed/privacy-filter-nemotron-v2 | 1,400 M | 0.978 | 0.976 | 0.983 | 0.384 | 0.941 | 0.593 | 0.809 |
123
+ | 6 | fastino/gliner2-privacy-filter-PII-multi | 307 M | 0.914 | 0.904 | 0.936 | 0.545 | 0.854 | 0.646 | 0.800 |
124
+ | 7 | nvidia/gliner-PII | 445 M | 0.945 | 0.913 | 0.920 | 0.531 | 0.772 | 0.714 | 0.799 |
125
+ | 8 | antoniogr7/pii-identifier-v0.1 | 150 M | 0.945 | 0.814 | 0.939 | 0.380 | 0.970 | 0.726 | 0.796 |
126
+ | 9 | hivetrace/gliner-guard-omni | 307 M | 0.955 | 0.926 | 0.891 | 0.559 | 0.759 | 0.636 | 0.788 |
127
+ | 10 | fastino/gliner2-multi-v1 | 307 M | 0.903 | 0.878 | 0.870 | 0.569 | 0.829 | 0.661 | 0.785 |
128
+ | 11 | knowledgator/gliner-pii-large-v1.0 | 440 M | 0.909 | 0.879 | 0.951 | 0.517 | 0.839 | 0.581 | 0.779 |
129
+ | 12 | kalyan-ks/ettin-68m-nemotron-pii | 68 M | 0.919 | 0.845 | 0.918 | 0.382 | 0.939 | 0.663 | 0.777 |
130
+ | 13 | VidaiUK/stirling-minimo-pii-10m | 92 M | 0.917 | 0.776 | 0.979 | 0.202 | 0.930 | 0.792 | 0.766 |
131
+ | 14 | kalyan-ks/ettin-32m-nemotron-pii | 32 M | 0.911 | 0.794 | 0.917 | 0.294 | 0.932 | 0.680 | 0.755 |
132
+ | 15 | fastino/gliner2-large-v1 | 486 M | 0.868 | 0.798 | 0.873 | 0.474 | 0.857 | 0.602 | 0.746 |
133
+ | 16 | gravitee-io/bert-small-pii-detection | 29 M | 0.900 | 0.729 | 0.818 | 0.273 | 0.693 | 0.987 | 0.733 |
134
+ | 17 | OpenMed/privacy-filter-nemotron | 1,400 M | 0.889 | 0.719 | 0.888 | 0.228 | 0.957 | 0.549 | 0.705 |
135
+ | 18 | OpenMed/privacy-filter-multilingual | 1,400 M | 0.942 | 0.844 | 0.864 | 0.321 | 0.766 | 0.468 | 0.701 |
136
+ | 19 | kalyan-ks/ettin-17m-nemotron-pii | 17 M | 0.865 | 0.723 | 0.868 | 0.234 | 0.895 | 0.553 | 0.690 |
137
+ | 20 | bardsai/eu-pii-anonimization-multilang | 278 M | 0.831 | 0.843 | 0.890 | 0.254 | 0.715 | 0.575 | 0.685 |
138
+ | 21 | scanpatch/pii-ner-nemotron | 559 M | 0.820 | 0.806 | 0.741 | 0.573 | 0.578 | 0.561 | 0.680 |
139
+ | 22 | knowledgator/gliner-pii-base-v1.0 | 166 M | 0.795 | 0.727 | 0.894 | 0.332 | 0.777 | 0.546 | 0.678 |
140
+ | 23 | **LukasKunhardt/pii-filter-small** | 141 M | 0.901 | 0.845 | 0.898 | 0.290 | 0.616 | 0.495 | 0.674 |
141
+ | 24 | urchade/gliner_multi_pii-v1 | 289 M | 0.735 | 0.762 | 0.795 | 0.424 | 0.731 | 0.555 | 0.667 |
142
+ | 25 | openai/privacy-filter | 1,399 M | 0.843 | 0.805 | 0.869 | 0.313 | 0.607 | 0.536 | 0.662 |
143
+ | 26 | fastino/gliner2-base-v1 | 208 M | 0.750 | 0.723 | 0.891 | 0.292 | 0.739 | 0.499 | 0.649 |
144
+ | 27 | tabularisai/eu-pii-safeguard | 559 M | 0.805 | 0.833 | 0.848 | 0.143 | 0.610 | 0.545 | 0.631 |
145
+ | 28 | gretelai/gretel-gliner-bi-small-v1.0 | 189 M | 0.716 | 0.644 | 0.975 | 0.312 | 0.719 | 0.404 | 0.628 |
146
+ | 29 | lakshyakh93/deberta_finetuned_pii | 139 M | 0.960 | 0.682 | 0.930 | 0.133 | 0.742 | 0.305 | 0.625 |
147
+ | 30 | gretelai/gretel-gliner-bi-base-v1.0 | 242 M | 0.624 | 0.596 | 0.978 | 0.359 | 0.703 | 0.356 | 0.603 |
148
+ | 31 | LiquidAI/LFM2.5-Encoder-350M-PII-Detector | 355 M | 0.819 | 0.808 | 0.811 | 0.099 | 0.500 | 0.545 | 0.597 |
149
+ | 32 | presidio/en_core_web_lg | 106 M | 0.734 | 0.622 | 0.758 | 0.154 | 0.729 | 0.518 | 0.586 |
150
+ | 33 | nationaldesignstudio/rampart | 18 M | 0.798 | 0.810 | 0.794 | 0.151 | 0.456 | 0.439 | 0.575 |
151
+ | 34 | HikmaAI/hikmaai-distilbert-pii | 135 M | 0.805 | 0.788 | 0.591 | 0.140 | 0.393 | 0.401 | 0.520 |
152
+ | 35 | iiiorg/piiranha-v1-detect-personal-information | 278 M | 0.803 | 0.813 | 0.607 | 0.146 | 0.360 | 0.369 | 0.516 |
153
+ | 36 | ai4privacy/llama-ai4privacy-multilingual-categorical-anonymiser-openpii | 150 M | 0.700 | 0.520 | 0.689 | 0.063 | 0.441 | 0.338 | 0.458 |
154
+ | 37 | ai4privacy/llama-ai4privacy-multilingual-anonymiser-openpii | 150 M | 0.562 | 0.488 | 0.576 | 0.067 | 0.339 | 0.272 | 0.384 |
155
+
156
+ ## Clinical notes, through `pipeline()`
157
+
158
+ An extra check outside the training domain, not part of the gate: the plain `pipeline("token-classification", aggregation_strategy="simple", stride=128)`, arg-max, on the GraSCCo test letters (German, real letters with replaced identifiers, CC BY 4.0) and the MDeID test split (synthetic clinical notes, CC BY-NC 4.0, test only). Scored with my clinical benchmark code, not `evaluate.py` (`results/test_pipeline_clinical.json`). A document has a leak if a name, ID, phone or fax number, e-mail address or street stays less than half redacted. The model was not trained for clinical text, and most documents leak something.
159
+
160
+ | Set | Language | Documents | Character precision | Character recall | Character F1 | Documents with a leak |
161
+ |---|---|---|---|---|---|---|
162
+ | GraSCCo test | all | 41 | 0.930 | 0.713 | 0.807 | 0.732 |
163
+ | MDeID test | all | 2,856 | 0.943 | 0.725 | 0.820 | 0.773 |
164
+ | MDeID test | de | 402 | 0.944 | 0.732 | 0.824 | 0.789 |
165
+ | MDeID test | en | 416 | 0.942 | 0.678 | 0.789 | 0.757 |
166
+ | MDeID test | es | 408 | 0.949 | 0.754 | 0.840 | 0.740 |
167
+ | MDeID test | fr | 410 | 0.945 | 0.766 | 0.846 | 0.720 |
168
+ | MDeID test | it | 404 | 0.941 | 0.750 | 0.835 | 0.752 |
169
+ | MDeID test | nl | 405 | 0.947 | 0.671 | 0.786 | 0.864 |
170
+ | MDeID test | pt | 411 | 0.937 | 0.722 | 0.816 | 0.791 |
171
+
172
  ## Licences
173
 
174
+ jhu-clsp/mmBERT-small MIT, openai/privacy-filter Apache 2.0, DeepSeek V4.1 Flash MIT. ai4privacy/pii-masking-300k: own licence for academic use, test only. nvidia/Nemotron-PII CC BY 4.0, gretelai/synthetic_pii_finance_multilingual Apache 2.0, DataikuNLP/kiji-pii-training-data Apache 2.0. piimb/pii-masking-benchmark CC BY-NC 4.0, test only.
code/README.md CHANGED
@@ -15,11 +15,12 @@ pip install torch transformers huggingface_hub numpy pandas requests onnx onnxru
15
  import evaluate
16
 
17
  tok, labels, run = evaluate.load_model("LukasKunhardt/pii-filter-small")
18
- print(evaluate.read("Hi, I'm Maria Keller. Call me at +49 151 2345 6789.", tok, labels, run))
19
- # with ONNX Runtime: evaluate.load_model("LukasKunhardt/pii-filter-small", onnx_file="onnx/model_int8.onnx")
 
20
  ```
21
 
22
- `read` returns `(start, end, category)` spans. It reads long texts in windows of 512 tokens that overlap by 128.
23
 
24
  ## Files
25
 
@@ -28,7 +29,7 @@ print(evaluate.read("Hi, I'm Maria Keller. Call me at +49 151 2345 6789.", tok,
28
  | `make_texts.py` | Writes texts with invented personal information through OpenRouter (`OPENROUTER_API_KEY`), and drops texts that overlap the test samples |
29
  | `label.py` | Labels the texts with openai/privacy-filter: spans and per-character category probabilities |
30
  | `train.py` | Trains the student on the teacher's spans (BIOES cross-entropy) and probabilities (KL), picks the checkpoint on development texts |
31
- | `export_onnx.py` | Exports to ONNX, quantises to int8 and compares both with PyTorch on the development texts |
32
  | `evaluate.py` | Draws the test samples, maps their labels (`mapping.json`), reads any model the same way, scores it; also runs privacy-filter through `opf` |
33
  | `plot_pareto.py` | Draws the charts of the model card from `results/` |
34
  | `results/` | The measurement files behind the model card and `RESULTS.md` |
 
15
  import evaluate
16
 
17
  tok, labels, run = evaluate.load_model("LukasKunhardt/pii-filter-small")
18
+ print(evaluate.read("Hi, I'm Anna Müller, born 12 May 1984. Call me at +49 151 2345 6789.", tok, labels, run))
19
+ # [(8, 19, 'private_person'), (26, 37, 'private_date'), (50, 67, 'private_phone')]
20
+ # with ONNX Runtime: evaluate.load_model("LukasKunhardt/pii-filter-small", onnx_file="onnx/model_quantized.onnx")
21
  ```
22
 
23
+ `read` returns `(start, end, category)` spans, joined over the BIOES labels and trimmed of spaces. It reads long texts in windows of 512 tokens that overlap by 128, as in training.
24
 
25
  ## Files
26
 
 
29
  | `make_texts.py` | Writes texts with invented personal information through OpenRouter (`OPENROUTER_API_KEY`), and drops texts that overlap the test samples |
30
  | `label.py` | Labels the texts with openai/privacy-filter: spans and per-character category probabilities |
31
  | `train.py` | Trains the student on the teacher's spans (BIOES cross-entropy) and probabilities (KL), picks the checkpoint on development texts |
32
+ | `export_onnx.py` | Writes `onnx/model.onnx` (fp32) and `onnx/model_quantized.onnx` (int8 embedding table) and compares both with PyTorch on the development texts |
33
  | `evaluate.py` | Draws the test samples, maps their labels (`mapping.json`), reads any model the same way, scores it; also runs privacy-filter through `opf` |
34
  | `plot_pareto.py` | Draws the charts of the model card from `results/` |
35
  | `results/` | The measurement files behind the model card and `RESULTS.md` |
code/evaluate.py CHANGED
@@ -12,7 +12,7 @@ Metrics per set and language:
12
  char F1 binary: is this character personal information (any category)
13
 
14
  python evaluate.py --model LukasKunhardt/pii-filter-small --out results/mine.json
15
- python evaluate.py --model LukasKunhardt/pii-filter-small --onnx onnx/model_int8.onnx --out results/mine_int8.json
16
  python evaluate.py --model openai/privacy-filter --out results/pf_transformers.json
17
  python evaluate.py --opf --out results/pf_opf.json # privacy-filter with its official decoder (pip install opf)
18
  python evaluate.py --model ... --speed # CPU ms per 1,000 characters on 50 Nemotron documents
 
12
  char F1 binary: is this character personal information (any category)
13
 
14
  python evaluate.py --model LukasKunhardt/pii-filter-small --out results/mine.json
15
+ python evaluate.py --model LukasKunhardt/pii-filter-small --onnx onnx/model_quantized.onnx --out results/mine_int8.json
16
  python evaluate.py --model openai/privacy-filter --out results/pf_transformers.json
17
  python evaluate.py --opf --out results/pf_opf.json # privacy-filter with its official decoder (pip install opf)
18
  python evaluate.py --model ... --speed # CPU ms per 1,000 characters on 50 Nemotron documents
code/export_onnx.py CHANGED
@@ -1,20 +1,22 @@
1
- """Export a trained student to ONNX and quantise it to int8 for CPU, then compare both files with PyTorch on the development split.
2
 
3
  python export_onnx.py --model model --out onnx --check labels.jsonl
4
- Writes model.onnx (fp32, an intermediate file) and model_int8.onnx.
 
5
  """
6
  import argparse
7
  import json
8
  import os
9
  import time
10
 
 
11
  import onnx
 
12
  import torch
13
  from onnxruntime.quantization import QuantType, quantize_dynamic
14
  from onnxruntime.quantization.shape_inference import quant_pre_process
15
  from transformers import AutoModelForTokenClassification, AutoTokenizer
16
 
17
- import evaluate
18
 
19
 
20
  class Logits(torch.nn.Module):
@@ -35,51 +37,58 @@ def export(model_dir, out):
35
  with torch.no_grad():
36
  torch.onnx.export(Logits(model), (x["input_ids"], x["attention_mask"]), f"{out}/model.onnx", input_names=["input_ids", "attention_mask"],
37
  output_names=["logits"], dynamic_axes=dyn, opset_version=17, dynamo=False)
38
- tok.save_pretrained(out)
39
- model.config.save_pretrained(out)
40
 
41
 
42
  def quantize(out):
43
- # A plain dynamic int8 file was unusable (development char F1 0.389 against 0.904 for fp32). What works: shape preprocessing,
44
- # per-channel weights, MatMul only, reduce_range, and the classification head kept in fp32.
45
- quant_pre_process(f"{out}/model.onnx", f"{out}/model_pre.onnx", skip_symbolic_shape=True)
46
- head = [n.name for n in onnx.load(f"{out}/model_pre.onnx", load_external_data=False).graph.node
 
47
  if n.op_type in ("MatMul", "Gemm") and ("classifier" in n.name or "/head/" in n.name)]
48
- quantize_dynamic(f"{out}/model_pre.onnx", f"{out}/model_int8.onnx", weight_type=QuantType.QInt8, per_channel=True, reduce_range=True,
49
- op_types_to_quantize=["MatMul"], nodes_to_exclude=head)
50
- os.remove(f"{out}/model_pre.onnx")
51
- return head
52
 
53
 
54
  def check(model_dir, out, labels_file, threads):
55
- """Character F1 against the teacher on the development split, and CPU time, for PyTorch, ONNX fp32 and ONNX int8."""
56
- dev = [r for r in map(json.loads, open(labels_file, encoding="utf-8")) if r["split"] == "dev"]
 
 
57
  torch.set_num_threads(threads)
 
 
 
 
58
  res = {}
59
- for name, onnx_file in [("torch", None), ("onnx_fp32", f"{out}/model.onnx"), ("onnx_int8", f"{out}/model_int8.onnx")]:
60
- tok, labels, run = evaluate.load_model(model_dir if onnx_file is None else out, onnx_file, "cpu", threads)
61
- rows = []
 
 
62
  t0 = time.time()
63
- for r in dev:
64
- doc = {"text": r["text"], "gold": sorted({tuple(s) for s in r["spans"]}), "ignore": []}
65
- rows.append((("dev", r["lang"]), evaluate.score(doc, evaluate.read(r["text"], tok, labels, run))))
66
- res[name] = evaluate.summarize(rows)["dev/all"]
67
- res[name]["seconds"] = round(time.time() - t0)
68
- print(name, json.dumps(res[name]), flush=True)
69
- return res
 
70
 
71
 
72
  def main():
73
  ap = argparse.ArgumentParser()
74
  ap.add_argument("--model", required=True, help="folder of the trained student")
75
  ap.add_argument("--out", default="onnx")
76
- ap.add_argument("--check", help="labels.jsonl from label.py; compares the files on its development split")
77
  ap.add_argument("--threads", type=int, default=3)
78
  a = ap.parse_args()
79
  export(a.model, a.out)
80
- print("kept in fp32:", quantize(a.out))
81
  if a.check:
82
- json.dump(check(a.model, a.out, a.check, a.threads), open(f"{a.out}/onnx_dev.json", "w"), indent=1)
83
 
84
 
85
  if __name__ == "__main__":
 
1
+ """Export a trained student to the two ONNX files of the Hub repo and compare them with PyTorch on the development split.
2
 
3
  python export_onnx.py --model model --out onnx --check labels.jsonl
4
+ Writes onnx/model.onnx (fp32) and onnx/model_quantized.onnx (int8 embedding table, all other weights fp32). These are the file
5
+ names transformers.js looks for, so `dtype: "q8"` there loads the int8 file.
6
  """
7
  import argparse
8
  import json
9
  import os
10
  import time
11
 
12
+ import numpy as np
13
  import onnx
14
+ import onnxruntime as ort
15
  import torch
16
  from onnxruntime.quantization import QuantType, quantize_dynamic
17
  from onnxruntime.quantization.shape_inference import quant_pre_process
18
  from transformers import AutoModelForTokenClassification, AutoTokenizer
19
 
 
20
 
21
 
22
  class Logits(torch.nn.Module):
 
37
  with torch.no_grad():
38
  torch.onnx.export(Logits(model), (x["input_ids"], x["attention_mask"]), f"{out}/model.onnx", input_names=["input_ids", "attention_mask"],
39
  output_names=["logits"], dynamic_axes=dyn, opset_version=17, dynamo=False)
 
 
40
 
41
 
42
  def quantize(out):
43
+ # The embedding table holds 98 of the 141 million parameters, so int8 there halves the file. I also tried int8 MatMul layers:
44
+ # the file got smaller and faster, but only 97.6 % of the tokens kept their PyTorch label (embeddings only: 99.93 %).
45
+ pre = f"{out}/model_pre.onnx"
46
+ quant_pre_process(f"{out}/model.onnx", pre, skip_symbolic_shape=True)
47
+ head = [n.name for n in onnx.load(pre, load_external_data=False).graph.node
48
  if n.op_type in ("MatMul", "Gemm") and ("classifier" in n.name or "/head/" in n.name)]
49
+ quantize_dynamic(pre, f"{out}/model_quantized.onnx", weight_type=QuantType.QInt8, per_channel=True, reduce_range=True,
50
+ op_types_to_quantize=["Gather"], nodes_to_exclude=head)
51
+ os.remove(pre)
 
52
 
53
 
54
  def check(model_dir, out, labels_file, threads):
55
+ """Per file: share of tokens with the same arg-max label as PyTorch (first 512 tokens of each development text), CPU time and size."""
56
+ texts = [r["text"] for r in map(json.loads, open(labels_file, encoding="utf-8")) if r["split"] == "dev"]
57
+ tok = AutoTokenizer.from_pretrained(model_dir)
58
+ model = AutoModelForTokenClassification.from_pretrained(model_dir).eval()
59
  torch.set_num_threads(threads)
60
+ enc = [tok(t, truncation=True, max_length=512, return_tensors="np") for t in texts]
61
+ with torch.no_grad():
62
+ ref = [model(input_ids=torch.tensor(e["input_ids"]), attention_mask=torch.tensor(e["attention_mask"])).logits[0].argmax(-1).numpy()
63
+ for e in enc]
64
  res = {}
65
+ for f in ("model.onnx", "model_quantized.onnx"):
66
+ opts = ort.SessionOptions()
67
+ opts.intra_op_num_threads = threads
68
+ session = ort.InferenceSession(f"{out}/{f}", opts, providers=["CPUExecutionProvider"])
69
+ same = n = 0
70
  t0 = time.time()
71
+ for e, r in zip(enc, ref):
72
+ z = session.run(None, {"input_ids": e["input_ids"].astype(np.int64), "attention_mask": e["attention_mask"].astype(np.int64)})[0][0]
73
+ same += int((z.argmax(-1) == r).sum())
74
+ n += len(r)
75
+ res[f"onnx/{f}"] = {"token_agreement": round(same / n, 5), "ms_per_text": round(1000 * (time.time() - t0) / len(enc), 1),
76
+ "mb": round(os.path.getsize(f"{out}/{f}") / 1e6, 1)}
77
+ print(f, json.dumps(res[f"onnx/{f}"]), flush=True)
78
+ return {"texts": len(texts), "files": res}
79
 
80
 
81
  def main():
82
  ap = argparse.ArgumentParser()
83
  ap.add_argument("--model", required=True, help="folder of the trained student")
84
  ap.add_argument("--out", default="onnx")
85
+ ap.add_argument("--check", help="labels.jsonl from label.py; compares both files with PyTorch on its development split")
86
  ap.add_argument("--threads", type=int, default=3)
87
  a = ap.parse_args()
88
  export(a.model, a.out)
89
+ quantize(a.out)
90
  if a.check:
91
+ json.dump(check(a.model, a.out, a.check, a.threads), open(f"{a.out}/quantization_check.json", "w"), indent=1)
92
 
93
 
94
  if __name__ == "__main__":
code/plot_pareto.py CHANGED
@@ -13,7 +13,7 @@ import matplotlib.pyplot as plt # noqa: E402
13
 
14
  HERE = os.path.dirname(os.path.abspath(__file__))
15
  SETS = ["ai4privacy", "nemotron", "kiji", "gretel"]
16
- MINE, OTHER = "#0072B2", "#D55E00" # blue and vermilion, distinct for colour-blind readers
17
 
18
 
19
  def load(name):
@@ -26,16 +26,16 @@ def mean_char_f1(res):
26
 
27
  def points():
28
  mine, opf, tf = load("test_mine.json"), load("test_privacy_filter_opf.json"), load("test_privacy_filter_transformers.json")
29
- speed = load("speed.json")
30
  params_mine = load("train_mmbert_small_seed43.json")["params"]
31
  params_pf = tf["openai/privacy-filter"]["params"]
32
- # name, params, mean char F1, CPU ms per 1,000 characters, mine?
33
  return [
34
- ("pii-filter-small", params_mine, mean_char_f1(mine["ours_s43"]), speed["ours_s43_torch_cpu"], True),
35
- ("pii-filter-small int8", params_mine, mean_char_f1(mine["ours_s43_onnx_int8"]), speed["ours_s43_onnx_int8_cpu"], True),
36
- ("privacy-filter (opf)", params_pf, mean_char_f1(opf["opf_viterbi"]), speed["privacy_filter_opf_viterbi_cpu"], False),
37
  ("privacy-filter (transformers)", params_pf, mean_char_f1(tf["openai/privacy-filter"]),
38
- mine["privacy_filter_cpu_ms_per_1k_chars"], False),
39
  ]
40
 
41
 
@@ -55,11 +55,18 @@ def draw(pts, xi, xlabel, title, caption, offsets, xlim, path):
55
  xy = [(p[xi], p[2]) for p in pts]
56
  f = front(xy)
57
  ax.step([x for x, _ in f], [y for _, y in f], where="post", color="#999999", lw=1.5, ls="--", zorder=1, label="Pareto front")
58
- for (name, *_, mine), (x, y) in zip(pts, xy):
59
- ax.scatter(x, y, s=170 if mine else 120, color=MINE if mine else "white", edgecolor=MINE if mine else OTHER, lw=2.5, zorder=3)
 
 
 
 
 
 
 
60
  dx, dy, ha = offsets[name]
61
- ax.annotate(f"{name}\n{y:.3f}", (x, y), xytext=(dx, dy), textcoords="offset points", ha=ha, va="center",
62
- fontsize=15, fontweight="bold" if mine else "normal", color="#222222")
63
  ax.set_xscale("log")
64
  ax.set_xlim(*xlim)
65
  ax.set_ylim(0.70, 0.83)
@@ -69,8 +76,8 @@ def draw(pts, xi, xlabel, title, caption, offsets, xlim, path):
69
  ax.grid(alpha=0.25)
70
  for side in ("top", "right"):
71
  ax.spines[side].set_visible(False)
72
- fig.text(0.5, 0.015, caption, ha="center", fontsize=12, color="#555555")
73
- fig.tight_layout(rect=(0, 0.04, 1, 1))
74
  fig.savefig(path + ".png")
75
  fig.savefig(path + ".svg")
76
  plt.close(fig)
@@ -81,16 +88,14 @@ def main():
81
  ap.add_argument("--out", default="pareto")
82
  a = ap.parse_args()
83
  pts = points()
84
- caption = "ai4privacy, Nemotron-PII, Kiji, Gretel test samples (4,150 documents). Filled: my model."
 
85
  draw(pts, 1, "Parameters (log scale)", "PII detection: quality against model size", caption,
86
- {"pii-filter-small": (14, 26, "left"), "pii-filter-small int8": (16, -16, "left"),
87
- "privacy-filter (opf)": (8, 30, "right"), "privacy-filter (transformers)": (-16, 0, "right")},
88
  (6e7, 3e9), a.out + "_size")
89
  draw(pts, 3, "CPU milliseconds per 1,000 characters (log scale, 3 threads)", "PII detection: quality against CPU time", caption,
90
- {"pii-filter-small": (14, 26, "left"), "pii-filter-small int8": (12, -30, "left"),
91
- "privacy-filter (opf)": (8, 30, "right"), "privacy-filter (transformers)": (16, 0, "left")},
92
  (60, 6e4), a.out + "_speed")
93
 
94
-
95
  if __name__ == "__main__":
96
  main()
 
13
 
14
  HERE = os.path.dirname(os.path.abspath(__file__))
15
  SETS = ["ai4privacy", "nemotron", "kiji", "gretel"]
16
+ MINE, LIGHT, OTHER = "#0072B2", "#56B4E9", "#D55E00" # blue, sky blue and vermilion, distinct for colour-blind readers
17
 
18
 
19
  def load(name):
 
26
 
27
  def points():
28
  mine, opf, tf = load("test_mine.json"), load("test_privacy_filter_opf.json"), load("test_privacy_filter_transformers.json")
29
+ int8, speed, speed_onnx = load("test_onnx_quantized.json"), load("speed.json"), load("speed_onnx.json")
30
  params_mine = load("train_mmbert_small_seed43.json")["params"]
31
  params_pf = tf["openai/privacy-filter"]["params"]
32
+ # name, params, mean char F1, CPU ms per 1,000 characters, marker (circle: other model, filled circle: mine, diamond: my int8 file)
33
  return [
34
+ ("pii-filter-small", params_mine, mean_char_f1(mine["ours_s43"]), speed["ours_s43_torch_cpu"], "mine"),
35
+ ("int8 file", params_mine, mean_char_f1(int8), speed_onnx["onnx_model_quantized_cpu"], "int8"),
36
+ ("privacy-filter (opf)", params_pf, mean_char_f1(opf["opf_viterbi"]), speed["privacy_filter_opf_viterbi_cpu"], "other"),
37
  ("privacy-filter (transformers)", params_pf, mean_char_f1(tf["openai/privacy-filter"]),
38
+ mine["privacy_filter_cpu_ms_per_1k_chars"], "other"),
39
  ]
40
 
41
 
 
55
  xy = [(p[xi], p[2]) for p in pts]
56
  f = front(xy)
57
  ax.step([x for x, _ in f], [y for _, y in f], where="post", color="#999999", lw=1.5, ls="--", zorder=1, label="Pareto front")
58
+ style = {"mine": dict(s=300, color=MINE, edgecolor=MINE, marker="o"), "int8": dict(s=100, color=LIGHT, edgecolor=MINE, marker="D"),
59
+ "other": dict(s=120, color="white", edgecolor=OTHER, marker="o")}
60
+ ys = {p[0]: y for p, (_, y) in zip(pts, xy)}
61
+ for (name, *_, kind), (x, y) in zip(pts, xy):
62
+ ax.scatter(x, y, lw=2.5, zorder=3, **style[kind])
63
+ if kind == "int8":
64
+ continue
65
+ # my two files sit almost on top of each other, so they share one label
66
+ text = f"{name}\nPyTorch {y:.3f}, int8 file {ys['int8 file']:.3f}" if kind == "mine" else f"{name}\n{y:.3f}"
67
  dx, dy, ha = offsets[name]
68
+ ax.annotate(text, (x, y), xytext=(dx, dy), textcoords="offset points", ha=ha, va="center",
69
+ fontsize=15, fontweight="bold" if kind == "mine" else "normal", color="#222222")
70
  ax.set_xscale("log")
71
  ax.set_xlim(*xlim)
72
  ax.set_ylim(0.70, 0.83)
 
76
  ax.grid(alpha=0.25)
77
  for side in ("top", "right"):
78
  ax.spines[side].set_visible(False)
79
+ fig.text(0.5, 0.012, caption, ha="center", va="bottom", fontsize=12, color="#555555", linespacing=1.4)
80
+ fig.tight_layout(rect=(0, 0.07, 1, 1))
81
  fig.savefig(path + ".png")
82
  fig.savefig(path + ".svg")
83
  plt.close(fig)
 
88
  ap.add_argument("--out", default="pareto")
89
  a = ap.parse_args()
90
  pts = points()
91
+ caption = ("ai4privacy, Nemotron-PII, Kiji, Gretel test samples (4,150 documents).\n"
92
+ "Blue: my model (large circle PyTorch weights, diamond int8 ONNX file).")
93
  draw(pts, 1, "Parameters (log scale)", "PII detection: quality against model size", caption,
94
+ {"pii-filter-small": (16, -48, "left"), "privacy-filter (opf)": (8, 30, "right"), "privacy-filter (transformers)": (-16, 0, "right")},
 
95
  (6e7, 3e9), a.out + "_size")
96
  draw(pts, 3, "CPU milliseconds per 1,000 characters (log scale, 3 threads)", "PII detection: quality against CPU time", caption,
97
+ {"pii-filter-small": (-10, -48, "left"), "privacy-filter (opf)": (8, 30, "right"), "privacy-filter (transformers)": (16, 0, "left")},
 
98
  (60, 6e4), a.out + "_speed")
99
 
 
100
  if __name__ == "__main__":
101
  main()
code/results/piimb.json ADDED
@@ -0,0 +1,531 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "note": "PIIMB (piimb/pii-masking-benchmark), character-level masking F2 per task (scores.test[0].f2), mean over six tasks. Other models from the dataset piimb/pii-masking-benchmark-results; pii-filter-small from my own run of piimb evaluate with default settings.",
3
+ "tasks": [
4
+ "ai4privacy-en",
5
+ "ai4privacy-multi",
6
+ "gretel",
7
+ "mapa-eur-lex",
8
+ "nemotron-pii",
9
+ "privy"
10
+ ],
11
+ "rows": [
12
+ {
13
+ "rank": 1,
14
+ "model": "OpenMed/privacy-filter-multilingual-v2",
15
+ "dtype": "bfloat16",
16
+ "n_parameters": 1399604809,
17
+ "license": "apache-2.0",
18
+ "mean_f2": 0.8359,
19
+ "ai4privacy-en": 0.9754,
20
+ "ai4privacy-multi": 0.9701,
21
+ "gretel": 0.9727,
22
+ "mapa-eur-lex": 0.3728,
23
+ "nemotron-pii": 0.907,
24
+ "privy": 0.8176
25
+ },
26
+ {
27
+ "rank": 2,
28
+ "model": "OpenMed/OpenMed-PII-SuperClinical-Large-434M-v1",
29
+ "dtype": "float32",
30
+ "n_parameters": 434120810,
31
+ "license": "apache-2.0",
32
+ "mean_f2": 0.8349,
33
+ "ai4privacy-en": 0.9443,
34
+ "ai4privacy-multi": 0.8987,
35
+ "gretel": 0.9449,
36
+ "mapa-eur-lex": 0.5245,
37
+ "nemotron-pii": 0.9631,
38
+ "privy": 0.7341
39
+ },
40
+ {
41
+ "rank": 3,
42
+ "model": "knowledgator/gliner-stream-pii-v1.0",
43
+ "dtype": "bfloat16",
44
+ "n_parameters": 676575232,
45
+ "license": null,
46
+ "mean_f2": 0.8277,
47
+ "ai4privacy-en": 0.9575,
48
+ "ai4privacy-multi": 0.9213,
49
+ "gretel": 0.9388,
50
+ "mapa-eur-lex": 0.4114,
51
+ "nemotron-pii": 0.8327,
52
+ "privy": 0.9043
53
+ },
54
+ {
55
+ "rank": 4,
56
+ "model": "OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1",
57
+ "dtype": "float32",
58
+ "n_parameters": 141385834,
59
+ "license": "apache-2.0",
60
+ "mean_f2": 0.8163,
61
+ "ai4privacy-en": 0.9485,
62
+ "ai4privacy-multi": 0.8882,
63
+ "gretel": 0.9529,
64
+ "mapa-eur-lex": 0.4776,
65
+ "nemotron-pii": 0.9717,
66
+ "privy": 0.6588
67
+ },
68
+ {
69
+ "rank": 5,
70
+ "model": "OpenMed/privacy-filter-nemotron-v2",
71
+ "dtype": "bfloat16",
72
+ "n_parameters": 1399607373,
73
+ "license": "other",
74
+ "mean_f2": 0.8093,
75
+ "ai4privacy-en": 0.9784,
76
+ "ai4privacy-multi": 0.9763,
77
+ "gretel": 0.9828,
78
+ "mapa-eur-lex": 0.3837,
79
+ "nemotron-pii": 0.9413,
80
+ "privy": 0.5931
81
+ },
82
+ {
83
+ "rank": 6,
84
+ "model": "fastino/gliner2-privacy-filter-PII-multi",
85
+ "dtype": "float32",
86
+ "n_parameters": 307098645,
87
+ "license": "apache-2.0",
88
+ "mean_f2": 0.7997,
89
+ "ai4privacy-en": 0.9139,
90
+ "ai4privacy-multi": 0.9037,
91
+ "gretel": 0.936,
92
+ "mapa-eur-lex": 0.5453,
93
+ "nemotron-pii": 0.8536,
94
+ "privy": 0.6459
95
+ },
96
+ {
97
+ "rank": 7,
98
+ "model": "nvidia/gliner-PII",
99
+ "dtype": "float32",
100
+ "n_parameters": 445463040,
101
+ "license": "other",
102
+ "mean_f2": 0.7992,
103
+ "ai4privacy-en": 0.9448,
104
+ "ai4privacy-multi": 0.9126,
105
+ "gretel": 0.9204,
106
+ "mapa-eur-lex": 0.5312,
107
+ "nemotron-pii": 0.7724,
108
+ "privy": 0.7137
109
+ },
110
+ {
111
+ "rank": 8,
112
+ "model": "antoniogr7/pii-identifier-v0.1",
113
+ "dtype": "float32",
114
+ "n_parameters": 149690223,
115
+ "license": "apache-2.0",
116
+ "mean_f2": 0.7957,
117
+ "ai4privacy-en": 0.9453,
118
+ "ai4privacy-multi": 0.8141,
119
+ "gretel": 0.9393,
120
+ "mapa-eur-lex": 0.3796,
121
+ "nemotron-pii": 0.9699,
122
+ "privy": 0.7257
123
+ },
124
+ {
125
+ "rank": 9,
126
+ "model": "hivetrace/gliner-guard-omni",
127
+ "dtype": "float32",
128
+ "n_parameters": 307098645,
129
+ "license": "apache-2.0",
130
+ "mean_f2": 0.7879,
131
+ "ai4privacy-en": 0.9551,
132
+ "ai4privacy-multi": 0.9263,
133
+ "gretel": 0.8913,
134
+ "mapa-eur-lex": 0.5591,
135
+ "nemotron-pii": 0.7594,
136
+ "privy": 0.6359
137
+ },
138
+ {
139
+ "rank": 10,
140
+ "model": "fastino/gliner2-multi-v1",
141
+ "dtype": "float32",
142
+ "n_parameters": 307098645,
143
+ "license": "apache-2.0",
144
+ "mean_f2": 0.7847,
145
+ "ai4privacy-en": 0.9031,
146
+ "ai4privacy-multi": 0.8779,
147
+ "gretel": 0.8697,
148
+ "mapa-eur-lex": 0.5686,
149
+ "nemotron-pii": 0.8285,
150
+ "privy": 0.6606
151
+ },
152
+ {
153
+ "rank": 11,
154
+ "model": "knowledgator/gliner-pii-large-v1.0",
155
+ "dtype": "float32",
156
+ "n_parameters": 440220163,
157
+ "license": "apache-2.0",
158
+ "mean_f2": 0.7795,
159
+ "ai4privacy-en": 0.9095,
160
+ "ai4privacy-multi": 0.8791,
161
+ "gretel": 0.9511,
162
+ "mapa-eur-lex": 0.5174,
163
+ "nemotron-pii": 0.8393,
164
+ "privy": 0.5807
165
+ },
166
+ {
167
+ "rank": 12,
168
+ "model": "kalyan-ks/ettin-68m-nemotron-pii",
169
+ "dtype": "bfloat16",
170
+ "n_parameters": 68462187,
171
+ "license": "mit",
172
+ "mean_f2": 0.7775,
173
+ "ai4privacy-en": 0.9188,
174
+ "ai4privacy-multi": 0.8447,
175
+ "gretel": 0.9182,
176
+ "mapa-eur-lex": 0.3818,
177
+ "nemotron-pii": 0.9385,
178
+ "privy": 0.663
179
+ },
180
+ {
181
+ "rank": 13,
182
+ "model": "VidaiUK/stirling-minimo-pii-10m",
183
+ "dtype": "float32",
184
+ "n_parameters": 92441166,
185
+ "license": "cc-by-nc-4.0",
186
+ "mean_f2": 0.7659,
187
+ "ai4privacy-en": 0.9167,
188
+ "ai4privacy-multi": 0.7757,
189
+ "gretel": 0.979,
190
+ "mapa-eur-lex": 0.2024,
191
+ "nemotron-pii": 0.93,
192
+ "privy": 0.7918
193
+ },
194
+ {
195
+ "rank": 14,
196
+ "model": "kalyan-ks/ettin-32m-nemotron-pii",
197
+ "dtype": "bfloat16",
198
+ "n_parameters": 32072171,
199
+ "license": "mit",
200
+ "mean_f2": 0.7548,
201
+ "ai4privacy-en": 0.9113,
202
+ "ai4privacy-multi": 0.7939,
203
+ "gretel": 0.9173,
204
+ "mapa-eur-lex": 0.2942,
205
+ "nemotron-pii": 0.9322,
206
+ "privy": 0.6798
207
+ },
208
+ {
209
+ "rank": 15,
210
+ "model": "fastino/gliner2-large-v1",
211
+ "dtype": "float32",
212
+ "n_parameters": 486444053,
213
+ "license": "apache-2.0",
214
+ "mean_f2": 0.7455,
215
+ "ai4privacy-en": 0.8684,
216
+ "ai4privacy-multi": 0.7984,
217
+ "gretel": 0.8725,
218
+ "mapa-eur-lex": 0.4739,
219
+ "nemotron-pii": 0.8573,
220
+ "privy": 0.6024
221
+ },
222
+ {
223
+ "rank": 16,
224
+ "model": "gravitee-io/bert-small-pii-detection",
225
+ "dtype": "float32",
226
+ "n_parameters": 28527155,
227
+ "license": "apache-2.0",
228
+ "mean_f2": 0.7332,
229
+ "ai4privacy-en": 0.8998,
230
+ "ai4privacy-multi": 0.7287,
231
+ "gretel": 0.8176,
232
+ "mapa-eur-lex": 0.273,
233
+ "nemotron-pii": 0.6933,
234
+ "privy": 0.987
235
+ },
236
+ {
237
+ "rank": 17,
238
+ "model": "OpenMed/privacy-filter-nemotron",
239
+ "dtype": "bfloat16",
240
+ "n_parameters": 1399607373,
241
+ "license": "apache-2.0",
242
+ "mean_f2": 0.7051,
243
+ "ai4privacy-en": 0.8892,
244
+ "ai4privacy-multi": 0.7192,
245
+ "gretel": 0.8882,
246
+ "mapa-eur-lex": 0.2281,
247
+ "nemotron-pii": 0.9568,
248
+ "privy": 0.5491
249
+ },
250
+ {
251
+ "rank": 18,
252
+ "model": "OpenMed/privacy-filter-multilingual",
253
+ "dtype": "bfloat16",
254
+ "n_parameters": 1399604809,
255
+ "license": "apache-2.0",
256
+ "mean_f2": 0.7008,
257
+ "ai4privacy-en": 0.9417,
258
+ "ai4privacy-multi": 0.8439,
259
+ "gretel": 0.8641,
260
+ "mapa-eur-lex": 0.3213,
261
+ "nemotron-pii": 0.7658,
262
+ "privy": 0.4679
263
+ },
264
+ {
265
+ "rank": 19,
266
+ "model": "kalyan-ks/ettin-17m-nemotron-pii",
267
+ "dtype": "bfloat16",
268
+ "n_parameters": 16890731,
269
+ "license": "mit",
270
+ "mean_f2": 0.6895,
271
+ "ai4privacy-en": 0.8647,
272
+ "ai4privacy-multi": 0.723,
273
+ "gretel": 0.8678,
274
+ "mapa-eur-lex": 0.2337,
275
+ "nemotron-pii": 0.8946,
276
+ "privy": 0.5534
277
+ },
278
+ {
279
+ "rank": 20,
280
+ "model": "bardsai/eu-pii-anonimization-multilang",
281
+ "dtype": "float32",
282
+ "n_parameters": 277506117,
283
+ "license": "apache-2.0",
284
+ "mean_f2": 0.6847,
285
+ "ai4privacy-en": 0.8314,
286
+ "ai4privacy-multi": 0.8433,
287
+ "gretel": 0.8902,
288
+ "mapa-eur-lex": 0.2537,
289
+ "nemotron-pii": 0.7146,
290
+ "privy": 0.5751
291
+ },
292
+ {
293
+ "rank": 21,
294
+ "model": "scanpatch/pii-ner-nemotron",
295
+ "dtype": "float32",
296
+ "n_parameters": 558897207,
297
+ "license": "apache-2.0",
298
+ "mean_f2": 0.6797,
299
+ "ai4privacy-en": 0.8197,
300
+ "ai4privacy-multi": 0.8056,
301
+ "gretel": 0.7407,
302
+ "mapa-eur-lex": 0.5732,
303
+ "nemotron-pii": 0.5779,
304
+ "privy": 0.5609
305
+ },
306
+ {
307
+ "rank": 22,
308
+ "model": "knowledgator/gliner-pii-base-v1.0",
309
+ "dtype": "float32",
310
+ "n_parameters": 166023936,
311
+ "license": "apache-2.0",
312
+ "mean_f2": 0.6784,
313
+ "ai4privacy-en": 0.7951,
314
+ "ai4privacy-multi": 0.7267,
315
+ "gretel": 0.894,
316
+ "mapa-eur-lex": 0.3323,
317
+ "nemotron-pii": 0.7766,
318
+ "privy": 0.5458
319
+ },
320
+ {
321
+ "rank": 23,
322
+ "model": "LukasKunhardt/pii-filter-small",
323
+ "dtype": "float32",
324
+ "n_parameters": 140654241,
325
+ "license": "mit",
326
+ "mean_f2": 0.6743,
327
+ "ai4privacy-en": 0.9013,
328
+ "ai4privacy-multi": 0.845,
329
+ "gretel": 0.8984,
330
+ "mapa-eur-lex": 0.2901,
331
+ "nemotron-pii": 0.6155,
332
+ "privy": 0.4955
333
+ },
334
+ {
335
+ "rank": 24,
336
+ "model": "urchade/gliner_multi_pii-v1",
337
+ "dtype": "float32",
338
+ "n_parameters": 288949504,
339
+ "license": "apache-2.0",
340
+ "mean_f2": 0.667,
341
+ "ai4privacy-en": 0.7353,
342
+ "ai4privacy-multi": 0.7618,
343
+ "gretel": 0.7948,
344
+ "mapa-eur-lex": 0.4241,
345
+ "nemotron-pii": 0.7307,
346
+ "privy": 0.5553
347
+ },
348
+ {
349
+ "rank": 25,
350
+ "model": "openai/privacy-filter",
351
+ "dtype": "bfloat16",
352
+ "n_parameters": 1399486865,
353
+ "license": "apache-2.0",
354
+ "mean_f2": 0.6621,
355
+ "ai4privacy-en": 0.8426,
356
+ "ai4privacy-multi": 0.8052,
357
+ "gretel": 0.8687,
358
+ "mapa-eur-lex": 0.3129,
359
+ "nemotron-pii": 0.6068,
360
+ "privy": 0.5362
361
+ },
362
+ {
363
+ "rank": 26,
364
+ "model": "fastino/gliner2-base-v1",
365
+ "dtype": "float32",
366
+ "n_parameters": 208476821,
367
+ "license": "apache-2.0",
368
+ "mean_f2": 0.6489,
369
+ "ai4privacy-en": 0.7495,
370
+ "ai4privacy-multi": 0.7234,
371
+ "gretel": 0.891,
372
+ "mapa-eur-lex": 0.2918,
373
+ "nemotron-pii": 0.739,
374
+ "privy": 0.499
375
+ },
376
+ {
377
+ "rank": 27,
378
+ "model": "tabularisai/eu-pii-safeguard",
379
+ "dtype": "float32",
380
+ "n_parameters": 558916682,
381
+ "license": "other",
382
+ "mean_f2": 0.6306,
383
+ "ai4privacy-en": 0.8046,
384
+ "ai4privacy-multi": 0.833,
385
+ "gretel": 0.8476,
386
+ "mapa-eur-lex": 0.1435,
387
+ "nemotron-pii": 0.6103,
388
+ "privy": 0.5446
389
+ },
390
+ {
391
+ "rank": 28,
392
+ "model": "gretelai/gretel-gliner-bi-small-v1.0",
393
+ "dtype": "float32",
394
+ "n_parameters": 189107328,
395
+ "license": "apache-2.0",
396
+ "mean_f2": 0.6285,
397
+ "ai4privacy-en": 0.7155,
398
+ "ai4privacy-multi": 0.6444,
399
+ "gretel": 0.9752,
400
+ "mapa-eur-lex": 0.3124,
401
+ "nemotron-pii": 0.7194,
402
+ "privy": 0.4041
403
+ },
404
+ {
405
+ "rank": 29,
406
+ "model": "lakshyakh93/deberta_finetuned_pii",
407
+ "dtype": "float32",
408
+ "n_parameters": 138690932,
409
+ "license": "mit",
410
+ "mean_f2": 0.6255,
411
+ "ai4privacy-en": 0.96,
412
+ "ai4privacy-multi": 0.6825,
413
+ "gretel": 0.9301,
414
+ "mapa-eur-lex": 0.1328,
415
+ "nemotron-pii": 0.7422,
416
+ "privy": 0.3055
417
+ },
418
+ {
419
+ "rank": 30,
420
+ "model": "gretelai/gretel-gliner-bi-base-v1.0",
421
+ "dtype": "float32",
422
+ "n_parameters": 242281344,
423
+ "license": "apache-2.0",
424
+ "mean_f2": 0.6028,
425
+ "ai4privacy-en": 0.624,
426
+ "ai4privacy-multi": 0.5957,
427
+ "gretel": 0.9777,
428
+ "mapa-eur-lex": 0.3594,
429
+ "nemotron-pii": 0.7033,
430
+ "privy": 0.3565
431
+ },
432
+ {
433
+ "rank": 31,
434
+ "model": "LiquidAI/LFM2.5-Encoder-350M-PII-Detector",
435
+ "dtype": "float32",
436
+ "n_parameters": 354648993,
437
+ "license": "other",
438
+ "mean_f2": 0.5969,
439
+ "ai4privacy-en": 0.8189,
440
+ "ai4privacy-multi": 0.8077,
441
+ "gretel": 0.8112,
442
+ "mapa-eur-lex": 0.0987,
443
+ "nemotron-pii": 0.5001,
444
+ "privy": 0.545
445
+ },
446
+ {
447
+ "rank": 32,
448
+ "model": "presidio/en_core_web_lg",
449
+ "dtype": "float32",
450
+ "n_parameters": 106175470,
451
+ "license": "MIT",
452
+ "mean_f2": 0.5858,
453
+ "ai4privacy-en": 0.7342,
454
+ "ai4privacy-multi": 0.6218,
455
+ "gretel": 0.7583,
456
+ "mapa-eur-lex": 0.1539,
457
+ "nemotron-pii": 0.7288,
458
+ "privy": 0.518
459
+ },
460
+ {
461
+ "rank": 33,
462
+ "model": "nationaldesignstudio/rampart",
463
+ "dtype": "q4",
464
+ "n_parameters": 18434723,
465
+ "license": "cc-by-4.0",
466
+ "mean_f2": 0.5748,
467
+ "ai4privacy-en": 0.7981,
468
+ "ai4privacy-multi": 0.8103,
469
+ "gretel": 0.7938,
470
+ "mapa-eur-lex": 0.1509,
471
+ "nemotron-pii": 0.4562,
472
+ "privy": 0.4394
473
+ },
474
+ {
475
+ "rank": 34,
476
+ "model": "HikmaAI/hikmaai-distilbert-pii",
477
+ "dtype": "float32",
478
+ "n_parameters": 134760995,
479
+ "license": "apache-2.0",
480
+ "mean_f2": 0.5196,
481
+ "ai4privacy-en": 0.8051,
482
+ "ai4privacy-multi": 0.7878,
483
+ "gretel": 0.5906,
484
+ "mapa-eur-lex": 0.14,
485
+ "nemotron-pii": 0.3929,
486
+ "privy": 0.401
487
+ },
488
+ {
489
+ "rank": 35,
490
+ "model": "iiiorg/piiranha-v1-detect-personal-information",
491
+ "dtype": "float32",
492
+ "n_parameters": 278232594,
493
+ "license": "cc-by-nc-nd-4.0",
494
+ "mean_f2": 0.5163,
495
+ "ai4privacy-en": 0.8027,
496
+ "ai4privacy-multi": 0.8128,
497
+ "gretel": 0.6074,
498
+ "mapa-eur-lex": 0.1459,
499
+ "nemotron-pii": 0.36,
500
+ "privy": 0.3691
501
+ },
502
+ {
503
+ "rank": 36,
504
+ "model": "ai4privacy/llama-ai4privacy-multilingual-categorical-anonymiser-openpii",
505
+ "dtype": "float32",
506
+ "n_parameters": 149635624,
507
+ "license": "mit",
508
+ "mean_f2": 0.4582,
509
+ "ai4privacy-en": 0.6995,
510
+ "ai4privacy-multi": 0.5196,
511
+ "gretel": 0.6886,
512
+ "mapa-eur-lex": 0.063,
513
+ "nemotron-pii": 0.4407,
514
+ "privy": 0.338
515
+ },
516
+ {
517
+ "rank": 37,
518
+ "model": "ai4privacy/llama-ai4privacy-multilingual-anonymiser-openpii",
519
+ "dtype": "float32",
520
+ "n_parameters": 149607171,
521
+ "license": "mit",
522
+ "mean_f2": 0.3838,
523
+ "ai4privacy-en": 0.5617,
524
+ "ai4privacy-multi": 0.4878,
525
+ "gretel": 0.5757,
526
+ "mapa-eur-lex": 0.0669,
527
+ "nemotron-pii": 0.3386,
528
+ "privy": 0.272
529
+ }
530
+ ]
531
+ }
code/results/speed_onnx.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "note": "CPU ms per 1,000 characters, same 50 Nemotron test documents, 3 threads, evaluate.py --speed, one run per file, after one warm-up document. A later run than speed.json, so the machine may differ.",
3
+ "threads": 3,
4
+ "docs": 50,
5
+ "onnx_model_quantized_cpu": 201.7,
6
+ "onnx_model_fp32_cpu": 230.9
7
+ }
code/results/test_onnx_quantized.json ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "note": "onnx/model_quantized.onnx (int8 embedding table, other weights fp32) on the four test samples, read and scored by evaluate.py (--onnx). One run, after the file was chosen on development texts.",
3
+ "ai4privacy/Dutch": {
4
+ "n": 200,
5
+ "span_f1": 0.6683,
6
+ "char_f1": 0.904,
7
+ "span_p": 0.6585,
8
+ "span_r": 0.6784
9
+ },
10
+ "ai4privacy/English": {
11
+ "n": 200,
12
+ "span_f1": 0.7169,
13
+ "char_f1": 0.9302,
14
+ "span_p": 0.6775,
15
+ "span_r": 0.7612
16
+ },
17
+ "ai4privacy/French": {
18
+ "n": 200,
19
+ "span_f1": 0.7082,
20
+ "char_f1": 0.9312,
21
+ "span_p": 0.6527,
22
+ "span_r": 0.7741
23
+ },
24
+ "ai4privacy/German": {
25
+ "n": 200,
26
+ "span_f1": 0.707,
27
+ "char_f1": 0.929,
28
+ "span_p": 0.6476,
29
+ "span_r": 0.7786
30
+ },
31
+ "ai4privacy/Italian": {
32
+ "n": 200,
33
+ "span_f1": 0.691,
34
+ "char_f1": 0.9145,
35
+ "span_p": 0.6351,
36
+ "span_r": 0.7577
37
+ },
38
+ "ai4privacy/Spanish": {
39
+ "n": 200,
40
+ "span_f1": 0.7631,
41
+ "char_f1": 0.9328,
42
+ "span_p": 0.7346,
43
+ "span_r": 0.794
44
+ },
45
+ "ai4privacy/all": {
46
+ "n": 1200,
47
+ "span_f1": 0.7091,
48
+ "char_f1": 0.9237,
49
+ "span_p": 0.6674,
50
+ "span_r": 0.7563
51
+ },
52
+ "gretel/Dutch": {
53
+ "n": 150,
54
+ "span_f1": 0.387,
55
+ "char_f1": 0.631,
56
+ "span_p": 0.2877,
57
+ "span_r": 0.591
58
+ },
59
+ "gretel/English": {
60
+ "n": 150,
61
+ "span_f1": 0.4463,
62
+ "char_f1": 0.6871,
63
+ "span_p": 0.366,
64
+ "span_r": 0.5717
65
+ },
66
+ "gretel/France": {
67
+ "n": 150,
68
+ "span_f1": 0.3943,
69
+ "char_f1": 0.6594,
70
+ "span_p": 0.2805,
71
+ "span_r": 0.6636
72
+ },
73
+ "gretel/German": {
74
+ "n": 150,
75
+ "span_f1": 0.4048,
76
+ "char_f1": 0.6404,
77
+ "span_p": 0.2982,
78
+ "span_r": 0.63
79
+ },
80
+ "gretel/Italian": {
81
+ "n": 150,
82
+ "span_f1": 0.3879,
83
+ "char_f1": 0.6462,
84
+ "span_p": 0.2799,
85
+ "span_r": 0.6315
86
+ },
87
+ "gretel/Spanish": {
88
+ "n": 150,
89
+ "span_f1": 0.4541,
90
+ "char_f1": 0.6685,
91
+ "span_p": 0.3421,
92
+ "span_r": 0.6753
93
+ },
94
+ "gretel/Swedish": {
95
+ "n": 150,
96
+ "span_f1": 0.3643,
97
+ "char_f1": 0.6101,
98
+ "span_p": 0.2619,
99
+ "span_r": 0.5984
100
+ },
101
+ "gretel/all": {
102
+ "n": 1050,
103
+ "span_f1": 0.4042,
104
+ "char_f1": 0.6488,
105
+ "span_p": 0.2993,
106
+ "span_r": 0.6219
107
+ },
108
+ "kiji/Danish": {
109
+ "n": 150,
110
+ "span_f1": 0.3227,
111
+ "char_f1": 0.801,
112
+ "span_p": 0.4752,
113
+ "span_r": 0.2442
114
+ },
115
+ "kiji/Dutch": {
116
+ "n": 150,
117
+ "span_f1": 0.4139,
118
+ "char_f1": 0.859,
119
+ "span_p": 0.5687,
120
+ "span_r": 0.3254
121
+ },
122
+ "kiji/English": {
123
+ "n": 150,
124
+ "span_f1": 0.3696,
125
+ "char_f1": 0.8553,
126
+ "span_p": 0.4852,
127
+ "span_r": 0.2985
128
+ },
129
+ "kiji/French": {
130
+ "n": 150,
131
+ "span_f1": 0.3823,
132
+ "char_f1": 0.8392,
133
+ "span_p": 0.4733,
134
+ "span_r": 0.3207
135
+ },
136
+ "kiji/German": {
137
+ "n": 150,
138
+ "span_f1": 0.4014,
139
+ "char_f1": 0.8808,
140
+ "span_p": 0.5358,
141
+ "span_r": 0.3209
142
+ },
143
+ "kiji/Spanish": {
144
+ "n": 150,
145
+ "span_f1": 0.4243,
146
+ "char_f1": 0.8261,
147
+ "span_p": 0.5255,
148
+ "span_r": 0.3558
149
+ },
150
+ "kiji/all": {
151
+ "n": 900,
152
+ "span_f1": 0.3864,
153
+ "char_f1": 0.8441,
154
+ "span_p": 0.511,
155
+ "span_r": 0.3106
156
+ },
157
+ "nemotron/English": {
158
+ "n": 1000,
159
+ "span_f1": 0.6211,
160
+ "char_f1": 0.8231,
161
+ "span_p": 0.6809,
162
+ "span_r": 0.5709
163
+ },
164
+ "nemotron/all": {
165
+ "n": 1000,
166
+ "span_f1": 0.6211,
167
+ "char_f1": 0.8231,
168
+ "span_p": 0.6809,
169
+ "span_r": 0.5709
170
+ },
171
+ "mean": {
172
+ "char_f1": 0.8099,
173
+ "span_f1": 0.5302
174
+ }
175
+ }
code/results/test_pipeline_clinical.json ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "note": "pipeline('token-classification', aggregation_strategy='simple', stride=128), arg-max, on two clinical test sets outside the model's training domain: GraSCCo test (41 German letters) and MDeID test (synthetic clinical notes, 7 languages). Character precision, recall and F1 (personal or not), and the share of documents with a leak (a name, ID, phone or fax number, e-mail address or street less than half redacted), pooled per set. Scored with the research benchmark code, not evaluate.py.",
3
+ "sets": {
4
+ "grascco_test": {
5
+ "all": {
6
+ "n_docs": 41,
7
+ "char_p": 0.93,
8
+ "char_r": 0.713,
9
+ "char_f1": 0.8072,
10
+ "doc_leak_rate": 0.7317
11
+ },
12
+ "de": {
13
+ "n_docs": 41,
14
+ "char_p": 0.93,
15
+ "char_r": 0.713,
16
+ "char_f1": 0.8072,
17
+ "doc_leak_rate": 0.7317
18
+ }
19
+ },
20
+ "mdeid_test": {
21
+ "all": {
22
+ "n_docs": 2856,
23
+ "char_p": 0.9434,
24
+ "char_r": 0.7254,
25
+ "char_f1": 0.8202,
26
+ "doc_leak_rate": 0.7731
27
+ },
28
+ "de": {
29
+ "n_docs": 402,
30
+ "char_p": 0.9437,
31
+ "char_r": 0.7316,
32
+ "char_f1": 0.8242,
33
+ "doc_leak_rate": 0.7886
34
+ },
35
+ "en": {
36
+ "n_docs": 416,
37
+ "char_p": 0.942,
38
+ "char_r": 0.6785,
39
+ "char_f1": 0.7888,
40
+ "doc_leak_rate": 0.7572
41
+ },
42
+ "es": {
43
+ "n_docs": 408,
44
+ "char_p": 0.9485,
45
+ "char_r": 0.7542,
46
+ "char_f1": 0.8402,
47
+ "doc_leak_rate": 0.7402
48
+ },
49
+ "fr": {
50
+ "n_docs": 410,
51
+ "char_p": 0.9446,
52
+ "char_r": 0.7658,
53
+ "char_f1": 0.8459,
54
+ "doc_leak_rate": 0.7195
55
+ },
56
+ "it": {
57
+ "n_docs": 404,
58
+ "char_p": 0.9406,
59
+ "char_r": 0.75,
60
+ "char_f1": 0.8346,
61
+ "doc_leak_rate": 0.7525
62
+ },
63
+ "nl": {
64
+ "n_docs": 405,
65
+ "char_p": 0.9473,
66
+ "char_r": 0.671,
67
+ "char_f1": 0.7856,
68
+ "doc_leak_rate": 0.8642
69
+ },
70
+ "pt": {
71
+ "n_docs": 411,
72
+ "char_p": 0.9371,
73
+ "char_r": 0.7224,
74
+ "char_f1": 0.8158,
75
+ "doc_leak_rate": 0.7908
76
+ }
77
+ }
78
+ }
79
+ }
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:004913577e27266d445da2483e62676b7d9fa75782d21a3f89bd479d601fb21f
3
+ size 563111606
onnx/model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4052b059ac4967376ad1e4034e88c7a4f35b1a7c422c7d04cb3ae92a1c24e2b6
3
+ size 268183397
onnx/quantization_check.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "what": "Agreement of each ONNX file with the PyTorch model on 242 development texts (220 synthetic letters in 22 languages, 22 GraSCCo development letters), first 512 tokens each.",
3
+ "token_agreement": "share of tokens with the same most likely label",
4
+ "rule": "the smallest int8 file with token_agreement >= 0.998 ships as model_quantized.onnx",
5
+ "files": {
6
+ "onnx/model.onnx": {
7
+ "token_agreement": 1.0,
8
+ "ms_per_text": 294.4499,
9
+ "mb": 563.11161
10
+ },
11
+ "onnx/model_quantized.onnx (int8 embeddings, other weights fp32)": {
12
+ "token_agreement": 0.99926,
13
+ "ms_per_text": 279.47659,
14
+ "mb": 268.1834
15
+ }
16
+ },
17
+ "int8_variants_not_shipped": {
18
+ "int8 MatMul + embeddings": {
19
+ "token_agreement": 0.9759,
20
+ "ms_per_text": 221.65454,
21
+ "mb": 142.23502
22
+ },
23
+ "int8 MatMul only (the int8 file of v1.0 to v1.0.2)": {
24
+ "token_agreement": 0.97614,
25
+ "ms_per_text": 218.09945,
26
+ "mb": 437.14657
27
+ },
28
+ "int8 MatMul + embeddings, full 8-bit range": {
29
+ "token_agreement": 1e-05,
30
+ "ms_per_text": 159.89959,
31
+ "mb": 142.23502
32
+ },
33
+ "int8 full 8-bit range, feed-forward output layers kept fp32": {
34
+ "token_agreement": 0.98132,
35
+ "ms_per_text": 204.97135,
36
+ "mb": 171.36481
37
+ },
38
+ "int8 full 8-bit range, last two layers kept fp32": {
39
+ "token_agreement": 1e-05,
40
+ "ms_per_text": 638.9034,
41
+ "mb": 153.68482
42
+ }
43
+ }
44
+ }
pareto_size.png CHANGED

Git LFS Details

  • SHA256: 26dc86c4f227891bb96026ed8c58df136b043bc227c3e2320b3e318255e8da85
  • Pointer size: 131 Bytes
  • Size of remote file: 115 kB

Git LFS Details

  • SHA256: 987a2042de7ecf39b91b959016326aedd5d91d95298dbaa4f68f17307cb99caa
  • Pointer size: 131 Bytes
  • Size of remote file: 127 kB
pareto_size.svg CHANGED
pareto_speed.png CHANGED

Git LFS Details

  • SHA256: 38bd2ede5b3b27112ff21d15eb43b2189b0cb10d56b41871a9729013d1e07fca
  • Pointer size: 131 Bytes
  • Size of remote file: 126 kB

Git LFS Details

  • SHA256: e5d74a2690fde2016414f7473e262e07bf46fe1e690e5ab4182874f7585454ab
  • Pointer size: 131 Bytes
  • Size of remote file: 137 kB
pareto_speed.svg CHANGED
rules/README.md CHANGED
@@ -1 +1 @@
1
- The rules I wrote before training (gate), before the single test opening, and before the second privacy-filter row, plus the label mapping, in German as written.
 
1
+ The rules I wrote before training (gate), before the single test opening, and before the second privacy-filter row, plus the label mapping, in German as written. For v1.0.3: the rules for choosing the ONNX files on development texts (`form_onnx*`), for the one test run of the new int8 file (`form_messung`), and for the PIIMB run (`piimb`).
rules/form_messung_20261122.md ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Regel: Messung der neuen ONNX-Dateien und des pipeline-Wegs (22.11.2026, vor der Messung)
2
+
3
+ Anlass: Auftrag Lukas 22.11. spät. Die Karten zeigen künftig als Hauptweg die normale
4
+ `pipeline("token-classification", aggregation_strategy="simple", stride=128)` und messen genau diesen Weg. Dazu kommen die neuen Dateien
5
+ `onnx/model.onnx` und `onnx/model_quantized.onnx` (Auswahl nach `regeln/form_onnx_20261122.md`, nur auf dev).
6
+
7
+ Testsätze (alle schon geöffnet, für dieselben Modelle): GraSCCo-Test (41 Briefe, `bench/split.py`, geöffnet 20.11. für v1.0 und base v1.0)
8
+ und MDeID-Test 7 Sprachen (de geöffnet 20.11., die anderen 6 in Linie 7 Stufe 1 am 22.11., Regel 43578d4). Diese Öffnung dient nur der
9
+ Karte; an Modellen, Schwellen und Dateiauswahl ändert sich danach nichts.
10
+
11
+ Zeilen (GRUPPE=form in `fabrik/mehrsprachig/grund_job.py`, Maße `bench/core.py`: Zeichen-P/R/F1, Leckrate, je Sprache und gepoolt):
12
+ - je Modell (german-clinical-deid-base, german-clinical-deid, pii-filter-small): pipeline-Weg wie oben, ohne Schwelle (Argmax);
13
+ - je deid-Modell: Paket mit `onnx/model.onnx` und mit dem gewählten `onnx/model_quantized.onnx` (Schwelle aus config, wie ausgeliefert).
14
+
15
+ Die Karte zeigt alle Zeilen, auch wenn der pipeline-Weg schlechter ist als das Paket. Weicht eine ausgelieferte ONNX-Datei auf einem Satz
16
+ im Leck um mehr als 1 Punkt von der bisher berichteten Zahl ab, nennt die Karte die Zahl der Datei.
17
+ pii-filter-small: Die Zahlen auf seinen eigenen Testsätzen (Nemotron-PII, Gretel, Kiji, ai4privacy) für die neue int8-Datei kommen mit
18
+ dessen eigenem `evaluate.py`; dafür gilt dieselbe Regel sinngemäß.
rules/form_onnx2_20261122.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Regel: weitere int8-Varianten, wenn die erste Runde keine Datei liefert (22.11.2026, 22:00 UTC, vor der Messung)
2
+
3
+ Erste Runde (`regeln/form_onnx_20261122.md`, 8e9ef58): german-clinical-deid-base hat keine Variante mit token_agreement ≥ 0,998
4
+ (B nur Gather 0,99798, A 0,9912, C 0,9915). Nach dieser Regel bekommt base darum vorerst kein `model_quantized.onnx`.
5
+ Zweite Runde, nur auf denselben dev-Texten, gleiche Schwellen (token_agreement ≥ 0,998 und redact_agreement_t001 ≥ 0,995),
6
+ gleiche Auswahl (kleinste Datei, die beides hält). Neue Varianten, alle mit Gather int8, Klassifikationskopf fp32, per_channel:
7
+ - D: MatMul int8 ohne reduce_range (volle 8 Bit statt 7).
8
+ - E: wie D, aber die zweite Linear-Schicht jedes Feed-Forward-Blocks (`output/dense`, `mlp/Wo`) bleibt fp32.
9
+ - F: wie D, aber die Schichten der letzten zwei Encoder-Blöcke bleiben fp32.
10
+ Gilt für jedes Modell ohne Datei aus Runde 1 und für jedes, bei dem eine Variante kleiner als die Runde-1-Wahl hält.
11
+ Hält keine Variante: kein `model_quantized.onnx`; die Karte sagt warum, und die Demo nutzt `model.onnx`.
rules/form_onnx_20261122.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Regel: ONNX-Dateien in Horizon-Form für die drei vorhandenen Modelle (22.11.2026, vor jeder Messung)
2
+
3
+ Anlass: Auftrag Lukas 22.11. spät, Punkt 1 (Form der Repos). transformers.js sucht ohne Zusatz `onnx/model.onnx` (fp32) und
4
+ `onnx/model_quantized.onnx` (int8). Unser int8 von pii-filter-small hat 437 MB, weil die Embeddings fp32 bleiben.
5
+
6
+ Modelle (genau die ausgelieferten Gewichte vom Hub): german-clinical-deid, german-clinical-deid-base, pii-filter-small.
7
+ Prüftexte (nur dev, nie Test): Linie-5 gold_dev, je Sprache die ersten 10 Briefe (220), und GraSCCo dev (22), je auf 512 Tokens gekürzt.
8
+
9
+ Varianten für int8 (Kopf immer fp32, per_channel, reduce_range, wie bisher):
10
+ - A: MatMul und Gather (Embeddings) int8.
11
+ - B: nur Gather int8, MatMul fp32.
12
+ - C: nur MatMul int8 (bisheriges Rezept).
13
+
14
+ Maße je Datei gegen PyTorch fp32 auf denselben Texten: Anteil Tokens mit gleichem Argmax-Label (`token_agreement`), Anteil Tokens mit
15
+ gleicher Entscheidung "nicht-O-Wahrscheinlichkeit ≥ 0,01" (`redact_agreement_t001`, die Schwelle der beiden deid-Modelle), Größe in MB, ms je Text.
16
+
17
+ Auswahl `model_quantized.onnx`: die kleinste Variante mit token_agreement ≥ 0,998 und redact_agreement_t001 ≥ 0,995 (bei pii-filter-small
18
+ zählt nur token_agreement, es nutzt Argmax). Erfüllt keine Variante beides: kein `model_quantized.onnx`, die Karte sagt warum.
19
+ `model.onnx` (fp32) muss token_agreement ≥ 0,9999 haben, sonst wird nichts davon ausgeliefert. Alle Varianten stehen in
20
+ `onnx/quantization_check.json`. Die alten Dateien (model_fp16.onnx, model_int8.onnx) fallen weg; Testzahlen der Karten bleiben die der
21
+ damals gemessenen Dateien, bis eine neue Datei auf Test gemessen ist (die Karte sagt, welche Datei gemessen wurde).
rules/piimb_20261122.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Regel: PIIMB-Messung für pii-filter-small (22.11.2026, vor der Messung)
2
+
3
+ PIIMB (piimb/pii-masking-benchmark, CC BY-NC 4.0, nur Test) misst Maskierung auf Zeichenebene ohne Labels, Rangliste nach Avg F2.
4
+ Gemessen wird genau die ausgelieferte Datei von LukasKunhardt/pii-filter-small (Hub, main) mit dem offiziellen Befehl
5
+ `piimb evaluate --model-id LukasKunhardt/pii-filter-small` in den Voreinstellungen (Teilmenge sentences, alle Aufgaben, Pipeline
6
+ token-classification, aggregation simple). Keine eigene Schwelle, kein zweiter Lauf mit anderen Einstellungen.
7
+ Das Ergebnis kommt unverändert in RESULTS.md und die Karte (alle sechs Aufgaben, auch schwache), und es wird bei PIIMB eingereicht,
8
+ egal welcher Platz. Die beiden deid-Modelle messe ich hier nicht: Sie sind für deutsche klinische Texte gebaut, PIIMB ist allgemeine PII
9
+ vor allem auf Englisch; ihre Karten sagen das. Eine spätere Messung von ihnen bekäme eine eigene Regel.
10
+ Diese Messung ändert nichts an pii-filter-small (kein Training, keine Auswahl danach).