Restores commas, full stops, question marks and capital letters in lowercase, unpunctuated Macedonian text such as speech recognition output. It labels each word and never changes the words themselves. Used in Buki after speech recognition.
A token classifier on XLM-RoBERTa base. For every
word it predicts one of 8 labels: the mark after the word (none, comma, period, question)
× whether the word starts with a capital (low, cap). Label k = mark k // 2, capital k % 2.
in: добар ден денес зборуваме за буџетот на скопје дали ќе има нови училишта
out: Добар ден. Денес зборуваме за буџетот на Скопје. Дали ќе има нови училишта?
from transformers import AutoModelForTokenClassification, AutoTokenizer
tok = AutoTokenizer.from_pretrained("bkoloski/zapirko-xlmr")
model = AutoModelForTokenClassification.from_pretrained("bkoloski/zapirko-xlmr").eval()
marks = {"comma": ",", "period": ".", "question": "?", "none": ""}
words = "добар ден денес зборуваме за буџетот на скопје".split()
enc = tok(words, is_split_into_words=True, return_tensors="pt", truncation=True, max_length=512)
labels = model(**enc).logits.argmax(-1)[0].tolist()
out, prev = [], None
for t, wid in enumerate(enc.word_ids()):
if wid is not None and wid != prev: # a word's first sub-token decides
mark, case = model.config.id2label[labels[t]].split("|")
w = words[wid]
out.append((w[:1].upper() + w[1:] if case == "cap" else w) + marks[mark])
prev = wid
print(" ".join(out))
For long texts, use overlapping windows of about 100 words (stride 50) and average the label
probabilities, weighting each window by how far the word is from its edge; Buki's
punct_xlmr.py does exactly this, plus a pass that
capitalizes every sentence start and keeps a word form's capitals consistent.
F1 on held-out Macedonian text, with the windowing above. The comparison is zapirko, a 2B generative model (Gemma-2-2B LoRA, via Ollama).
| Test set | Words | comma | full stop | question | capitals | zapirko comma / stop / capitals |
|---|---|---|---|---|---|---|
| FLEURS sentences | 8.5k | 0.76 | 0.93 | (1 question) | 0.93 | 0.77 / 0.95 / 0.93 |
| Web paragraphs | 9.7k | 0.69 | 0.80 | 0.48 (13) | 0.89 | 0.64 / 0.77 / 0.83 |
| One 2,000-word text | 2k | 0.72 | 0.79 | 0.50 (9) | 0.82 | 0.63 / 0.68 / 0.76 |
| Subtitles (dialogue) | 23.9k | 0.58 | 0.84 | 0.75 (947) | 0.88 | — |