Instructions to use cenkierpiotr/anonPL-300M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- GLiNER
How to use cenkierpiotr/anonPL-300M with GLiNER:
from gliner import GLiNER model = GLiNER.from_pretrained("cenkierpiotr/anonPL-300M") text = "Cristiano Ronaldo dos Santos Aveiro was born on 5 February 1985 in Funchal, Madeira, Portugal." labels = ["person", "date", "location"] entities = model.predict_entities(text, labels) for entity in entities: print(entity["text"], "=>", entity["label"]) - Notebooks
- Google Colab
- Kaggle
anonPL-300M
π΅π± Polski | π¬π§ English
π΅π± Polski
Fine-tune modelu GLiNER (bazowy model: knowledgator/gliner-x-small, backbone google/mt5-small, ok. 300M parametrΓ³w), dotrenowany na syntetycznych polskich dokumentach prawniczych do wykrywania danych osobowych i identyfikatorΓ³w wymagajΔ
cych anonimizacji.
WAΕ»NE OSTRZEΕ»ENIE β to nie jest samodzielny system anonimizacji
Ten model jest przeznaczony wyΕΔ cznie jako dodatkowa warstwa wspomagajΔ ca recall (wykrywanie potencjalnie przeoczonych fragmentΓ³w), nigdy jako samodzielny, w peΕni automatyczny mechanizm anonimizacji.
W docelowej architekturze, dla ktΓ³rej model powstaΕ, autorytatywnym mechanizmem wykrywania i maskowania danych osobowych jest deterministyczny pipeline regex + walidacja sum kontrolnych (dla PESEL, NIP, REGON, IBAN itd.) oraz klasyczny model NER. Ten pipeline jest audytowalny i, na czystym tekΕcie, bezbΕΔdny dla identyfikatorΓ³w o sztywnej strukturze. anonPL-300M nigdy nie zastΔpuje tego mechanizmu i nigdy nie trafia bezpoΕrednio do finalnego, zanonimizowanego dokumentu β kaΕΌde wskazanie modelu, ktΓ³re nie pokrywa siΔ z juΕΌ istniejΔ
cΔ
, zatwierdzonΔ
detekcjΔ
, musi trafiΔ do kolejki "niepewne / potencjalnie przeoczone", wymagajΔ
cej rΔcznej weryfikacji przez czΕowieka przed jakΔ
kolwiek decyzjΔ
o usuniΔciu lub zamaskowaniu danych.
PowΓ³d tej decyzji architektonicznej: bΕΔ d faΕszywie ujemny (model nie wykryΕ danej osobowej, ktΓ³ra powinna byΔ zamaskowana) w tym zastosowaniu oznacza realny wyciek danych osobowych klienta kancelarii β nieakceptowalne ryzyko bez warstwy ludzkiej weryfikacji.
Opis modelu i zastosowanie
Model jest wersjΔ dostrojonΔ (fine-tune) architektury GLiNER, ktΓ³ra stanowi oparty na zakresach (span-based) enkoder do ekstrakcji nazwanych encji (NER) z moΕΌliwoΕciΔ dziaΕania w trybie zero-shot. ZostaΕ przeszkolony na syntetycznych polskich dokumentach prawniczych, takich jak pisma procesowe, umowy, akty notarialne oraz postanowienia sΔ dowe. GΕΓ³wnym zadaniem modelu jest wykrywanie danych osobowych oraz rΓ³ΕΌnego rodzaju identyfikatorΓ³w w dokumentacji przetwarzanej w kancelariach prawnych i instytucjach powiΔ zanych.
W przeciwieΕstwie do tradycyjnych modeli NER, ktΓ³re opierajΔ siΔ na sztywnych sΕownikach lub predefiniowanych listach, GLiNER analizuje tekst pod kΔ tem znaczenia i identyfikuje encje na podstawie opisΓ³w etykiet ("label description"), nie sztywnej listy sΕΓ³w. Takie podejΕcie pozwala na skuteczne wykrywanie danych nawet wtedy, gdy wystΔpujΔ one w nietypowych sformuΕowaniach, odmianach lub kontekstach gramatycznych, ktΓ³re nie pojawiΕy siΔ wprost w materiaΕach treningowych.
anonPL-300M to mniejszy i szybszy z dwΓ³ch opublikowanych wariantΓ³w rozmiaru (drugi to anonPL-494M) β przy niΕΌszej liczbie parametrΓ³w oferuje wyraΕΊnie szybszΔ
inferencjΔ i mniejsze zuΕΌycie pamiΔci, kosztem nieco niΕΌszej odpornoΕci na skrajnie zaszumiony tekst. W tej konkretnej ewaluacji rΓ³ΕΌnica jakoΕci miΔdzy wariantami jest niewielka (patrz sekcja "Wyniki ewaluacji") β anonPL-300M jest zwykle rozsΔ
dnym domyΕlnym wyborem, a anonPL-494M ma sens tam, gdzie priorytetem jest maksymalna odpornoΕΔ na bardzo zaszumione skany.
Taksonomia etykiet
Model rozpoznaje 13 kategorii encji, podzielonych na dwie grupy o rΓ³ΕΌnym uzasadnieniu:
Grupa A β encje wolnotekstowe (peΕna wartoΕΔ treningu)
Kategorie, ktΓ³re regex nie jest w stanie sensownie wykryΔ, bo nie majΔ sztywnego ksztaΕtu skΕadniowego β wymagajΔ zrozumienia kontekstu:
| Etykieta wewnΔtrzna | Opis (etykieta uΕΌyta w treningu/ewaluacji) |
|---|---|
legal_role_person |
osoba fizyczna (strona lub uczestnik postΔpowania) β imiΔ i nazwisko wraz z rolΔ procesowΔ |
institution |
instytucja lub sΔ d (np. "SΔ d Rejonowy w Poznaniu") |
address |
adres (ulica, numer, kod pocztowy, miasto) |
case_number |
sygnatura sprawy |
notarial_act |
numer aktu notarialnego |
usc_act |
numer aktu stanu cywilnego lub poΕwiadczenia dziedziczenia |
inheritance_registry |
numer wpisu w rejestrze spadkowym |
Grupa B β identyfikatory strukturalne (trening pod odpornoΕΔ na szum OCR)
Te kategorie majΔ w 100% deterministyczny, sztywny ksztaΕt (cyfry + suma kontrolna) β na czystym tekΕcie regex+checksum jest bezbΕΔdny i nie potrzebuje modelu. GLiNER ma tu sens wyΕΔ cznie jako "druga szansa": gdy dokument pochodzi ze skanu/OCR i cyfry identyfikatora sΔ zaszumione (bΕΔdne rozpoznanie znaku), walidacja sumy kontrolnej zawodzi mimo ΕΌe dana faktycznie jest obecna w dokumencie β model, trenowany wΕaΕnie na takich zaszumionych wariantach, moΕΌe wtedy wskazaΔ fragment do rΔcznej weryfikacji, ktΓ³rego regex by przeoczyΕ.
| Etykieta wewnΔtrzna | Opis |
|---|---|
pesel |
numer PESEL |
nip |
numer NIP |
regon |
numer REGON |
iban |
numer rachunku bankowego IBAN |
id_card |
numer dowodu osobistego |
vehicle_vin |
numer VIN pojazdu |
13 kolejnych kategorii z peΕnej taksonomii systemu docelowego (np. numer telefonu, e-mail, adres IP, numer rejestracyjny pojazdu, data) zostaΕo celowo wyΕΔ czonych z treningu GLiNER β majΔ w peΕni deterministyczny ksztaΕt skΕadniowy, regex ma na nich 100% precyzji i trening neuronowy nie daje tam ΕΌadnej dodatkowej wartoΕci.
Wyniki ewaluacji
Ewaluacja porΓ³wnawcza na syntetycznym zbiorze testowym (ten sam rozkΕad kategorii co dane treningowe), w dwΓ³ch wariantach tekstu i przy czterech progach decyzyjnych. WyjaΕnienie parametrΓ³w, prostym jΔzykiem:
- Precision (precyzja) β z wszystkich fragmentΓ³w, ktΓ³re model wskazaΕ jako danΔ osobowΔ , jaki odsetek faktycznie niΔ byΕ. Niska precyzja = model "krzyczy wilk" za czΔsto (duΕΌo faΕszywych alarmΓ³w trafia do kolejki rΔcznej weryfikacji).
- Recall (czuΕoΕΔ/kompletnoΕΔ) β z wszystkich rzeczywistych danych osobowych w dokumencie, jaki odsetek model faktycznie wykryΕ. To jest metryka najwaΕΌniejsza dla tego zastosowania β niski recall = model przeoczyΕ dane osobowe, ktΓ³re powinny byΔ zamaskowane (realne ryzyko wycieku).
- F1 β jedna liczba ΕΔ czΔ ca precyzjΔ i recall (Εrednia harmoniczna) β wysoka tylko wtedy, gdy obie sΔ wysokie.
- Threshold (prΓ³g decyzyjny) β liczba od 0 do 1, im niΕΌsza, tym model jest "bardziej podejrzliwy" i zgΕasza wiΔcej kandydatΓ³w (wyΕΌszy recall, niΕΌsza precyzja). Dla tego zastosowania celowo testowano niskie progi (0.15β0.35), bo priorytetem jest zΕapanie wszystkiego potencjalnie wraΕΌliwego, nawet za cenΔ wiΔkszego szumu w kolejce do rΔcznej weryfikacji.
- Tekst "clean" vs "OCR-noised" β "clean" to czysty tekst ΕΊrΓ³dΕowy (np. plik z edytora tekstu), "OCR-noised" to ten sam tekst po sztucznym wprowadzeniu bΕΔdΓ³w typowych dla skanowania/OCR (np. pomylenie znakΓ³w O/0, I/1/l, S/5, B/8) β symuluje realny scenariusz skanowanych dokumentΓ³w.
- Zero-shot baseline β wynik tego samego modelu bazowego (
gliner-x-small) BEZ ΕΌadnego dotrenowania, czyli "z pudeΕka". PorΓ³wnanie z zero-shot pokazuje, ile realnie daΕ fine-tuning.
Wyniki mikro-uΕrednione (wszystkie kategorie ΕΔ cznie), prΓ³g 0.25
| Wariant tekstu | Model | Precision | Recall | F1 |
|---|---|---|---|---|
| Tekst czysty | anonPL-300M (ten model) | 0.977 | 0.993 | 0.985 |
| Tekst czysty | zero-shot gliner-x-small (bez treningu) |
0.308 | 0.819 | 0.447 |
| Tekst czysty | zero-shot gliner_multi-v2.1 (bez treningu) |
0.457 | 0.584 | 0.513 |
| Tekst z szumem OCR | anonPL-300M (ten model) | 0.958 | 0.940 | 0.949 |
| Tekst z szumem OCR | zero-shot gliner-x-small (bez treningu) |
0.282 | 0.741 | 0.409 |
| Tekst z szumem OCR | zero-shot gliner_multi-v2.1 (bez treningu) |
0.434 | 0.542 | 0.482 |
Fine-tuning znaczΔ
co podnosi wszystkie metryki wzglΔdem modelu bazowego "z pudeΕka" β recall na czystym tekΕcie roΕnie z 0.82 do 0.99, a na tekΕcie zaszumionym OCR z 0.74 do 0.94. Widoczny jest oczekiwany, niewielki spadek skutecznoΕci na tekΕcie zaszumionym OCR wzglΔdem czystego (recall 0.99 β 0.94) β to jest normalne, bo zaszumione znaki utrudniajΔ
rozpoznanie nawet modelowi trenowanemu na takich wariantach. Warto odnotowaΔ, ΕΌe na wariancie OCR-noised anonPL-300M wypada w tej ewaluacji nieco lepiej niΕΌ wiΔkszy anonPL-494M (recall 0.940 vs 0.930) β rΓ³ΕΌnica jest niewielka i w granicach szumu pomiarowego jednego przebiegu ewaluacji, nie naleΕΌy z niej wyciΔ
gaΔ dalekosiΔΕΌnych wnioskΓ³w bez powtΓ³rzenia testu na wiΔkszej prΓ³bie.
PeΕna tabela z rozbiciem na 13 kategorii i 4 progi decyzyjne (0.15/0.25/0.35/0.5): plik comparative_eval.json w repozytorium treningowym.
Wykresy porΓ³wnawcze recall per kategoria (ten model, anonPL-494M, oraz trzy modele zero-shot bez treningu), osobno dla tekstu czystego i zaszumionego OCR: recall_clean_vs_zeroshot.png, recall_ocr_vs_zeroshot.png.
Krzywa treningu (val F1, prΓ³g ewaluacyjny wewnΔ trz treningu = 0.5)
| Epoka | val F1 |
|---|---|
| 1 | 0.9794 |
| 2 | 0.9823 |
| 3 | 0.9841 |
| 4 | 0.9845 |
| 5 | 0.9844 |
| 6 | 0.9844 |
| 7 | 0.9844 |
Trening zatrzymany przez early stopping po epoce 7 (brak dalszej poprawy val F1 w ramach ustalonej "patience").
Format modelu i eksport ONNX
Model udostΔpniany jest w formacie ONNX (nie GGUF β format GGUF/llama.cpp jest zaprojektowany pod architektury autoregresywne typu LLM, GLiNER to bidirekcyjny enkoder ze span-classification head i nie ma natywnego, oficjalnego wsparcia GGUF). DostΔpne warianty:
onnx/model.onnxβ ONNX fp32, peΕna precyzja (656 MB).onnx/model_quantized.onnxβ ONNX int8 (dynamic quantization), znaczΔ co mniejszy rozmiar plikΓ³w i szybsza inferencja na CPU (165 MB), przy niewielkim spadku precyzji liczb β w praktyce dla tego zadania rΓ³ΕΌnica w jakoΕci detekcji jest zwykle marginalna. Dla mniejszego modelu bazowego (gliner-x-small) ten wariant jest szczegΓ³lnie atrakcyjny dla wdroΕΌeΕ bez GPU.
SposΓ³b uΕΌycia (przykΕadowy kod inferencji ONNX Runtime)
PrzykΕad poniΕΌej zakΕada, ΕΌe eksport ONNX (onnx/model.onnx lub onnx/model_quantized.onnx) oraz pliki tokenizera znajdujΔ
siΔ w katalogu modelu. Do uruchomienia potrzebny jest pakiet gliner (obsΕuguje backend ONNX Runtime natywnie) lub bezpoΕrednio onnxruntime z wΕasnΔ
logikΔ
pre/post-processingu.
from gliner import GLiNER
# Wariant fp32 (peΕna precyzja) lub model_quantized.onnx (int8, szybszy)
model = GLiNER.from_pretrained(
"sciezka/do/anonPL-300M",
load_onnx_model=True,
onnx_model_file="onnx/model_quantized.onnx",
)
text = """
Powodem w niniejszej sprawie jest Jan Kowalski, zamieszkaΕy
przy ul. DΕugiej 15, 61-800 PoznaΕ, PESEL 90010112345.
Sygnatura sprawy: I C 456/26.
"""
labels = [
"osoba fizyczna (strona lub uczestnik postΔpowania)",
"adres",
"numer PESEL",
"sygnatura sprawy",
]
# Niski prΓ³g decyzyjny (np. 0.2) = maksymalny recall, wiΔcej faΕszywych alarmΓ³w
# do przekazania dalej do rΔcznej weryfikacji β zgodnie z przeznaczeniem modelu.
entities = model.predict_entities(text, labels, threshold=0.2)
for entity in entities:
print(entity["text"], "=>", entity["label"], f"(score={entity['score']:.2f})")
KaΕΌde wskazanie modelu musi przejΕΔ przez proces ludzkiej weryfikacji przed usuniΔciem lub zamaskowaniem danych β patrz sekcja "Ograniczenia i etyka".
Licencja
Ten model jest licencjonowany na zasadach PolyForm Noncommercial License 1.0.0.
To zmiana wzglΔdem wczeΕniejszego stanu tego projektu: model bazowy knowledgator/gliner-x-small jest publikowany na licencji Apache 2.0 i pozostaje na niej β ta licencja nie jest zmieniana ani odbierana. Jednak fine-tune (wagi tego modelu), dane treningowe oraz integracja z aplikacjΔ
"Anonimizator Pism" sΔ
od tej publikacji licencjonowane przez autora na licencji niekomercyjnej, niezaleΕΌnie od licencji modelu bazowego.
Co to oznacza w praktyce:
- UΕΌycie niekomercyjne β bezpΕatne i dozwolone bez dodatkowej zgody: uΕΌycie osobiste, badawcze, edukacyjne, testowe, a takΕΌe uΕΌycie przez organizacje nonprofit (non-profit) w ramach ich dziaΕalnoΕci statutowej. Obejmuje to rΓ³wnieΕΌ dowolne modyfikacje i redystrybucjΔ w tych samych, niekomercyjnych warunkach.
- UΕΌycie komercyjne wymaga osobnej, wyraΕΊnej zgody autora: jakiekolwiek wykorzystanie modelu (samodzielnie lub jako czΔΕΔ produktu/usΕugi) w celu generowania przychodu, w ramach dziaΕalnoΕci gospodarczej, lub przez podmiot komercyjny (w tym kancelarie prawne ΕwiadczΔ ce usΕugi pΕatne z wykorzystaniem tego modelu poza zakresem osobistego/testowego uΕΌycia) wymaga uprzedniego kontaktu z autorem i uzyskania osobnej licencji komercyjnej.
- PeΕny, wiΔ ΕΌΔ cy tekst licencji: https://polyformproject.org/licenses/noncommercial/1.0.0/
Dane treningowe sΔ w 100% syntetyczne (wygenerowane programistycznie + warianty stylistyczne wygenerowane przez LLM), bez wykorzystania rzeczywistych dokumentΓ³w klientΓ³w jakiejkolwiek kancelarii β nie ma tu wiΔc kwestii licencji/zgody osΓ³b trzecich dotyczΔ cej samych danych treningowych.
Ograniczenia i etyka
Model przetwarza wraΕΌliwe dane osobowe (PII), dlatego wszelkie operacje z jego uΕΌyciem, zarΓ³wno na etapie testowania, jak i inferencji, muszΔ byΔ przeprowadzane z zachowaniem rygorystycznych standardΓ³w bezpieczeΕstwa oraz w peΕnej zgodnoΕci z przepisami RODO.
NaleΕΌy podkreΕliΔ, ΕΌe model nie jest przeznaczony do w peΕni zautomatyzowanej i autonomicznej anonimizacji dokumentΓ³w. Powinien byΔ traktowany jako warstwa wspomagajΔ ca proces wykrywania (zwiΔkszajΔ ca recall), ktΓ³rej zadaniem jest wskazanie potencjalnie przeoczonych fragmentΓ³w tekstu. KaΕΌda wskazana przez model encja wymaga bezwzglΔdnej weryfikacji przez wykwalifikowanego czΕowieka przed podjΔciem decyzji o usuniΔciu lub zamaskowaniu danych.
W kontekΕcie prawnym bΕΔ d faΕszywie ujemny, czyli niewykrycie danej osobowej przez model, prowadzi do realnego ryzyka wycieku poufnych danych klienta kancelarii, co niesie za sobΔ powaΕΌne konsekwencje prawne i wizerunkowe. Ryzyko to musi byΔ Εwiadomie akceptowane i zarzΔ dzane przez uΕΌytkownika systemu.
PoniewaΕΌ model trenowany byΕ wyΕΔ
cznie na danych syntetycznych, a nie na rzeczywistych dokumentach klientΓ³w, istnieje ryzyko obniΕΌonej skutecznoΕci generalizacji na nietypowe, niestandardowe formaty dokumentΓ³w spoza rozkΕadu treningowego (np. bardzo nieformalny jΔzyk, nietypowe skrΓ³ty, dokumenty w innym rejestrze niΕΌ pisma sΔ
dowe). Model moΕΌe popeΕniaΔ bΕΔdy, w tym pominiΔcia istotnych fragmentΓ³w lub bΕΔdne wskazania (faΕszywe alarmy). Jako mniejszy model, anonPL-300M moΕΌe byΔ nieco bardziej podatny na takie bΕΔdy przy skrajnie nietypowych sformuΕowaniach niΕΌ wiΔkszy wariant anonPL-494M β nie zostaΕo to jednak potwierdzone systematycznym testem poza standardowΔ
ewaluacjΔ
porΓ³wnawczΔ
wyΕΌej. Korzystanie z modelu nie zwalnia uΕΌytkownika z ostatecznej odpowiedzialnoΕci prawnej za poprawnoΕΔ i kompletnoΕΔ procesu anonimizacji.
Zastosowanie w aplikacji
Ten model jest wykorzystywany jako dodatkowa warstwa detekcji w darmowej aplikacji desktopowej "Anonimizator Pism" (Windows + Linux) do anonimizacji polskich dokumentΓ³w prawniczych: https://github.com/cenkierpiotr/anonimizator-pism2 β licencjonowanej niekomercyjnie, tak samo jak ten model.
π¬π§ English
A fine-tune of the GLiNER model (base model: knowledgator/gliner-x-small, google/mt5-small backbone, ~300M parameters), further trained on synthetic Polish legal documents to detect personal data and identifiers requiring anonymization.
IMPORTANT WARNING β this is not a standalone anonymization system
This model is intended solely as an additional recall-boosting layer (detecting potentially overlooked fragments), never as a standalone, fully automatic anonymization mechanism.
In the target architecture this model was built for, the authoritative mechanism for detecting and masking personal data is a deterministic regex pipeline + checksum validation (for PESEL, NIP, REGON, IBAN, etc.) combined with a classic NER model. This pipeline is auditable and, on clean text, error-free for identifiers with a rigid structure. anonPL-300M never replaces this mechanism and never flows directly into the final, anonymized document β any detection from the model that does not overlap with an already-confirmed detection must be routed to an "uncertain / potentially overlooked" queue, requiring manual human review before any decision to remove or mask data is made.
Rationale for this architectural decision: a false-negative error (the model fails to detect personal data that should have been masked) in this use case means a real leak of a law firm client's personal data β an unacceptable risk without a human verification layer.
Model description and intended use
This model is a fine-tuned version of the GLiNER architecture, a span-based encoder for named entity recognition (NER) capable of zero-shot operation. It was trained on synthetic Polish legal documents such as court filings, contracts, notarial deeds, and court rulings. The model's main task is to detect personal data and various identifiers in documentation processed by law firms and related institutions.
Unlike traditional NER models, which rely on rigid dictionaries or predefined lists, GLiNER analyzes text for meaning and identifies entities based on label descriptions rather than a fixed list of words. This approach enables effective detection of data even when it appears in unusual phrasings, inflected forms, or grammatical contexts that did not appear explicitly in the training material.
anonPL-300M is the smaller and faster of the two published size variants (the other being anonPL-494M) β with fewer parameters, it offers noticeably faster inference and lower memory usage, at the cost of slightly lower robustness to extremely noisy text. In this specific evaluation, the quality difference between the variants is small (see "Evaluation results" section) β anonPL-300M is usually a reasonable default choice, while anonPL-494M makes sense where maximum robustness to very noisy scans is the priority.
Label taxonomy
The model recognizes 13 entity categories, split into two groups with different rationale:
Group A β free-text entities (full training value)
Categories that regex cannot meaningfully detect, because they have no rigid syntactic shape β they require contextual understanding:
| Internal label | Description (label used in training/evaluation) |
|---|---|
legal_role_person |
natural person (a party or participant in proceedings) β full name together with their procedural role |
institution |
institution or court (e.g. "District Court in PoznaΕ") |
address |
address (street, number, postal code, city) |
case_number |
case reference number |
notarial_act |
notarial deed number |
usc_act |
civil registry act number or certificate of succession |
inheritance_registry |
inheritance registry entry number |
Group B β structural identifiers (trained for robustness to OCR noise)
These categories have a 100% deterministic, rigid shape (digits + checksum) β on clean text, regex+checksum is error-free and does not need the model. GLiNER only makes sense here as a "second chance": when a document originates from a scan/OCR and the identifier's digits are noisy (character misrecognition), checksum validation fails even though the data is genuinely present in the document β the model, trained specifically on such noisy variants, can then flag the fragment for manual review that regex would have missed.
| Internal label | Description |
|---|---|
pesel |
Polish national identification number (PESEL) |
nip |
Polish tax identification number (NIP) |
regon |
Polish business statistical number (REGON) |
iban |
IBAN bank account number |
id_card |
national ID card number |
vehicle_vin |
vehicle VIN number |
13 further categories from the target system's full taxonomy (e.g. phone number, email, IP address, vehicle registration plate, date) were intentionally excluded from GLiNER training β they have a fully deterministic syntactic shape, regex achieves 100% precision on them, and neural training adds no additional value there.
Evaluation results
Comparative evaluation on a synthetic test set (same category distribution as the training data), across two text variants and four decision thresholds. Plain-language explanation of the parameters:
- Precision β of all fragments the model flagged as personal data, what fraction actually was. Low precision = the model "cries wolf" too often (many false alarms end up in the manual review queue).
- Recall (sensitivity/completeness) β of all the real personal data present in the document, what fraction the model actually detected. This is the most important metric for this use case β low recall means the model missed personal data that should have been masked (a real risk of data leakage).
- F1 β a single number combining precision and recall (harmonic mean) β high only when both are high.
- Threshold β a number from 0 to 1; the lower it is, the more "suspicious" the model becomes and the more candidates it flags (higher recall, lower precision). For this use case, low thresholds (0.15β0.35) were deliberately tested, because the priority is catching everything potentially sensitive, even at the cost of more noise in the manual review queue.
- "clean" vs "OCR-noised" text β "clean" is the original source text (e.g. a text-editor file); "OCR-noised" is the same text after artificially injecting errors typical of scanning/OCR (e.g. confusing O/0, I/1/l, S/5, B/8) β simulating a real scenned-document scenario.
- Zero-shot baseline β the result of the same base model (
gliner-x-small) WITHOUT any fine-tuning, i.e. "out of the box". Comparison against zero-shot shows how much value the fine-tuning actually added.
Micro-averaged results (all categories combined), threshold 0.25
| Text variant | Model | Precision | Recall | F1 |
|---|---|---|---|---|
| Clean text | anonPL-300M (this model) | 0.977 | 0.993 | 0.985 |
| Clean text | zero-shot gliner-x-small (untrained) |
0.308 | 0.819 | 0.447 |
| Clean text | zero-shot gliner_multi-v2.1 (untrained) |
0.457 | 0.584 | 0.513 |
| OCR-noised text | anonPL-300M (this model) | 0.958 | 0.940 | 0.949 |
| OCR-noised text | zero-shot gliner-x-small (untrained) |
0.282 | 0.741 | 0.409 |
| OCR-noised text | zero-shot gliner_multi-v2.1 (untrained) |
0.434 | 0.542 | 0.482 |
Fine-tuning significantly improves all metrics compared to the base model "out of the box" β recall on clean text rises from 0.82 to 0.99, and on OCR-noised text from 0.74 to 0.94. There is an expected, small drop in performance on OCR-noised text relative to clean text (recall 0.99 β 0.94) β this is normal, since noisy characters make recognition harder even for a model trained on such variants. It is worth noting that on the OCR-noised variant, anonPL-300M performs slightly better in this evaluation than the larger anonPL-494M (recall 0.940 vs 0.930) β the difference is small and within the measurement noise of a single evaluation run, and should not be over-interpreted without repeating the test on a larger sample.
Full breakdown by 13 categories and 4 decision thresholds (0.15/0.25/0.35/0.5): file comparative_eval.json in the training repository.
Comparative recall-per-category charts (this model, anonPL-494M, and three untrained zero-shot models), separately for clean and OCR-noised text: recall_clean_vs_zeroshot.png, recall_ocr_vs_zeroshot.png.
Training curve (validation F1, in-training evaluation threshold = 0.5)
| Epoch | val F1 |
|---|---|
| 1 | 0.9794 |
| 2 | 0.9823 |
| 3 | 0.9841 |
| 4 | 0.9845 |
| 5 | 0.9844 |
| 6 | 0.9844 |
| 7 | 0.9844 |
Training was stopped by early stopping after epoch 7 (no further val F1 improvement within the configured patience).
Model format and ONNX export
The model is distributed in ONNX format (not GGUF β the GGUF/llama.cpp format is designed for autoregressive LLM-style architectures; GLiNER is a bidirectional encoder with a span-classification head and has no native, official GGUF support). Available variants:
onnx/model.onnxβ ONNX fp32, full precision (656 MB).onnx/model_quantized.onnxβ ONNX int8 (dynamic quantization), significantly smaller file size and faster CPU inference (165 MB), at a small cost in numeric precision β in practice, for this task the difference in detection quality is usually marginal. For the smaller base model (gliner-x-small), this variant is especially attractive for GPU-less deployments.
Usage (example ONNX Runtime inference code)
The example below assumes the ONNX export (onnx/model.onnx or onnx/model_quantized.onnx) and the tokenizer files are located in the model directory. Running it requires the gliner package (which natively supports the ONNX Runtime backend), or onnxruntime directly with your own pre/post-processing logic.
from gliner import GLiNER
# fp32 variant (full precision), or model_quantized.onnx (int8, faster)
model = GLiNER.from_pretrained(
"path/to/anonPL-300M",
load_onnx_model=True,
onnx_model_file="onnx/model_quantized.onnx",
)
text = """
Powodem w niniejszej sprawie jest Jan Kowalski, zamieszkaΕy
przy ul. DΕugiej 15, 61-800 PoznaΕ, PESEL 90010112345.
Sygnatura sprawy: I C 456/26.
"""
labels = [
"natural person (a party or participant in proceedings)",
"address",
"PESEL number",
"case reference number",
]
# Low decision threshold (e.g. 0.2) = maximum recall, more false positives
# to be passed on for manual review β consistent with the model's intended use.
entities = model.predict_entities(text, labels, threshold=0.2)
for entity in entities:
print(entity["text"], "=>", entity["label"], f"(score={entity['score']:.2f})")
Every detection made by the model must go through a human verification process before any data is removed or masked β see the "Limitations and ethics" section.
License
This model is licensed under the PolyForm Noncommercial License 1.0.0.
This is a change from the earlier state of this project: the base model knowledgator/gliner-x-small is published under the Apache 2.0 license, and that license remains unchanged and is not being revoked. However, the fine-tuned weights of this model, the training data, and the integration with the "Anonimizator Pism" application are, as of this publication, licensed by the author under a noncommercial license, independently of the base model's license.
What this means in practice:
- Noncommercial use β free and permitted without additional consent: personal, research, educational, and testing use, as well as use by nonprofit organizations as part of their statutory activities. This also includes any modification and redistribution under the same noncommercial terms.
- Commercial use requires the author's separate, explicit consent: any use of the model (standalone or as part of a product/service) for the purpose of generating revenue, as part of a business activity, or by a commercial entity (including law firms providing paid services using this model beyond personal/testing use) requires prior contact with the author and a separate commercial license.
- Full, binding license text: https://polyformproject.org/licenses/noncommercial/1.0.0/
The training data is 100% synthetic (programmatically generated plus stylistic variants generated by an LLM), without the use of any real client documents from any law firm β so there is no third-party licensing/consent issue regarding the training data itself.
Limitations and ethics
The model processes sensitive personal data (PII), so all operations involving its use β both during testing and inference β must be carried out in compliance with rigorous security standards and full GDPR compliance.
It should be emphasized that the model is not intended for fully automated, autonomous document anonymization. It should be treated as a layer that supports the detection process (increasing recall), whose job is to flag potentially overlooked text fragments. Every entity flagged by the model requires mandatory verification by a qualified human before any decision is made to remove or mask the data.
In a legal context, a false-negative error β i.e. the model failing to detect personal data β leads to a real risk of leaking a law firm client's confidential data, which carries serious legal and reputational consequences. This risk must be knowingly accepted and managed by the user of the system.
Because the model was trained exclusively on synthetic data rather than real client documents, there is a risk of reduced generalization performance on unusual, non-standard document formats outside the training distribution (e.g. very informal language, unusual abbreviations, documents from a different register than court filings). The model may make errors, including missing significant fragments or flagging false positives. As a smaller model, anonPL-300M may be somewhat more prone to such errors on extremely unusual phrasings than the larger anonPL-494M variant β however, this has not been confirmed by systematic testing beyond the standard comparative evaluation above. Use of the model does not relieve the user of ultimate legal responsibility for the correctness and completeness of the anonymization process.
Application use
This model is used as an additional detection layer in a free desktop application called "Anonimizator Pism" (Windows + Linux) for anonymizing Polish legal documents: https://github.com/cenkierpiotr/anonimizator-pism2 β licensed noncommercially, exactly like this model.
- Downloads last month
- 10
Model tree for cenkierpiotr/anonPL-300M
Base model
knowledgator/gliner-x-small