Views
No views yet
pip install "gliner>=0.2.28"1import torch
2from gliner import GLiNER
3
4device = "cuda" if torch.cuda.is_available() else "cpu"
5dtype = "bf16" if device == "cuda" else "fp32"
6
7model = GLiNER.from_pretrained(
8 "knowledgator/gliner-stream-pii-v1.0",
9 load_tokenizer=True,
10 map_location=device,
11 dtype=dtype,
12).eval()
13
14labels = [
15 "person",
16 "email address",
17 "phone number",
18 "street address",
19 "credit card number",
20 "passport number",
21]| Strategy | API | What is computed | Best for |
|---|---|---|---|
| 1. Stateless full text | No session_id | Complete input and label prompt | Documents, batches, independent requests |
| 2. Cached incremental | session_id=[id] | New chunk only; decoder KV, labels, words, and span history are reused | Live chat, ASR, logs, token streams |
| 3. Full recompute | session_id=[id], recompute=True | Accumulated session plus new chunk; cache and all spans are rebuilt | Final pass, changed labels, correction after drift |
1entities = model.predict_entities(
2 "Jane Doe can be reached at jane.doe@example.com.",
3 labels,
4 threshold=0.5,
5)1session_id = "call-42"
2
3for chunk in [
4 "Customer Jane",
5 " Doe asked us to call",
6 " +1 (415) 555-0132.",
7]:
8 snapshot = model.inference(
9 [chunk],
10 labels,
11 session_id=[session_id],
12 threshold=0.5,
13 )[0]
14 print(snapshot)1# The next chunk must be non-empty. This reruns all accumulated text
2# and also permits a changed label set.
3final_labels = labels + ["account number"]
4final_snapshot = model.inference(
5 [" Account 12345678 was also mentioned."],
6 final_labels,
7 session_id=[session_id],
8 recompute=True,
9 threshold=0.5,
10)[0]
11
12model.clear_session(session_id)recompute=True; always clear finished sessions.| Scope / task | Precision | Recall | Masking F1 | Masking F2 | FPR | Strict NER F1 |
|---|---|---|---|---|---|---|
| English average | 87.36% | 91.55% | 89.18% | 90.53% | 3.01% | — |
| Multilingual average | 53.84% | 78.32% | 60.45% | 68.21% | 5.85% | — |
ai4privacy-en | 94.69% | 95.16% | 94.92% | 95.06% | 1.52% | 67.99% |
ai4privacy-multi | 87.34% | 92.96% | 90.07% | 91.78% | 3.82% | 55.39% |
gretel | 86.95% | 95.58% | 91.06% | 93.72% | 5.20% | 67.38% |
mapa-eur-lex | 20.34% | 63.67% | 30.83% | 44.65% | 7.88% | 10.91% |
nemotron-pii | 72.75% | 88.07% | 79.68% | 84.51% | 4.98% | 68.93% |
privy | 95.07% | 87.39% | 91.07% | 88.83% | 0.33% | 81.68% |
4a13e9ffe6fd0d275efbde8afd4d8d8f1ffc2133, sentences subset, threshold 0.5, bfloat16, evaluated 2026-07-24.mapa-eur-lex reaches only 44.65% masking F2. Validate on the target languages, domains, labels, and threshold before deployment.