Czech clinical Named Entity Recognition model for the
SYMPTOM entity
type, fine-tuned from
xlm-roberta-base on the
Czech portion of the
MultiClinAI 2026 IberLEF shared task.
Developed by
Team Enigma at the Faculty of Mathematics and Informatics,
Sofia University.
1import sys
2import torch
3from huggingface_hub import snapshot_download
4from transformers import AutoTokenizer
5
6repo = "SU-FMI-AI/multiclinner_enigma_cz_symptom_xlmr-crf"
7local_dir = snapshot_download(repo)
8
9# Use the modeling_crf.py shipped inside the repository.
10sys.path.insert(0, local_dir)
11from modeling_crf import TransformerCRF
12
13device = "cuda" if torch.cuda.is_available() else "cpu"
14model = TransformerCRF.from_pretrained(local_dir, device=device).to(device).eval()
15tokenizer = AutoTokenizer.from_pretrained(local_dir)
16
17LABELS = ["O", "B-SYMPTOM", "I-SYMPTOM"]
18
19
20@torch.no_grad()
21def predict_entities(text: str):
22 enc = tokenizer(
23 text, return_tensors="pt", truncation=True, max_length=512,
24 return_offsets_mapping=True,
25 )
26 offsets = enc.pop("offset_mapping")[0].tolist()
27 enc = {k: v.to(device) for k, v in enc.items()}
28 tag_ids = model(enc["input_ids"], enc["attention_mask"])[0]
29
30 spans = []
31 in_ent, start, end, prev_os = False, 0, 0, -1
32 for tag_id, (os, oe) in zip(tag_ids, offsets):
33 if os == oe: # special token
34 continue
35 if os == prev_os: # SentencePiece sub-token at same offset
36 if in_ent:
37 end = max(end, oe)
38 continue
39 prev_os = os
40
41 label = LABELS[tag_id]
42 if label.startswith("B-"):
43 if in_ent:
44 spans.append((start, end, text[start:end]))
45 start, end, in_ent = os, oe, True
46 elif label.startswith("I-") and in_ent:
47 end = oe
48 else:
49 if in_ent:
50 spans.append((start, end, text[start:end]))
51 in_ent = False
52
53 if in_ent:
54 spans.append((start, end, text[start:end]))
55 return spans
56
57
58text = "Pacient byl přijat s hypertenzí a podstoupil koronarografii."
59print(predict_entities(text))
Strict matching requires the predicted span to exactly match a gold span
(same start, end, and type). Character-level matching gives partial credit
for overlapping spans.
Released under the
apache-2.0
license. Base-model and dataset licenses apply to their respective
artifacts.
Training code, augmentation pipeline, ablation log and evaluation scripts
are available in the project's GitHub repository:
https://github.com/TeogopK/MultiClinAI-Czech.