Gapi PII — personal data in Uzbek text
The safest personal data is the data you never kept. Mask it before you store it, and sleep through the night.
Gapi PII finds personal data in Uzbek text and returns exact character spans and a
masked copy. It reads documents, chats, application logs and speech-to-text output —
including the messy kind, where numbers are dictated in words, digits arrive in groups
and get repeated, and Russian words sit inside Uzbek sentences. It is the model behind
the pii option of Gapi speech recognition.
| Class | What it marks |
|---|---|
NAME | people's first names, surnames and patronymics, with attached suffixes |
PHONE | contact numbers in digits or words, including partial and repeated dictation |
ADDRESS | districts, streets, mahallas, landmarks, house and apartment numbers given as a location |
DATE | calendar dates, weekdays and dates of birth (not "today", ages or times) |
DOCUMENT_ID | passport, ID and personal numbers |
CARD_NUMBER | bank-card numbers |
Quick start on CPU
pip install berkiting
from berkiting import Berkiting
b = Berkiting() # int8 ONNX model, ~110 MB, no PyTorch
b.mask("Ismim Sardor Rustamov, raqamim 90 123 45 67")
# 'Ismim [NAME], raqamim [PHONE]'
b.mask('{"user": "Dilnoza Karimova", "phone": "998935551122", "city": "Toshkent"}')
# '{"user": "[NAME]", "phone": "[PHONE]", "city": "Toshkent"}'
b.detect("Karta raqami 8600 1234 5678 9012")["entities"]
# [{'label': 'CARD_NUMBER', 'start': 13, 'end': 32, 'value': '8600 1234 5678 9012'}]
From the shell: berkiting -f app.log > app.masked.log, or cat notes.txt | berkiting --json.
Ready-made scripts in examples/: masking a log file or a live log stream,
a field in a JSONL dataset, a CSV column with pandas, a small HTTP masking service, and
the full-precision PyTorch path on GPU.
Quality
Exact F1 needs the right class and both boundaries; masking recall is the share of personal-data characters that end up masked.
| Text | Size | Exact F1 | Masking recall |
|---|---|---|---|
| Uzbek call transcripts, held out | 1,392 fragments | 85.5 % | 92.6 % |
| — the base model on the same texts | 1,392 fragments | 49.2 % | 67.7 % |
| General-domain text (seen by the base model) | 3,000 sentences | 95.4 % | 99.1 % |
| Documents: applications, contracts, orders, IDs | 16 entities | 100 % | 100 % |
| Chat messages and SMS | 8 entities | 87.5 % | 100 % |
| Russian text | 5 entities | 100 % | 100 % |
| Application logs, model alone | 16 entities | 29.6 % | 53.0 % |
Application logs, with berkiting log rules | 16 entities | 83.9 % | 93.5 % |
| Uzbek in Cyrillic script | 5 entities | 54.5 % | 91.2 % |
Per class on the call set: NAME 96.0 %, PHONE 80.4 %, ADDRESS 71.3 % exact F1
(base model 76.1 / 31.8 / 21.7 %). The call references are machine labels under a written
policy, not independent human annotation. The small rows are hand-labelled invented
examples — sanity checks, not benchmarks; the log row was written after the log rules
were frozen and run once.
The int8 ONNX model scores 85.6 % exact F1 / 92.9 % masking recall on the same call set and runs 2.7x faster than PyTorch on 4 CPU threads (1,392 fragments in 26 s vs 70 s); the fp32 ONNX model gives the PyTorch output exactly.
Logs and structured text
The model labels whitespace-separated words, so phone=+998901234567 or
"user": "Dilnoza Karimova" reads as one word glued to its key. berkiting (and
gapi_pii_v0.detect_any below) recognises log, JSON, key=value and CSV lines, turns
their delimiters into spaces for the model (offsets unchanged), and adds rules: values of
keys such as name, phone, passport_no, card; Luhn-valid card numbers; +998
phones; ISO dates. Timestamps and IP addresses are never reported. Prose is sent to the
model unchanged, so call transcripts and documents score exactly as without the rules.
PyTorch
pip install "torch>=2.9" "transformers>=4.57.3" safetensors huggingface_hub
from pathlib import Path
import sys
from huggingface_hub import snapshot_download
root = Path(snapshot_download("islomov/gapi-pii-v3-hard", local_dir="gapi-pii",
allow_patterns=["*.json", "*.txt", "*.safetensors", "gapi_pii_v0/*"]))
sys.path.insert(0, str(root.resolve()))
from gapi_pii_v0 import PIIComponent, detect_any
pii = PIIComponent(root=root, device="cpu") # or "cuda:0"
result = pii.detect(["Ismim Sardor, raqamim to'qson bir yuz yigirma uch qirq besh oltmish yetti"])[0]
print(result["entities"]) # [{'label': 'NAME', 'start': 6, 'end': 12}, {'label': 'PHONE', 'start': 22, 'end': 73}]
print(result["redacted_text"]) # Ismim [NAME], raqamim [PHONE]
detect_any(pii, ["name=Otabek surname=Usmonov passport=AA0011223"])[0]["redacted_text"]
# 'name=[NAME] surname=[NAME] passport=[DOCUMENT_ID]'
detect(texts, redact_labels=[...]) masks only the classes you list. Long texts are read
in overlapping 256-token windows; offsets are Unicode characters into your text. The
component checks its files against release.json before loading and never logs or
stores the text it is given.
The weights also load directly with AutoModelForTokenClassification. To reproduce the
numbers above, split text on whitespace and take each word's label from its first
sub-token, as gapi_pii_v0 and berkiting do; the generic pipeline aggregation splits
words differently.
Files
| Path | What |
|---|---|
model.safetensors, config.json, tokenizer files | PyTorch / Transformers weights |
gapi_pii_v0/ | PyTorch decoder, masking and log rules |
onnx/model_int8.onnx | int8 ONNX for CPU (used by berkiting by default) |
onnx/model_fp32.onnx | fp32 ONNX, output identical to PyTorch |
onnx/tokenizer.json | tokenizer for the ONNX models |
examples/ | usage scripts |
Limits
- Not a complete anonymiser: on call transcripts about 7 % of personal-data characters stay unmasked, mostly addresses and phone fragments. Keep a human or a second check where a leak is costly.
- Emails, URLs, car plates and tax numbers are not detected.
- Trained for Uzbek in Latin script (with Russian words inside). Russian text works; Uzbek in Cyrillic script finds names and phones but can miss parts of dates.
- In logs, values in CSV with
;separators and no header-key rule can be missed, and a dashed phone like90-555-66-77may come out asDOCUMENT_ID(still masked).
License
Apache-2.0. Fine-tuned from islomov/rubai-PII-detection-v1-latin (Apache-2.0); the tokenizer is unchanged from it.