admin-promptshield commited on
Commit
b8a41f7
·
verified ·
1 Parent(s): b7afe2f

Model card: provenance, verification, Latin-script scope

Browse files
Files changed (1) hide show
  1. README.md +140 -0
README.md ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: afl-3.0
3
+ base_model: Davlan/bert-base-multilingual-cased-ner-hrl
4
+ base_model_relation: quantized
5
+ library_name: transformers.js
6
+ pipeline_tag: token-classification
7
+ tags:
8
+ - token-classification
9
+ - named-entity-recognition
10
+ - ner
11
+ - onnx
12
+ - transformers.js
13
+ - multilingual
14
+ - on-device
15
+ language:
16
+ - de
17
+ - en
18
+ - es
19
+ - fr
20
+ - it
21
+ - lv
22
+ - nl
23
+ - pt
24
+ ---
25
+
26
+ # bert-base-multilingual-cased-ner-hrl-latin
27
+
28
+ `Davlan/bert-base-multilingual-cased-ner-hrl`, quantized to int8 and stripped of
29
+ the vocabulary a Latin-script deployment can never tokenize.
30
+
31
+ **178.5 MB → 139.6 MB (−21.8%), with provably identical output** for the
32
+ languages it still covers. No encoder weight was touched. This is a packaging
33
+ change, not a distillation — there is no accuracy trade to evaluate.
34
+
35
+ ## Why it works
36
+
37
+ `bert-base-multilingual-cased` carries a 119,547-token vocabulary spanning 104
38
+ languages. At 768 dimensions that embedding table is **~92 MB of the 178 MB
39
+ file — more than half the model**, and every user downloads all of it. If you
40
+ ship Latin-script languages, the Cyrillic, CJK, Arabic, Hangul, Hebrew,
41
+ Devanagari, Greek, Armenian and Thai rows are downloaded by everyone and
42
+ gathered by no one.
43
+
44
+ Removing them is exact rather than approximate, for two reasons:
45
+
46
+ - The embedding is **per-tensor quantized** — a scalar scale and zero-point
47
+ shared by the whole tensor — and is read by a plain `Gather`. Selecting a
48
+ subset of rows preserves both the int8 values and their dequantization. No
49
+ weight is re-quantized and nothing drifts.
50
+ - **WordPiece is longest-match over the available pieces.** Only pieces
51
+ unreachable from a kept script were removed, so segmentation of Latin text is
52
+ unchanged too.
53
+
54
+ Vocabulary: **119,547 → 68,875 tokens** (57.6% kept).
55
+
56
+ ## Verification
57
+
58
+ Not asserted — measured. Both models were run over 77 real documents (contracts,
59
+ financial statements, medical records) in 7 languages, comparing **raw logits**
60
+ rather than entity lists, because entity lists can agree by luck:
61
+
62
+ | | |
63
+ | --- | --- |
64
+ | documents | 77 |
65
+ | entities compared | 2,219 |
66
+ | segmentation differences | **0** |
67
+ | entity differences | **0** |
68
+ | max abs. logit delta | **0.0000000000** |
69
+
70
+ The comparison is over raw logits and fails on any nonzero difference. **Verify
71
+ on your own corpus before shipping** — the guarantee is exact for kept scripts,
72
+ but "kept" depends on which scripts you selected, and a corpus containing a
73
+ dropped script will (correctly) diverge.
74
+
75
+ ## ⚠️ Latin script only
76
+
77
+ Text in a dropped script is **not supported** — it degrades to `[UNK]`, not to
78
+ "slightly worse". Relative to the original model:
79
+
80
+ - **Kept:** German, English, Spanish, French, Italian, Latvian, Dutch,
81
+ Portuguese — and any other Latin-script language the base model handled.
82
+ - **Removed:** **Arabic and Chinese**, which the original supports and this
83
+ model does not.
84
+
85
+ If you need those, use
86
+ [`Xenova/bert-base-multilingual-cased-ner-hrl`](https://huggingface.co/Xenova/bert-base-multilingual-cased-ner-hrl)
87
+ — it is the model this one is built from, unchanged apart from the vocabulary.
88
+
89
+ The same technique keeps whichever scripts you do ship: retaining kana and
90
+ ideographs alongside Latin lands at ~151 MB, still 27 MB under the original.
91
+
92
+ ## Labels
93
+
94
+ `PER`, `ORG`, `LOC`, `DATE` — unchanged from the base model, as `B-`/`I-` tags.
95
+
96
+ ## Usage (transformers.js)
97
+
98
+ ```js
99
+ import { pipeline } from "@huggingface/transformers";
100
+
101
+ const ner = await pipeline(
102
+ "token-classification",
103
+ "promptshield/bert-base-multilingual-cased-ner-hrl-latin",
104
+ { dtype: "q8" },
105
+ );
106
+
107
+ await ner("Le contrat a été signé par Jean-Baptiste Lefèvre à Bordeaux.", {
108
+ aggregation_strategy: "simple",
109
+ });
110
+ ```
111
+
112
+ It also loads in `onnxruntime` directly — it is a standard BERT token-classification
113
+ graph with `input_ids`, `attention_mask` and `token_type_ids`.
114
+
115
+ ## Provenance and licence
116
+
117
+ | | |
118
+ | --- | --- |
119
+ | base | [`google-bert/bert-base-multilingual-cased`](https://huggingface.co/google-bert/bert-base-multilingual-cased) — Apache-2.0 |
120
+ | fine-tune | [`Davlan/bert-base-multilingual-cased-ner-hrl`](https://huggingface.co/Davlan/bert-base-multilingual-cased-ner-hrl) — **AFL-3.0** |
121
+ | ONNX export | [`Xenova/bert-base-multilingual-cased-ner-hrl`](https://huggingface.co/Xenova/bert-base-multilingual-cased-ner-hrl) |
122
+ | this repo | vocabulary pruning only — **AFL-3.0**, inherited |
123
+
124
+ All credit for the model itself belongs to **David Adelani (Davlan)** for the
125
+ fine-tune and to the Google Research team for the base model. We changed the
126
+ vocabulary and nothing else.
127
+
128
+ The upstream card declares no training datasets; if your use has data-provenance
129
+ requirements, check with the original authors rather than relying on this card.
130
+
131
+ ## Who made this and why
132
+
133
+ Built for [promptShield](https://promptshield.ca), an offline document
134
+ anonymizer. Its web app runs detection **entirely in the browser** — no document
135
+ ever leaves the device — so the model is a first-visit download, and 39 MB of
136
+ unreachable vocabulary was 39 MB charged to every visitor.
137
+
138
+ Published because the technique generalises: the embedding table is over half of
139
+ most multilingual encoders, and almost every deployment ships a fraction of the
140
+ 104 languages.