vadimbelsky commited on
Commit
c08a1e1
·
verified ·
1 Parent(s): 04b8e40

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +86 -105
  2. onnx/model_quantized.onnx +1 -1
  3. tokenizer.json +1 -1
README.md CHANGED
@@ -1,126 +1,107 @@
1
  ---
2
- license: other
3
- license_name: proprietary-sciencesoft
4
- base_model: FacebookAI/xlm-roberta-base
5
  language: [en, de, fr, it, es, ru, ar]
6
  pipeline_tag: token-classification
7
- tags: [pii, dlp, ner, privacy, multilingual, arabic]
8
- library_name: transformers
 
9
  ---
10
 
11
- # ScienceSoft PII Encoder
12
 
13
- Multilingual token classification for the personal data that **regex cannot
14
- find**. Built for the ai-firewall endpoint agent, which inspects outbound
15
- AI-assistant traffic and redacts personal data before it leaves the machine.
16
 
17
- ## What it detects, and what it deliberately does not
 
18
 
19
- Five semantic entities:
 
 
20
 
21
- | label | why an encoder |
22
- |---|---|
23
- | `PERSON` | no format; transliteration and dialect spelling |
24
- | `ORGANIZATION` | no format |
25
- | `LOCATION` | place names |
26
- | `ADDRESS` | free-form street addresses |
27
- | `DATE_TIME` | dates written as prose |
28
 
29
- It does **not** detect emails, phone numbers, card numbers, IBANs, SSNs,
30
- passports or tax IDs. Those have a format and usually a checksum, so a regex
31
- decides them deterministically, in every language, at no inference cost. An
32
- encoder adds only a second, weaker opinion there.
33
 
34
- This mirrors Presidio's division of labour: `IBAN_CODE` is "pattern match,
35
- context **and checksum**"; `PERSON` and `LOCATION` come from the NLP engine.
 
 
 
36
 
37
- ## Languages
38
 
39
- English, German, French, Italian, Spanish, Russian, Arabic — the last including
40
- Modern Standard, Gulf, Levantine, Egyptian, and **Arabizi** (Arabic in Latin
41
- script with digits: `3arabi`, `7abibi`).
42
 
43
- ## Results
 
 
 
 
 
 
 
 
 
44
 
45
- Two sets, kept apart on purpose.
 
 
46
 
47
- ### Held-out synthetic (int8 artifact, all five labels)
48
 
49
- | | F1 | | | F1 |
50
- |---|---|---|---|---|
51
- | en | 0.958 | | ar-arabizi | 0.889 |
52
- | es | 0.952 | | ar-msa | 0.777 |
53
- | ru | 0.947 | | ar-gulf | 0.769 |
54
- | de | 0.940 | | ar-levantine | 0.751 |
55
- | it | 0.930 | | ar-egyptian | 0.741 |
56
- | fr | 0.929 | | | |
57
 
58
- Evaluated on sentence frames the model never saw in training, with zero
59
- train/eval sentence overlap.
60
 
61
- ### Real text — WikiANN, PERSON
 
 
 
62
 
63
- Wikipedia prose the model never trained on, against the model this replaces
64
- (`onnx-community/multilang-pii-ner-ONNX`):
 
 
65
 
