polanon 0.3.2__tar.gz → 0.3.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polanon-0.3.2 → polanon-0.3.4}/CHANGELOG.md +107 -0
- {polanon-0.3.2 → polanon-0.3.4}/PKG-INFO +81 -11
- {polanon-0.3.2 → polanon-0.3.4}/README.md +77 -10
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/README.md +28 -19
- polanon-0.3.4/benchmarks/gold/karta_wypisowa.json +77 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/run.py +1 -1
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/README.md +9 -3
- polanon-0.3.4/benchmarks/samples/karta_wypisowa.txt +28 -0
- {polanon-0.3.2 → polanon-0.3.4}/docs/THREAT_MODEL.md +36 -0
- {polanon-0.3.2 → polanon-0.3.4}/docs/haystack-integration.md +6 -5
- {polanon-0.3.2 → polanon-0.3.4}/polanon/__init__.py +19 -6
- {polanon-0.3.2 → polanon-0.3.4}/polanon/allowlist.py +16 -2
- polanon-0.3.4/polanon/gateway/__init__.py +14 -0
- polanon-0.3.4/polanon/gateway/__main__.py +203 -0
- polanon-0.3.4/polanon/gateway/app.py +521 -0
- polanon-0.3.4/polanon/gateway/payloads.py +545 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/names_pl.py +113 -18
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/ner.py +29 -3
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/recognizers_pl.py +79 -12
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/secrets.py +20 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/pipeline.py +47 -19
- {polanon-0.3.2 → polanon-0.3.4}/polanon/turn.py +30 -5
- {polanon-0.3.2 → polanon-0.3.4}/polanon.egg-info/PKG-INFO +81 -11
- {polanon-0.3.2 → polanon-0.3.4}/polanon.egg-info/SOURCES.txt +10 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon.egg-info/entry_points.txt +1 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon.egg-info/requires.txt +4 -0
- {polanon-0.3.2 → polanon-0.3.4}/pyproject.toml +4 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_allowlist.py +47 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_benchmark.py +4 -4
- polanon-0.3.4/tests/test_gateway_app.py +547 -0
- polanon-0.3.4/tests/test_gateway_cli.py +119 -0
- polanon-0.3.4/tests/test_gateway_payloads.py +625 -0
- polanon-0.3.4/tests/test_gateway_server.py +100 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_known_parts.py +48 -1
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_layering.py +13 -8
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_names_guard.py +82 -1
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_ner_guard.py +25 -1
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_pipeline.py +105 -2
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_pipeline_invariants.py +43 -12
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_public_api.py +96 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_recognizers_pl.py +84 -2
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_secrets_guard.py +30 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_turn.py +29 -0
- {polanon-0.3.2 → polanon-0.3.4}/CONTRIBUTING.md +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/LICENSE +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/MANIFEST.in +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/SECURITY.md +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/compare_presidio.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/demo.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/cv.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/czat.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/faktura.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/invoice_se.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/invoice_uk.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/mail_klienta.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/monthly_roster.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/notatka_wewnetrzna.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/rechnung_ch.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/umowa.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/gold/zgloszenie_it.json +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/cv.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/czat.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/faktura.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/invoice_se.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/invoice_uk.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/mail_klienta.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/monthly_roster.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/notatka_wewnetrzna.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/rechnung_ch.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/umowa.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/benchmarks/samples/zgloszenie_it.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/docs/demo.gif +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/examples/anthropic_chat.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/examples/haystack_openai.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/examples/haystack_rag.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/examples/openai_chat.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/__main__.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/_canonical.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/_detection.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/_known_parts.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/_matching.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/_view.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/__init__.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/base.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/company_pl.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/denylist.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/guards/international.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/index.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/integrations/__init__.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/integrations/haystack.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/judge/__init__.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/judge/base.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/judge/mock.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/judge/ollama.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/judge/parsing.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/judge/prompt.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/judge/remote.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/output_sweep.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/policy.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/pseudonyms.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/py.typed +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/stream_restore.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon/types.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon.egg-info/dependency_links.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/polanon.egg-info/top_level.txt +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/setup.cfg +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/__init__.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/haystack.coveragerc +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_canonical.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_cli.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_company_guard.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_denylist_guard.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_examples.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_haystack.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_index.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_international_guard.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_judges.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_mock_judge.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_output_sweep.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_pseudonyms.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_readme_rag.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_stream_restore.py +0 -0
- {polanon-0.3.2 → polanon-0.3.4}/tests/test_types.py +0 -0
|
@@ -5,6 +5,113 @@ All notable changes to this project are recorded here. The format follows
|
|
|
5
5
|
[semantic versioning](https://semver.org/spec/v2.0.0.html); until 1.0, the second number goes up
|
|
6
6
|
only for a change that breaks something, as CONTRIBUTING.md describes.
|
|
7
7
|
|
|
8
|
+
## [0.3.4] - 2026-11-14
|
|
9
|
+
|
|
10
|
+
A new extra and fixes, and nothing that worked before stops working: a patch release, as
|
|
11
|
+
CONTRIBUTING.md describes. The gateway comes with `pip install "polanon[gateway]"`; `pip install
|
|
12
|
+
polanon` alone is unchanged and still needs nothing beyond the standard library. Where detection
|
|
13
|
+
missed or mislabelled a value it now differs, so a text may come out with other tokens: a first
|
|
14
|
+
name alone gives way to the language model's place or company, and a stray word left over where
|
|
15
|
+
two detections overlapped stays readable.
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- **A masking gateway for tools that speak the OpenAI API**, run by whoever needs it on their own
|
|
20
|
+
machine: `pip install "polanon[gateway]"`, then `polanon-gateway --upstream
|
|
21
|
+
https://api.openai.com/v1`, and Hermes Agent, n8n, Open WebUI or LibreChat point their base URL at
|
|
22
|
+
`http://127.0.0.1:8787/v1`. It serves `/v1/chat/completions` and the Responses API,
|
|
23
|
+
`/v1/responses`, streamed or not and with tool calls, `/v1/embeddings` and `/v1/models`, and
|
|
24
|
+
refuses every other endpoint, images and audio. With the Responses API the whole conversation
|
|
25
|
+
comes with every call, as Hermes Agent sends it with `store: false`, and encrypted reasoning
|
|
26
|
+
passes as it is; a call that leaves the conversation at the provider is refused. Every call
|
|
27
|
+
is masked, checked once more for any original value before it leaves, and restored on the way
|
|
28
|
+
back, a tool call's arguments as valid JSON. It keeps nothing on disk, listens on 127.0.0.1 and
|
|
29
|
+
needs a key every client sends to listen anywhere else, takes keys from the environment only, and
|
|
30
|
+
logs counts, never values. The library still imports no web framework: the gateway is a plain
|
|
31
|
+
ASGI application with httpx, served by uvicorn.
|
|
32
|
+
|
|
33
|
+
- **A twelfth benchmark document**, a hospital discharge summary, health data being the most
|
|
34
|
+
sensitive kind (#4): a patient with her PESEL, birth date, address and phone, her daughter, two
|
|
35
|
+
doctors behind their titles and the hospital's address. Every value is made up, and the patient
|
|
36
|
+
was born in 1847, so her PESEL belongs to nobody. The rules alone mask all of it but its two
|
|
37
|
+
places; with `pl_core_news_md` all 18 values are masked, and the ward's name is read as a company.
|
|
38
|
+
The corpus now has 187 annotated values: 161 masked with the rules alone (86%) and 184 with the
|
|
39
|
+
model (98%), with 8 over-masked spans, the ward one of them.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- **A model's reasoning sent back with its answer** is masked by `MaskedTurn.mask_messages`:
|
|
44
|
+
OpenRouter returns the reasoning next to the answer, in `reasoning` and `reasoning_details`, and
|
|
45
|
+
a client that kept the answer sent it back with the history, restored, in the clear. Now
|
|
46
|
+
`reasoning`, `reasoning_content` and the text and summary of every item of `reasoning_details`
|
|
47
|
+
are masked, and encrypted reasoning passes as it is. Found by the gateway's last check, which
|
|
48
|
+
refused the call, in a test against OpenRouter.
|
|
49
|
+
- **A surname on the next line or in the next cell** is masked without the language model:
|
|
50
|
+
"z panem Janem\nKowalskim" in a hard-wrapped e-mail, "Jan;Kowalski" in a CSV export and
|
|
51
|
+
"| Jan | Kowalski |" in a Markdown table kept the surname in clear (#15). On the next line it
|
|
52
|
+
joins the first name; in the next cell it is masked on its own, so the row keeps its columns.
|
|
53
|
+
Across a line or a cell the word must read as a surname, so "Imię: Jan\nNazwisko:", "Jan;Anna",
|
|
54
|
+
"Jan;Kraków" and "Kamil\nNowak Transport" under a signature stay apart.
|
|
55
|
+
- **A place spelled like a first name** keeps the language model's label: "Wakacje na Kubie" went
|
|
56
|
+
to the model as a person, since a first name outranked the model wherever the two overlapped
|
|
57
|
+
(#16). A first name alone, with no surname, initial or form of address, now scores 0.8, below
|
|
58
|
+
the model's 0.85, and is still masked as a person without the model. "Asia" alone is the
|
|
59
|
+
continent, as "Maja" is the month; "Asia Kowalska" and "pani Asia" stay people.
|
|
60
|
+
- **A piece left over from a losing detection** is treated alike in every turn (#20). Masked in
|
|
61
|
+
place in the first turn, it was a known value in the next, so the bare "NIP" that an address
|
|
62
|
+
rule left behind went to the model as an address in every sentence. A piece with no digit of a
|
|
63
|
+
type whose values always carry one, or with fewer than three letters and digits, now stays as
|
|
64
|
+
written; any other piece, such as the name of a loose span around an e-mail address, is masked
|
|
65
|
+
wherever it stands from the first turn on.
|
|
66
|
+
- **An academic title alone** stays readable: the Polish model tagged the "n." of "dr n. med." as a
|
|
67
|
+
person. A span the model finds made only of titles such as dr, n., med., hab., prof., mgr, inż.
|
|
68
|
+
and lek. is dropped, as form labels are; "dr n. med. Ewa Zawadzka" keeps the name masked.
|
|
69
|
+
|
|
70
|
+
## [0.3.3] - 2026-11-12
|
|
71
|
+
|
|
72
|
+
Fixes only, and nothing that worked before stops working: a patch release, as CONTRIBUTING.md
|
|
73
|
+
describes. More is masked than under 0.3.2, so a text may carry more tokens, and with
|
|
74
|
+
`WELL_KNOWN_NAMES` the names of a few public institutions stay readable.
|
|
75
|
+
|
|
76
|
+
### Fixed
|
|
77
|
+
|
|
78
|
+
- **A token-shaped number longer than six digits** in the input, such as `<OSOBA_50810112354>`,
|
|
79
|
+
no longer sets the number of every later token, and one of thousands of digits no longer stops
|
|
80
|
+
masking with a `ValueError`. A new token still skips every token the mapping holds, so
|
|
81
|
+
`<OSOBA_999999>` followed by a new person never hands out one token twice. Contributed by Sonike
|
|
82
|
+
in [#24](https://github.com/boromat/polanon/pull/24).
|
|
83
|
+
- **A spaCy model named as pip writes it**, such as `pl-core-news-md`, loads, and a model directory
|
|
84
|
+
without `meta.json` and `config.cfg` is reported when the guards are built, without a download
|
|
85
|
+
command that could not work. An installed model still wins over a file or folder of the same
|
|
86
|
+
name in the working directory. Contributed by Sonike in
|
|
87
|
+
[#27](https://github.com/boromat/polanon/pull/27).
|
|
88
|
+
- **A password named by a word or two before its colon**, "Hasło administratora: Zima2025!Lod",
|
|
89
|
+
"hasło użytkownika admin:", "Hasło do panelu klienta:", is masked: only "do", "dla" or "od" and
|
|
90
|
+
one word could stand there, so the value went out in clear. With words in between, the value
|
|
91
|
+
must look like a password, so "Hasło administratora zostało zmienione." and a date after "Hasło
|
|
92
|
+
ważne do:" stay as they are.
|
|
93
|
+
- **A PESEL with a typo right after its label** is masked: "PESEL: 15501416181", with a wrong
|
|
94
|
+
check digit, and "pesel 78059938421", with day 99, went out in clear, since the checksum was
|
|
95
|
+
checked before the label. Without the label the checksum still decides, so an order number of
|
|
96
|
+
eleven digits stays as it is.
|
|
97
|
+
- **A feminine surname in another case** is masked after the full name: once "Natalia Bielska"
|
|
98
|
+
was masked, "Bielskiej" and "Bielską" went out in clear, in the same text and in the next turn,
|
|
99
|
+
since no case of a surname in -ska, -cka or -dzka but the nominative begins with it. In
|
|
100
|
+
lowercase, "w bielskiej firmie" stays an adjective.
|
|
101
|
+
- **A street without "ul." and without a postcode** is masked after an address label, "Adres:
|
|
102
|
+
Japczaka 17", "zam. Długa 5", "mieszka przy Długiej 5", and after "z", "na", "przy" or "do"
|
|
103
|
+
with a town right after the number, "z Długiej 17 w Białymstoku". Both went out in clear.
|
|
104
|
+
"Windows 11 w Polsce", "na Windows 11 w firmie" and "Excel 365 w biurze" stay as they are.
|
|
105
|
+
- **An address is found in linear time** in a long run of capitalised words: each word started a
|
|
106
|
+
street that ran to the end of the run, so 5,000 words such as "Ulica Ulica ..." or "I I ..."
|
|
107
|
+
took several seconds, and ten times as many a hundred times longer. A street's name now takes
|
|
108
|
+
at most eight words and three titles, more than any Polish street needs.
|
|
109
|
+
- **ZUS, Płatnik and the institutions staff name every day** are on `WELL_KNOWN_NAMES`: with the
|
|
110
|
+
allowlist, "Jak to rozliczyć w ZUS?" and "zna program Płatnik" went out as `<FIRMA_1>`, since
|
|
111
|
+
the language model reads them as organisations. Added: ZUS, PUE ZUS, eZUS, Płatnik, KRUS, NFZ,
|
|
112
|
+
GUS, KSeF, ePUAP, CEIDG and PFRON. The list releases names only, so no identifier is unmasked,
|
|
113
|
+
and "pani Płatnik" stays a person.
|
|
114
|
+
|
|
8
115
|
## [0.3.2] - 2026-11-12
|
|
9
116
|
|
|
10
117
|
New features and fixes, and nothing that worked before stops working: a patch release, as
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: polanon
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Reversible PII masking for LLM calls, Polish-first: checksum-validated PESEL, NIP, REGON and IBAN, Polish names in every case, stable tokens and streaming restore.
|
|
5
5
|
Author: BoroMat
|
|
6
6
|
License-Expression: MIT
|
|
@@ -30,6 +30,9 @@ Provides-Extra: judge
|
|
|
30
30
|
Requires-Dist: httpx>=0.27; extra == "judge"
|
|
31
31
|
Provides-Extra: haystack
|
|
32
32
|
Requires-Dist: haystack-ai<4,>=3.0; extra == "haystack"
|
|
33
|
+
Provides-Extra: gateway
|
|
34
|
+
Requires-Dist: httpx>=0.27; extra == "gateway"
|
|
35
|
+
Requires-Dist: uvicorn>=0.30; extra == "gateway"
|
|
33
36
|
Provides-Extra: dev
|
|
34
37
|
Requires-Dist: pytest>=8; extra == "dev"
|
|
35
38
|
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
@@ -87,7 +90,8 @@ of the box:
|
|
|
87
90
|
- **Checksums.** A PESEL, NIP, REGON, ID card number, IBAN or payment card is validated, not just
|
|
88
91
|
pattern-matched: the checksum rejects most random digit strings — for a PESEL, together with the
|
|
89
92
|
birth date, about 98% of them — while a valid number always passes. KRS numbers, which have no
|
|
90
|
-
public checksum, and passports are recognised next to their label as well.
|
|
93
|
+
public checksum, and passports are recognised next to their label as well. Eleven digits right
|
|
94
|
+
after the word PESEL are masked even with a typo in them.
|
|
91
95
|
- **Seven grammatical cases.** "Jan Kowalski", "Jana Kowalskiego" and "z Janem Kowalskim" are the
|
|
92
96
|
same person. Polish first names are recognised in every case, in lowercase and typed without
|
|
93
97
|
Polish letters, together with the surname that agrees with them, without any language model.
|
|
@@ -127,9 +131,14 @@ and the restored answer matter as much as the numbers.
|
|
|
127
131
|
| Also places, and names and organisations no rule can see | `pip install "polanon[ner]"` then `python -m spacy download pl_core_news_md` |
|
|
128
132
|
| The stage-2 judges (a local Ollama model, or a remote one) | `pip install "polanon[judge]"` |
|
|
129
133
|
| Components for [Haystack 3](#with-haystack) pipelines | `pip install "polanon[haystack]"` |
|
|
134
|
+
| A [gateway](#a-gateway-for-any-openai-compatible-tool) for tools that use the OpenAI API | `pip install "polanon[gateway]"` |
|
|
130
135
|
|
|
131
136
|
Then use `default_guards()` with the model, or `default_guards(with_ner=False)` without it.
|
|
132
137
|
Another spaCy model is one argument away: `default_guards(spacy_model="pl_core_news_lg")`.
|
|
138
|
+
Package names copied from pip work too (`pl-core-news-lg`). A local model directory can be passed
|
|
139
|
+
as a path; it must contain `meta.json` and `config.cfg`. Missing packages or model directories are
|
|
140
|
+
reported when the guards are built, while the model itself loads on first use.
|
|
141
|
+
An installed model package takes priority over a local path with the same name.
|
|
133
142
|
|
|
134
143
|
## From the command line
|
|
135
144
|
|
|
@@ -440,6 +449,64 @@ component receives, and the masker receives the originals. A run that fails keep
|
|
|
440
449
|
the error's snapshot, written to disk with `HAYSTACK_PIPELINE_SNAPSHOT_SAVE_ENABLED`. Both are off
|
|
441
450
|
by default.
|
|
442
451
|
|
|
452
|
+
## A gateway for any OpenAI-compatible tool
|
|
453
|
+
|
|
454
|
+
Tools such as Hermes Agent, n8n, Open WebUI or LibreChat talk to a model through the OpenAI API.
|
|
455
|
+
`polanon-gateway` stands between such a tool and the provider, on the machine of whoever runs it:
|
|
456
|
+
every message is masked before it leaves, and the answer comes back with the original values,
|
|
457
|
+
streamed or not, tool calls included.
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
pip install "polanon[gateway,ner]"
|
|
461
|
+
python -m spacy download pl_core_news_md
|
|
462
|
+
polanon-gateway --upstream https://api.openai.com/v1
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
Then point the tool's base URL at `http://127.0.0.1:8787/v1` and keep its API key: the gateway
|
|
466
|
+
passes it on to the provider. A local model works the same way, `--upstream
|
|
467
|
+
http://localhost:11434/v1` for Ollama.
|
|
468
|
+
|
|
469
|
+
| Tool | Where the base URL goes |
|
|
470
|
+
|---|---|
|
|
471
|
+
| Hermes Agent | `base_url` of the model or of a named provider in `config.yaml` |
|
|
472
|
+
| n8n | the Base URL of the OpenAI credential |
|
|
473
|
+
| Open WebUI | the URL of an OpenAI API connection |
|
|
474
|
+
| LibreChat | the `baseURL` of a custom endpoint in `librechat.yaml` |
|
|
475
|
+
|
|
476
|
+
What it does with a call:
|
|
477
|
+
|
|
478
|
+
- It serves `/v1/chat/completions` and the Responses API, `/v1/responses`, streamed or not,
|
|
479
|
+
`/v1/embeddings` and `/v1/models`, and refuses every other endpoint, so nothing it cannot mask
|
|
480
|
+
leaves as it came.
|
|
481
|
+
- With the Responses API the whole conversation comes with every call, as Hermes Agent sends it
|
|
482
|
+
with `store: false`. A call that leaves it at the provider, with `previous_response_id` or
|
|
483
|
+
`conversation`, or asks for a `background` response to fetch later, would bring back tokens no
|
|
484
|
+
one can restore, and is refused. Encrypted reasoning passes as it is: the provider sealed it from
|
|
485
|
+
masked text.
|
|
486
|
+
- Every message, tool result and earlier tool call is masked, and a participant's `name` is left
|
|
487
|
+
out; tool schemas pass as they are.
|
|
488
|
+
- An image, a file or audio cannot be masked, so the call is refused; `--drop-unsupported` leaves
|
|
489
|
+
such content out and sends the rest.
|
|
490
|
+
- Before anything leaves, the payload is searched once more for every original value, and the call
|
|
491
|
+
is refused if one is still there.
|
|
492
|
+
- A note telling the model what the tokens are joins the system message: `--instructions en`, or
|
|
493
|
+
`none` to leave it out.
|
|
494
|
+
- It keeps nothing on disk. A tool sends the whole conversation with every call, and each call is
|
|
495
|
+
masked and restored on its own. With `POLANON_KEY` set to 64 hexadecimal characters, a person
|
|
496
|
+
keeps one token in every call and in every grammatical case.
|
|
497
|
+
|
|
498
|
+
Keys stay with whoever runs the gateway, and come from the environment only. By default the
|
|
499
|
+
tool's own key is passed on; `POLANON_UPSTREAM_KEY` sends another one instead. The gateway listens
|
|
500
|
+
on `127.0.0.1`. To reach it from another machine, set `--host` and `POLANON_GATEWAY_KEY`, which
|
|
501
|
+
every client must then send: without the key it refuses to start. The log names the path, the
|
|
502
|
+
status, the time and how many values of each type were masked, never a value.
|
|
503
|
+
|
|
504
|
+
There is no hosted service: the gateway runs where it is installed, and whoever runs it answers
|
|
505
|
+
for that machine, its keys and the provider the calls go to. Not supported yet: Anthropic's
|
|
506
|
+
Messages API. The
|
|
507
|
+
[threat model](https://github.com/boromat/polanon/blob/main/docs/THREAT_MODEL.md#the-gateway) says
|
|
508
|
+
what the gateway protects and what it does not.
|
|
509
|
+
|
|
443
510
|
## What it detects
|
|
444
511
|
|
|
445
512
|
Checksum-validated Polish identifiers (PESEL, NIP, REGON, ID card, IBAN, payment cards), KRS numbers
|
|
@@ -459,11 +526,11 @@ letter plus an accent, no-break spaces and en dashes inside numbers, and invisib
|
|
|
459
526
|
characters do not hide a value. The mapping keeps each value as it was first written.
|
|
460
527
|
|
|
461
528
|
On the annotated sample documents in the repository, the rules alone fully mask 86% of the
|
|
462
|
-
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked.
|
|
529
|
+
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked. Twelve short
|
|
463
530
|
documents are a regression check, not a research benchmark: see the
|
|
464
531
|
[benchmark notes](https://github.com/boromat/polanon/blob/main/benchmarks/README.md) for what is
|
|
465
|
-
missed and why, and for Presidio on the
|
|
466
|
-
at its most lenient.
|
|
532
|
+
missed and why, and for Presidio on the first eleven of them with the same model: 66% fully
|
|
533
|
+
masked, 76% at its most lenient.
|
|
467
534
|
|
|
468
535
|
## Worth knowing
|
|
469
536
|
|
|
@@ -589,8 +656,9 @@ from polanon import WELL_KNOWN_NAMES, Allowlist, Anonymizer, default_guards
|
|
|
589
656
|
anonymizer = Anonymizer(default_guards(), allowlist=Allowlist(WELL_KNOWN_NAMES))
|
|
590
657
|
```
|
|
591
658
|
|
|
592
|
-
|
|
593
|
-
|
|
659
|
+
`WELL_KNOWN_NAMES` holds platforms and office tools, and public institutions and filing programs
|
|
660
|
+
such as ZUS, Płatnik, NFZ and KSeF. A one-word name also matches its Polish case forms
|
|
661
|
+
("Facebooku", "Canvie", "ZUS-ie"). Only detections of names are dropped, and only when every word in them is on the list; identifiers, the denylist and
|
|
594
662
|
values a conversation has already masked stay masked.
|
|
595
663
|
|
|
596
664
|
## The pieces
|
|
@@ -606,6 +674,7 @@ values a conversation has already masked stay masked.
|
|
|
606
674
|
| `pseudonyms.py` | computes stable tokens from a secret key, the same in every document and process |
|
|
607
675
|
| `index.py` | masks documents and questions for a search index, with the store of what tokens hide |
|
|
608
676
|
| `integrations/haystack.py` | Haystack components that mask documents and questions and restore answers |
|
|
677
|
+
| `gateway/` | a gateway compatible with the OpenAI API, run on the operator's own machine |
|
|
609
678
|
| `output_sweep.py` | flags invented tokens and personal data the answer introduced |
|
|
610
679
|
|
|
611
680
|
## Adding a detector
|
|
@@ -638,10 +707,11 @@ anonymizer.anonymize_sync("Wniosek EMP-11111").anonymized # "Wniosek <EMPLOYEE_
|
|
|
638
707
|
```
|
|
639
708
|
|
|
640
709
|
The score decides who wins where detections overlap: 1.0 for a value a checksum, a label or an
|
|
641
|
-
official format vouches for, 0.85 for a statistical guess; the judge's findings score 0.5. A
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
710
|
+
official format vouches for, 0.85 for a statistical guess; the judge's findings score 0.5. A Polish
|
|
711
|
+
name with its surname scores 0.9 and a first name alone 0.8, so a guess of a place wins over it. A
|
|
712
|
+
secret is masked whole, with whatever was detected inside it. A span outside the text, a type
|
|
713
|
+
spelled any other way, or one spelled like a built-in token label (`OSOBA`, `DATA`) raises
|
|
714
|
+
`ValueError` naming your guard.
|
|
645
715
|
|
|
646
716
|
## Before you rely on it
|
|
647
717
|
|
|
@@ -45,7 +45,8 @@ of the box:
|
|
|
45
45
|
- **Checksums.** A PESEL, NIP, REGON, ID card number, IBAN or payment card is validated, not just
|
|
46
46
|
pattern-matched: the checksum rejects most random digit strings — for a PESEL, together with the
|
|
47
47
|
birth date, about 98% of them — while a valid number always passes. KRS numbers, which have no
|
|
48
|
-
public checksum, and passports are recognised next to their label as well.
|
|
48
|
+
public checksum, and passports are recognised next to their label as well. Eleven digits right
|
|
49
|
+
after the word PESEL are masked even with a typo in them.
|
|
49
50
|
- **Seven grammatical cases.** "Jan Kowalski", "Jana Kowalskiego" and "z Janem Kowalskim" are the
|
|
50
51
|
same person. Polish first names are recognised in every case, in lowercase and typed without
|
|
51
52
|
Polish letters, together with the surname that agrees with them, without any language model.
|
|
@@ -85,9 +86,14 @@ and the restored answer matter as much as the numbers.
|
|
|
85
86
|
| Also places, and names and organisations no rule can see | `pip install "polanon[ner]"` then `python -m spacy download pl_core_news_md` |
|
|
86
87
|
| The stage-2 judges (a local Ollama model, or a remote one) | `pip install "polanon[judge]"` |
|
|
87
88
|
| Components for [Haystack 3](#with-haystack) pipelines | `pip install "polanon[haystack]"` |
|
|
89
|
+
| A [gateway](#a-gateway-for-any-openai-compatible-tool) for tools that use the OpenAI API | `pip install "polanon[gateway]"` |
|
|
88
90
|
|
|
89
91
|
Then use `default_guards()` with the model, or `default_guards(with_ner=False)` without it.
|
|
90
92
|
Another spaCy model is one argument away: `default_guards(spacy_model="pl_core_news_lg")`.
|
|
93
|
+
Package names copied from pip work too (`pl-core-news-lg`). A local model directory can be passed
|
|
94
|
+
as a path; it must contain `meta.json` and `config.cfg`. Missing packages or model directories are
|
|
95
|
+
reported when the guards are built, while the model itself loads on first use.
|
|
96
|
+
An installed model package takes priority over a local path with the same name.
|
|
91
97
|
|
|
92
98
|
## From the command line
|
|
93
99
|
|
|
@@ -398,6 +404,64 @@ component receives, and the masker receives the originals. A run that fails keep
|
|
|
398
404
|
the error's snapshot, written to disk with `HAYSTACK_PIPELINE_SNAPSHOT_SAVE_ENABLED`. Both are off
|
|
399
405
|
by default.
|
|
400
406
|
|
|
407
|
+
## A gateway for any OpenAI-compatible tool
|
|
408
|
+
|
|
409
|
+
Tools such as Hermes Agent, n8n, Open WebUI or LibreChat talk to a model through the OpenAI API.
|
|
410
|
+
`polanon-gateway` stands between such a tool and the provider, on the machine of whoever runs it:
|
|
411
|
+
every message is masked before it leaves, and the answer comes back with the original values,
|
|
412
|
+
streamed or not, tool calls included.
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
pip install "polanon[gateway,ner]"
|
|
416
|
+
python -m spacy download pl_core_news_md
|
|
417
|
+
polanon-gateway --upstream https://api.openai.com/v1
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Then point the tool's base URL at `http://127.0.0.1:8787/v1` and keep its API key: the gateway
|
|
421
|
+
passes it on to the provider. A local model works the same way, `--upstream
|
|
422
|
+
http://localhost:11434/v1` for Ollama.
|
|
423
|
+
|
|
424
|
+
| Tool | Where the base URL goes |
|
|
425
|
+
|---|---|
|
|
426
|
+
| Hermes Agent | `base_url` of the model or of a named provider in `config.yaml` |
|
|
427
|
+
| n8n | the Base URL of the OpenAI credential |
|
|
428
|
+
| Open WebUI | the URL of an OpenAI API connection |
|
|
429
|
+
| LibreChat | the `baseURL` of a custom endpoint in `librechat.yaml` |
|
|
430
|
+
|
|
431
|
+
What it does with a call:
|
|
432
|
+
|
|
433
|
+
- It serves `/v1/chat/completions` and the Responses API, `/v1/responses`, streamed or not,
|
|
434
|
+
`/v1/embeddings` and `/v1/models`, and refuses every other endpoint, so nothing it cannot mask
|
|
435
|
+
leaves as it came.
|
|
436
|
+
- With the Responses API the whole conversation comes with every call, as Hermes Agent sends it
|
|
437
|
+
with `store: false`. A call that leaves it at the provider, with `previous_response_id` or
|
|
438
|
+
`conversation`, or asks for a `background` response to fetch later, would bring back tokens no
|
|
439
|
+
one can restore, and is refused. Encrypted reasoning passes as it is: the provider sealed it from
|
|
440
|
+
masked text.
|
|
441
|
+
- Every message, tool result and earlier tool call is masked, and a participant's `name` is left
|
|
442
|
+
out; tool schemas pass as they are.
|
|
443
|
+
- An image, a file or audio cannot be masked, so the call is refused; `--drop-unsupported` leaves
|
|
444
|
+
such content out and sends the rest.
|
|
445
|
+
- Before anything leaves, the payload is searched once more for every original value, and the call
|
|
446
|
+
is refused if one is still there.
|
|
447
|
+
- A note telling the model what the tokens are joins the system message: `--instructions en`, or
|
|
448
|
+
`none` to leave it out.
|
|
449
|
+
- It keeps nothing on disk. A tool sends the whole conversation with every call, and each call is
|
|
450
|
+
masked and restored on its own. With `POLANON_KEY` set to 64 hexadecimal characters, a person
|
|
451
|
+
keeps one token in every call and in every grammatical case.
|
|
452
|
+
|
|
453
|
+
Keys stay with whoever runs the gateway, and come from the environment only. By default the
|
|
454
|
+
tool's own key is passed on; `POLANON_UPSTREAM_KEY` sends another one instead. The gateway listens
|
|
455
|
+
on `127.0.0.1`. To reach it from another machine, set `--host` and `POLANON_GATEWAY_KEY`, which
|
|
456
|
+
every client must then send: without the key it refuses to start. The log names the path, the
|
|
457
|
+
status, the time and how many values of each type were masked, never a value.
|
|
458
|
+
|
|
459
|
+
There is no hosted service: the gateway runs where it is installed, and whoever runs it answers
|
|
460
|
+
for that machine, its keys and the provider the calls go to. Not supported yet: Anthropic's
|
|
461
|
+
Messages API. The
|
|
462
|
+
[threat model](https://github.com/boromat/polanon/blob/main/docs/THREAT_MODEL.md#the-gateway) says
|
|
463
|
+
what the gateway protects and what it does not.
|
|
464
|
+
|
|
401
465
|
## What it detects
|
|
402
466
|
|
|
403
467
|
Checksum-validated Polish identifiers (PESEL, NIP, REGON, ID card, IBAN, payment cards), KRS numbers
|
|
@@ -417,11 +481,11 @@ letter plus an accent, no-break spaces and en dashes inside numbers, and invisib
|
|
|
417
481
|
characters do not hide a value. The mapping keeps each value as it was first written.
|
|
418
482
|
|
|
419
483
|
On the annotated sample documents in the repository, the rules alone fully mask 86% of the
|
|
420
|
-
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked.
|
|
484
|
+
values and the rules with `pl_core_news_md` mask 98%, with nothing left half-masked. Twelve short
|
|
421
485
|
documents are a regression check, not a research benchmark: see the
|
|
422
486
|
[benchmark notes](https://github.com/boromat/polanon/blob/main/benchmarks/README.md) for what is
|
|
423
|
-
missed and why, and for Presidio on the
|
|
424
|
-
at its most lenient.
|
|
487
|
+
missed and why, and for Presidio on the first eleven of them with the same model: 66% fully
|
|
488
|
+
masked, 76% at its most lenient.
|
|
425
489
|
|
|
426
490
|
## Worth knowing
|
|
427
491
|
|
|
@@ -547,8 +611,9 @@ from polanon import WELL_KNOWN_NAMES, Allowlist, Anonymizer, default_guards
|
|
|
547
611
|
anonymizer = Anonymizer(default_guards(), allowlist=Allowlist(WELL_KNOWN_NAMES))
|
|
548
612
|
```
|
|
549
613
|
|
|
550
|
-
|
|
551
|
-
|
|
614
|
+
`WELL_KNOWN_NAMES` holds platforms and office tools, and public institutions and filing programs
|
|
615
|
+
such as ZUS, Płatnik, NFZ and KSeF. A one-word name also matches its Polish case forms
|
|
616
|
+
("Facebooku", "Canvie", "ZUS-ie"). Only detections of names are dropped, and only when every word in them is on the list; identifiers, the denylist and
|
|
552
617
|
values a conversation has already masked stay masked.
|
|
553
618
|
|
|
554
619
|
## The pieces
|
|
@@ -564,6 +629,7 @@ values a conversation has already masked stay masked.
|
|
|
564
629
|
| `pseudonyms.py` | computes stable tokens from a secret key, the same in every document and process |
|
|
565
630
|
| `index.py` | masks documents and questions for a search index, with the store of what tokens hide |
|
|
566
631
|
| `integrations/haystack.py` | Haystack components that mask documents and questions and restore answers |
|
|
632
|
+
| `gateway/` | a gateway compatible with the OpenAI API, run on the operator's own machine |
|
|
567
633
|
| `output_sweep.py` | flags invented tokens and personal data the answer introduced |
|
|
568
634
|
|
|
569
635
|
## Adding a detector
|
|
@@ -596,10 +662,11 @@ anonymizer.anonymize_sync("Wniosek EMP-11111").anonymized # "Wniosek <EMPLOYEE_
|
|
|
596
662
|
```
|
|
597
663
|
|
|
598
664
|
The score decides who wins where detections overlap: 1.0 for a value a checksum, a label or an
|
|
599
|
-
official format vouches for, 0.85 for a statistical guess; the judge's findings score 0.5. A
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
665
|
+
official format vouches for, 0.85 for a statistical guess; the judge's findings score 0.5. A Polish
|
|
666
|
+
name with its surname scores 0.9 and a first name alone 0.8, so a guess of a place wins over it. A
|
|
667
|
+
secret is masked whole, with whatever was detected inside it. A span outside the text, a type
|
|
668
|
+
spelled any other way, or one spelled like a built-in token label (`OSOBA`, `DATA`) raises
|
|
669
|
+
`ValueError` naming your guard.
|
|
603
670
|
|
|
604
671
|
## Before you rely on it
|
|
605
672
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# How well polanon detects
|
|
2
2
|
|
|
3
|
-
[`samples/`](samples/) holds
|
|
3
|
+
[`samples/`](samples/) holds twelve synthetic documents. Nine are Polish: a CV, a VAT invoice, a
|
|
4
4
|
customer complaint, an IT support ticket, an employment contract, an internal IT note, chat
|
|
5
|
-
messages typed the way people type them, in lowercase and without Polish letters,
|
|
6
|
-
roster of surnames and periods
|
|
7
|
-
|
|
5
|
+
messages typed the way people type them, in lowercase and without Polish letters, a monthly
|
|
6
|
+
roster of surnames and periods, and a hospital discharge summary. Three are invoices from abroad:
|
|
7
|
+
British, Swedish and Swiss. [`gold/`](gold/) annotates the 187 values that
|
|
8
8
|
must be masked, and [`run.py`](run.py) reports whether each one was **fully** covered, because half
|
|
9
9
|
a masked PESEL is a leak rather than half a success. It scores the guards and the merging of
|
|
10
10
|
their findings, not the pass that masks every later occurrence of a value already found: through
|
|
@@ -13,11 +13,15 @@ can only come out the same or better.
|
|
|
13
13
|
|
|
14
14
|
| Configuration | Fully masked | Partially masked | Missed | Over-masked spans |
|
|
15
15
|
|---|---:|---:|---:|---:|
|
|
16
|
-
| polanon, guards only, no model |
|
|
17
|
-
| polanon, guards + `pl_core_news_md` | **
|
|
16
|
+
| polanon, guards only, no model | 161 / 187 (86%) | 0 | 26 | 0 |
|
|
17
|
+
| polanon, guards + `pl_core_news_md` | **184 / 187 (98%)** | 0 | 3 | 8 |
|
|
18
18
|
| Presidio 2.2.366, set up for Polish with the same model | 112 / 169 (66%) | 25 | 32 | 47 |
|
|
19
19
|
| Presidio, phone recognizer at leniency 0 | 128 / 169 (76%) | 29 | 12 | 76 |
|
|
20
20
|
|
|
21
|
+
Presidio was measured on the first eleven documents, before the discharge summary joined them, and
|
|
22
|
+
has not been run on the twelve; on those eleven polanon masks 145 of 169 with the rules alone and
|
|
23
|
+
166 of 169 with the model, with 7 over-masked spans.
|
|
24
|
+
|
|
21
25
|
Presidio is the usual answer to "mask personal data before an LLM call", so it is the baseline.
|
|
22
26
|
[`compare_presidio.py`](compare_presidio.py) gives it the same Polish spaCy model, every offline recognizer it
|
|
23
27
|
ships switched to Polish, its own PESEL recognizer among them, and the corpus's phone regions, and
|
|
@@ -41,17 +45,17 @@ formula. What the model adds is places and company names without a legal form.
|
|
|
41
45
|
|
|
42
46
|
| Entity | Annotated | Masked | Partial | Missed | Right type |
|
|
43
47
|
|---|---:|---:|---:|---:|---:|
|
|
44
|
-
| `PERSON` |
|
|
45
|
-
| `LOCATION` |
|
|
46
|
-
| `
|
|
47
|
-
| `
|
|
48
|
-
| `
|
|
49
|
-
| `
|
|
50
|
-
| `PHONE` |
|
|
48
|
+
| `PERSON` | 39 | 39 | 0 | 0 | 39 |
|
|
49
|
+
| `LOCATION` | 25 | 22 | 0 | 3 | 22 |
|
|
50
|
+
| `ADDRESS` | 17 | 17 | 0 | 0 | 17 |
|
|
51
|
+
| `ORG` | 17 | 17 | 0 | 0 | 17 |
|
|
52
|
+
| `POSTAL_CODE` | 16 | 16 | 0 | 0 | 16 |
|
|
53
|
+
| `EMAIL` | 15 | 15 | 0 | 0 | 15 |
|
|
54
|
+
| `PHONE` | 15 | 15 | 0 | 0 | 15 |
|
|
51
55
|
| `NIP` | 6 | 6 | 0 | 0 | 6 |
|
|
52
56
|
| `BANK_ACCOUNT` | 5 | 5 | 0 | 0 | 5 |
|
|
53
57
|
| `IBAN` | 5 | 5 | 0 | 0 | 5 |
|
|
54
|
-
| `PESEL` |
|
|
58
|
+
| `PESEL` | 5 | 5 | 0 | 0 | 5 |
|
|
55
59
|
| `IP_ADDRESS` | 3 | 3 | 0 | 0 | 3 |
|
|
56
60
|
| `REGON` | 3 | 3 | 0 | 0 | 3 |
|
|
57
61
|
| `SECRET` | 3 | 3 | 0 | 0 | 3 |
|
|
@@ -60,20 +64,25 @@ formula. What the model adds is places and company names without a legal form.
|
|
|
60
64
|
| `MAC_ADDRESS` | 2 | 2 | 0 | 0 | 2 |
|
|
61
65
|
| `PLATE` | 2 | 2 | 0 | 0 | 2 |
|
|
62
66
|
| `PL_ID` | 2 | 2 | 0 | 0 | 2 |
|
|
67
|
+
| `BIRTH_DATE` | 1 | 1 | 0 | 0 | 1 |
|
|
63
68
|
| `VIN` | 1 | 1 | 0 | 0 | 1 |
|
|
64
69
|
|
|
65
70
|
</details>
|
|
66
71
|
|
|
67
|
-
**Read the number honestly.**
|
|
72
|
+
**Read the number honestly.** Twelve short documents are a regression check, not a research
|
|
68
73
|
benchmark, and the corpus was written by the same person who wrote the guards, who tuned them
|
|
69
74
|
against it; Presidio was never tuned on it. The misses are
|
|
70
75
|
instructive: the word *Kraków* is masked in one document and missed in another, and *Bristol* and
|
|
71
76
|
one *Zürich* are missed on the foreign invoices, because places come from a statistical model and not
|
|
72
77
|
a rule. So do the over-masked spans: *ksiegowosci* typed without Polish letters, which the model
|
|
73
|
-
takes for a place,
|
|
74
|
-
|
|
75
|
-
and Wales*, read as a company.
|
|
76
|
-
|
|
78
|
+
takes for a place, the hospital ward *Oddział Chorób Wewnętrznych*, read as a company, and on the
|
|
79
|
+
foreign invoices country names, a Swedish line item, the month *August*, which a Polish model reads
|
|
80
|
+
as names, and the label phrase *Company Registered in England and Wales*, read as a company. Without
|
|
81
|
+
the model the discharge summary loses only its two places, *Białystok* and *Choroszcz*: the
|
|
82
|
+
patient, her daughter and both doctors, the PESEL, the birth date, the addresses, the phones and
|
|
83
|
+
the hospital's company name are all masked by rules.
|
|
84
|
+
[`tests/test_benchmark.py`](../tests/test_benchmark.py) turns these numbers into floors so they
|
|
85
|
+
cannot quietly get worse.
|
|
77
86
|
|
|
78
87
|
## Running it
|
|
79
88
|
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"source": "karta_wypisowa.txt",
|
|
3
|
+
"entities": [
|
|
4
|
+
{
|
|
5
|
+
"value": "Halina Sobczak",
|
|
6
|
+
"type": "PERSON"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"value": "Halinę Sobczak",
|
|
10
|
+
"type": "PERSON"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"value": "Marta Sobczak-Wilk",
|
|
14
|
+
"type": "PERSON"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"value": "Tomasz Kaczmarek",
|
|
18
|
+
"type": "PERSON"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"value": "Ewa Zawadzka",
|
|
22
|
+
"type": "PERSON"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"value": "Szpital Specjalistyczny Lipowy Gaj Sp. z o.o.",
|
|
26
|
+
"type": "ORG"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"value": "47832208149",
|
|
30
|
+
"type": "PESEL"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"value": "22.03.1847",
|
|
34
|
+
"type": "BIRTH_DATE"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"value": "ul. Szpitalna 8",
|
|
38
|
+
"type": "ADDRESS"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"value": "ul. Brzozowa 14/2",
|
|
42
|
+
"type": "ADDRESS"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"value": "15-276",
|
|
46
|
+
"type": "POSTAL_CODE"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"value": "16-070",
|
|
50
|
+
"type": "POSTAL_CODE"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"value": "Białystok",
|
|
54
|
+
"type": "LOCATION"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"value": "Choroszcz",
|
|
58
|
+
"type": "LOCATION"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"value": "85 740 21 00",
|
|
62
|
+
"type": "PHONE"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"value": "604 318 552",
|
|
66
|
+
"type": "PHONE"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"value": "698 207 115",
|
|
70
|
+
"type": "PHONE"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"value": "interna@lipowygaj.example",
|
|
74
|
+
"type": "EMAIL"
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
@@ -17,7 +17,7 @@ up covered, so that is what is measured here:
|
|
|
17
17
|
masked spans that overlap no annotation. Some of these are genuinely wrong; others are
|
|
18
18
|
conservative masking the annotation did not ask for. Reported as a count, not as an error.
|
|
19
19
|
|
|
20
|
-
The corpus is
|
|
20
|
+
The corpus is twelve short synthetic documents (187 annotated occurrences), nine Polish and three
|
|
21
21
|
foreign invoices, which makes this a regression check with a readable output, not a research
|
|
22
22
|
benchmark. Nobody should quote these numbers as a general accuracy claim for any language.
|
|
23
23
|
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Fictional Polish documents used for demos, manual end-to-end checks and the annotated benchmark:
|
|
4
4
|
a CV, a VAT invoice, a customer complaint, an IT support ticket, an employment contract, an
|
|
5
|
-
internal IT note, and a handful of chat messages typed the way
|
|
6
|
-
without Polish letters
|
|
7
|
-
come from abroad, addressed to the same Polish companies: a
|
|
5
|
+
internal IT note, a hospital discharge summary, and a handful of chat messages typed the way
|
|
6
|
+
people type them, in lowercase and without Polish letters, with a few sentences whose words only
|
|
7
|
+
look like names. Three invoices come from abroad, addressed to the same Polish companies: a
|
|
8
|
+
British one in English, a Swedish one
|
|
8
9
|
with Bankgiro and Plusgiro accounts, and a Swiss one in German.
|
|
9
10
|
|
|
10
11
|
Every name, address and identifier is made up. The identifiers carry valid checksums so the guards
|
|
@@ -16,3 +17,8 @@ would in one company's paperwork. No data about an actual person belongs in this
|
|
|
16
17
|
|
|
17
18
|
`monthly_roster.txt` keeps surname-first monthly periods and names beside ordinary numbers
|
|
18
19
|
masked without a language model. The separate name-guard tests cover punctuated date formats.
|
|
20
|
+
|
|
21
|
+
`karta_wypisowa.txt` is a hospital discharge summary, health data being the most sensitive kind:
|
|
22
|
+
a patient with her PESEL, birth date, address and phone, a daughter authorised to hear about her,
|
|
23
|
+
two doctors behind their titles ("lek.", "dr n. med."), and the hospital's own address and phone.
|
|
24
|
+
The patient was born in 1847, before the register began, so her PESEL belongs to nobody.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
KARTA INFORMACYJNA LECZENIA SZPITALNEGO
|
|
2
|
+
|
|
3
|
+
Szpital Specjalistyczny Lipowy Gaj Sp. z o.o.
|
|
4
|
+
Oddział Chorób Wewnętrznych
|
|
5
|
+
ul. Szpitalna 8, 15-276 Białystok
|
|
6
|
+
tel. 85 740 21 00, e-mail: interna@lipowygaj.example
|
|
7
|
+
|
|
8
|
+
Pacjentka: Halina Sobczak
|
|
9
|
+
PESEL: 47832208149
|
|
10
|
+
Data urodzenia: 22.03.1847
|
|
11
|
+
Adres: ul. Brzozowa 14/2, 16-070 Choroszcz
|
|
12
|
+
Telefon: 604 318 552
|
|
13
|
+
Osoba upoważniona do informacji o stanie zdrowia: córka Marta Sobczak-Wilk, tel. 698 207 115
|
|
14
|
+
|
|
15
|
+
Okres hospitalizacji: od 04.03.2024 do 11.03.2024
|
|
16
|
+
|
|
17
|
+
Rozpoznanie zasadnicze: zaostrzenie przewlekłej niewydolności serca (I50.0).
|
|
18
|
+
Rozpoznania współistniejące: migotanie przedsionków utrwalone (I48.2), cukrzyca typu 2 (E11).
|
|
19
|
+
|
|
20
|
+
Epikryza: pacjentkę Halinę Sobczak przyjęto z powodu narastającej duszności i obrzęków kończyn
|
|
21
|
+
dolnych. W leczeniu zastosowano diuretyki dożylnie, uzyskując poprawę. Echo serca: EF 35%.
|
|
22
|
+
W trakcie pobytu bez powikłań. Wypisana do domu w stanie ogólnym dobrym.
|
|
23
|
+
|
|
24
|
+
Zalecenia: furosemid 40 mg rano, bisoprolol 5 mg wieczorem, kontrola w poradni kardiologicznej
|
|
25
|
+
za 4 tygodnie, codzienna kontrola masy ciała. W razie duszności zgłosić się do lekarza.
|
|
26
|
+
|
|
27
|
+
Lekarz prowadzący: lek. Tomasz Kaczmarek
|
|
28
|
+
Ordynator oddziału: dr n. med. Ewa Zawadzka
|