ArkadiuszPawlak commited on
Commit
34e0fa6
·
verified ·
1 Parent(s): 0cfd7c8

Add model card

Browse files
Files changed (1) hide show
  1. README.md +105 -0
README.md ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: pl
3
+ license: cc-by-4.0
4
+ tags:
5
+ - token-classification
6
+ - ner
7
+ - pii
8
+ - polish
9
+ - onnx
10
+ - bert
11
+ base_model: pczarnik/herbert-base-ner
12
+ datasets:
13
+ - clarin-pl/kpwr-ner
14
+ ---
15
+
16
+ # HerBERT NER — Polish PII (ONNX)
17
+
18
+ Fine-tuned [`pczarnik/herbert-base-ner`](https://huggingface.co/pczarnik/herbert-base-ner)
19
+ for detecting personal data (PII) in Polish text.
20
+
21
+ Detects: **PERSON**, **ADDRESS** (including full address with city, e.g. *ul. Lipowej 7 w Krakowie*).
22
+
23
+ Intended use: Polish web forms — browser-side inference via
24
+ [`@xenova/transformers`](https://github.com/xenova/transformers.js) + ONNX Runtime Web (WASM),
25
+ no backend required.
26
+
27
+ ## Training data
28
+
29
+ 4 813 training samples (train/dev/test split):
30
+
31
+ - **KPWr filtered** (3 113 samples) — [clarin-pl/kpwr-ner](https://huggingface.co/datasets/clarin-pl/kpwr-ner)
32
+ Polish press corpus; LOC-only (geographic) and schematic form-label samples removed.
33
+ - **LLM-synthetic** (1 700 train samples) — generated with GPT-4o-mini and claude-haiku-4-5,
34
+ covering ADDRESS with city suffix (*w Mieście*), PERSON in email context, and mixed cases.
35
+
36
+ Fine-tuned for 8 epochs with early stopping (patience=3), best checkpoint selected by **eval F1**
37
+ (seqeval, micro-averaged over B-PER/I-PER/B-LOC/I-LOC).
38
+
39
+ ## Evaluation (`kpwr_final_test.json`, 615 samples, character-level IoU >= 0.5)
40
+
41
+ | Label | F1 | Prec | Recall | TP | FP | FN |
42
+ |---------|------:|------:|-------:|-----:|-----:|-----:|
43
+ | PERSON | 0.922 | 0.885 | 0.962 | 425 | 55 | 17 |
44
+ | ADDRESS | 0.944 | 0.903 | 0.990 | 102 | 11 | 1 |
45
+
46
+ ADDRESS recall 0.990 — the model captures full addresses including city names.
47
+
48
+ ## Label mapping
49
+
50
+ The model outputs 5 BIO classes:
51
+
52
+ | Model label | Meaning for this use case |
53
+ |-------------|--------------------------|
54
+ | `B-PER` / `I-PER` | PERSON |
55
+ | `B-LOC` / `I-LOC` | ADDRESS |
56
+ | `O` | not PII |
57
+
58
+ ## Files
59
+
60
+ | File | Format | Notes |
61
+ |------|--------|-------|
62
+ | `model.onnx` | FP32 | highest quality |
63
+ | `model_quantized.onnx` | INT8 | **recommended for browser** |
64
+ | `onnx/model_quantized.onnx` | INT8 | alias for Transformers.js `dtype:"q8"` |
65
+ | `config.json` | JSON | label mapping, model config |
66
+ | `tokenizer.json` | JSON | HerBERT tokenizer |
67
+
68
+ ## Usage
69
+
70
+ ### Python (Transformers)
71
+
72
+ ```python
73
+ from transformers import pipeline
74
+
75
+ ner = pipeline(
76
+ "token-classification",
77
+ model="ArkadiuszPawlak/pczarnik-herbert-ner-polish-pii",
78
+ aggregation_strategy="simple",
79
+ )
80
+ result = ner("Jan Kowalski mieszka przy ul. Marszałkowskiej 1, 00-001 Warszawa.")
81
+ # [{"entity_group": "PER", "word": "Jan Kowalski", ...},
82
+ # {"entity_group": "LOC", "word": "ul. Marszałkowskiej 1, 00-001 Warszawa", ...}]
83
+ ```
84
+
85
+ ### Browser (@xenova/transformers + ONNX Runtime Web)
86
+
87
+ ```js
88
+ import { pipeline } from "@xenova/transformers";
89
+
90
+ const ner = await pipeline(
91
+ "token-classification",
92
+ "ArkadiuszPawlak/pczarnik-herbert-ner-polish-pii",
93
+ { aggregation_strategy: "simple" }
94
+ );
95
+
96
+ const LABEL_MAP = { PER: "PERSON", LOC: "ADDRESS" };
97
+
98
+ const raw = await ner("Jan Kowalski mieszka przy ul. Marszałkowskiej 1 w Krakowie.");
99
+ const entities = raw
100
+ .filter(e => e.entity_group in LABEL_MAP)
101
+ .map(e => ({ label: LABEL_MAP[e.entity_group], text: e.word, score: e.score }));
102
+ console.log(entities);
103
+ // [{ label: "PERSON", text: "Jan Kowalski", score: 0.99 },
104
+ // { label: "ADDRESS", text: "ul. Marszałkowskiej 1 w Krakowie", score: 0.97 }]
105
+ ```