66
- | | ours | incumbent |
67
- |---|---|---|
68
- | it | 0.865 | 0.229 |
69
- | de | 0.814 | 0.252 |
70
- | fr | 0.744 | 0.191 |
71
- | en | 0.733 | 0.182 |
72
- | es | 0.699 | 0.129 |
73
- | ar | 0.585 | 0.016 |
74
- | ru | 0.229 | 0.076 |
75
-
76
- ### Name-origin fairness
77
-
78
- Whole-name recall, identical English frames, name origin varied:
79
-
80
- anglo · arabic · slavic · south asian · east asian · african · hispanic —
81
- **1.0000 each, pairwise delta 0.0000.**
82
-
83
- ## Limitations — read these before quoting a number
84
-
85
- - **Trained on synthetic data only.** Real-text F1 across all five labels runs
86
- **0.20–0.48**, against 0.86 on the held-out synthetic set. The model has
87
- learned our sentence frames better than it has learned general prose. Some of
88
- the gap is genuine and some is WikiANN using different label conventions, but
89
- not all of it is conventions.
90
- - **Two synthetic scores are artifacts, not capability.** `DATE_TIME` 1.0000 and
91
- `ADDRESS` 0.997 measure a generator that produces formulaic dates
92
- (`12 March 1989`) and one address shape. Real prose contains neither. Do not
93
- quote them.
94
- - **Russian is the weak language.** 0.947 synthetic against 0.229 real-text
95
- PERSON — consistent across both real-text checks, so it is a property of the
96
- model, not of one benchmark.
97
- - **Arabic script sits ~0.15 below Latin and Cyrillic.** Arabizi is the
98
- strongest Arabic register, most likely because it is Latin script the base
99
- model handles natively.
100
- - **Name-origin fairness is measured on in-domain frames**, close to the
101
- training distribution. It does not establish fairness on arbitrary prose.
102
- - Not a compliance guarantee. One layer of a DLP system, not the system.
103
-
104
- ## Artifact
105
-
106
- `onnx/model_quantized.onnx` — 278 MB, int8 dynamic, opset 17, IR 8.
107
- Runs on ONNX Runtime ≥ 1.24. CPU latency, 4 threads: **28 ms @128 tokens,
108
- 166 ms @512**.
109
-
110
- Quantization is not a loss here — int8 scores **above** fp32 (0.8704 vs 0.8492).
111
-
112
- ## Training
113
-
114
- XLM-RoBERTa-base fine-tuned for token classification, 3 epochs, 280k generated
115
- examples across seven languages and five Arabic registers, 30% label-preserving
116
- augmentation.
117
-
118
- Training data is generated by ScienceSoft's own generators — no third-party
119
- corpus is used, so the model carries no upstream corpus licence. WikiANN is used
120
- for **evaluation only** and never for training.
121
-
122
- ## Licence and attribution
123
-
124
- Proprietary to ScienceSoft. Derived from
125
- [`FacebookAI/xlm-roberta-base`](https://huggingface.co/FacebookAI/xlm-roberta-base)
126
- (MIT), whose licence and copyright notice are retained.
 
1
  ---
2
+ license: apache-2.0
 
 
3
  language: [en, de, fr, it, es, ru, ar]
4
  pipeline_tag: token-classification
5
+ tags: [pii, ner, privacy, dlp, onnx, xlm-roberta]
6
+ library_name: onnxruntime
7
+ base_model: FacebookAI/xlm-roberta-base
8
  ---
9
 
10
+ # ScienceSoft PII encoder
11
 
12
+ Multilingual NER for the personal data **regex cannot find** — names,
13
+ organisations, locations, addresses and date expressions — in seven languages
14
+ plus four Arabic registers and Arabizi.
15
 
16
+ It is the NER half of a data-loss-prevention agent that inspects outbound
17
+ AI-assistant traffic on a device and redacts personal data before it leaves.
18
 
19
+ `xlm-roberta-base`, fine-tuned on a fully synthetic corpus
20
+ (`vadimbelsky/scnsoft-pii-synthetic-corpus`), exported to ONNX and int8
21
+ quantized. **278 MB**, CPU inference.
22
 
23
+ ## Labels
 
 
 
 
 
 
24
 
25
+ `PERSON` `ORGANIZATION` `LOCATION` `ADDRESS` `DATE_TIME` (BIO, 11 classes)
 
 
 
26
 
27
+ **Email, phone, card, IBAN and passport numbers are deliberately absent.** Those
28
+ have a shape and usually a checksum, so a regex decides them exactly and a
29
+ classifier only produces a second, weaker opinion that then competes with the
30
+ layer that was right. This model is built to leave them alone — and measurably
31
+ does (see `touch_rate` below).
32
 
33
+ ## Verified results
34
 
35
+ Gate run 2026-08-30. Every figure measured, none estimated.
 
 
36
 
37
+ | | this model | model it replaces |
38
+ |---|---|---|
39
+ | **regex-owned identifiers wrongly touched** (real ru text) | **0.1%** (1/770) | 53.6% (413/770) |
40
+ | **known-defect suite** | **18/18** | 7/18 |
41
+ | hivetrace ru PII — F1 / P / R | 0.5888 / 0.4375 / **0.9000** | 0.2754 / 0.1610 / 0.9500 |
42
+ | Wojood ar NER — F1 | 0.4888 | 0.4136 |
43
+ | int8 F1 (held-out synthetic) | 0.8906 | 0.8704 |
44
+ | int8 vs fp32 F1 cost | 0.0081 | — |
45
+ | latency p95 @512 tok (CPU, 4 thread) | 190.9 ms | 190.8 ms |
46
+ | name-origin bias delta | 0.0312 | not validly measured |
47
 
48
+ Head-to-head vs the previously shipped multilingual PII model, ours ahead in
49
+ every language: it +0.58 · es +0.55 · fr +0.52 · en +0.52 · de +0.48 ·
50
+ ar +0.45 · **ru +0.07**.
51
 
52
+ ## Read this before using it
53
 
54
+ **Recall was traded for precision.** Recall on real Russian PII fell 0.95 → 0.90
55
+ while precision rose 0.16 → 0.44. False positives dropped roughly 500×, which is
56
+ the right trade for a tool that rewrites user text — but if your application
57
+ prefers over-flagging to under-flagging, the model it replaces had higher recall.
 
 
 
 
58
 
59
+ **Russian is the weak language.** +0.07 head-to-head where every other language
60
+ is +0.45 or better, and hivetrace F1 0.59 is the lowest real-text score we have.
61
 
62
+ **Organisation boundaries are imperfect.** On
63
+ `вадим бельский из клиники «Здоровье»` it returns `клиники` (the common noun
64
+ "clinic") rather than the quoted name `«Здоровье»`. It finds an organisation is
65
+ present; it does not always choose the right span.
66
 
67
+ **Trained only on synthetic data.** Entity pools are finite, so scores on
68
+ generated text overstate real-world ability — the same model scores 0.95 on
69
+ held-out synthetic and 0.59 on real Russian. Judge it on the external
70
+ benchmarks above, not the synthetic figure.
71
 
72
+ **Arabizi is a reconstruction.** No corpus contains it; its conventions
73
+ (3=ain, 7=haa, 2=hamza) are our model of how people type, not observed data.
74
+
75
+ ## Use
76
+
77
+ Three files: `config.json`, `tokenizer.json`, `onnx/model_quantized.onnx`.
78
+
79
+ ```python
80
+ import json, onnxruntime as ort
81
+ from transformers import AutoTokenizer
82
+
83
+ tok = AutoTokenizer.from_pretrained("ScienceSoft/scnsoft-pii-encoder")
84
+ cfg = json.load(open("config.json"))
85
+ id2label = {int(k): v for k, v in cfg["id2label"].items()}
86
+ sess = ort.InferenceSession("onnx/model_quantized.onnx",
87
+ providers=["CPUExecutionProvider"])
88
+
89
+ enc = tok(text, return_offsets_mapping=True, return_tensors="np",
90
+ truncation=True, max_length=256)
91
+ offsets = enc.pop("offset_mapping")[0]
92
+ logits = sess.run(None, {i.name: enc[i.name] for i in sess.get_inputs()})[0]
93
+ # argmax -> id2label -> merge BIO spans using `offsets` for character positions
94
+ ```
95
+
96
+ Pair it with a regex/checksum layer for the structured identifiers it
97
+ deliberately ignores.
98
+
99
+ ## Training data
100
+
101
+ `vadimbelsky/scnsoft-pii-synthetic-corpus` — 486,947 rows, fully synthetic, no
102
+ real person's data. Roughly 13% of rows contain no entity at all; those
103
+ entity-free negatives are what took `touch_rate` from 53.6% to 0.1%.
104
+
105
+ ## Licence
106
+
107
+ Apache-2.0.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
onnx/model_quantized.onnx CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f85667b45f226b5c10c3debb07d3edf2b342c6891bea0db3c5540a97c6fa3e91
3
  size 278234412
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc5329911105c3d4a0cb95c0c18823c6e2575866b085633decc51523327a2f3b
3
  size 278234412
tokenizer.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:94b6f66edb763a1de9ee0edb887c3c33d2522e18a9fad2199600e485832af325
3
  size 17082987
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a514807cffabd8abaf028cfaffe7ff0c4f60b97ea2db80c41f14172ae6b018ca
3
  size 17082987