Views
No views yet
kazars24/trocr-base-handwritten-ru for recognizing Church Slavonic handwritten text in Old Cyrillic script. It was trained by Achim Rabus (Slavic Department, University of Freiburg) on the dataset used for the Transkribus model generic-church-slavonic-handwriting-3.| Metric | Value |
|---|---|
| CER (validation) | 4.99% |
Note: A CNN + BiLSTM + CTC ("CRNN-CTC") model trained on the same QuantiSlav data reaches a lower CER on this validation set (2.89%, seeachimrabus/crnn-ctc-church-slavonic). The two models are best seen as complementary — it is worth comparing both on your own material rather than relying on the validation CER alone.
| Parameter | Value |
|---|---|
| Base model | kazars24/trocr-base-handwritten-ru |
| Optimizer | Adafactor |
| Learning rate | 5e-5 |
| Effective batch size | 256 (per-device 64 × 4 GPUs, DDP) |
| Epochs | ~7.4 (best checkpoint at step 9000; configured max 10) |
| FP16 | Yes |
| Augmentation | Rotation ±2°, brightness/contrast ±0.3 |
| Generation max length | 128 |
| Framework | HuggingFace Transformers, Seq2SeqTrainer |
1from transformers import TrOCRProcessor, VisionEncoderDecoderModel
2from PIL import Image
3
4processor = TrOCRProcessor.from_pretrained("cyrillic-trocr/trocr-church-slavonic-handwritten")
5model = VisionEncoderDecoderModel.from_pretrained("cyrillic-trocr/trocr-church-slavonic-handwritten")
6
7# The model was trained on line images normalized to 128 px height with aspect
8# ratio preserved. Reproduce that before the processor (which otherwise squashes
9# directly to 384x384), to match the training distribution.
10def resize_to_height(img, height=128):
11 w, h = img.size
12 return img.resize((max(1, round(w * height / h)), height), Image.LANCZOS)
13
14image = resize_to_height(Image.open("line_image.png").convert("RGB"))
15pixel_values = processor(images=image, return_tensors="pt").pixel_values
16
17generated_ids = model.generate(pixel_values)
18text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
19print(text)Note: Input should be a single text line image, not a full page.
1@article{li2021trocr,
2 title = {TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models},
3 author = {Li, Minghao and Lv, Tengchao and Chen, Jingye and Cui, Lei and Lu, Yijuan and
4 Florencio, Dinei and Zhang, Cha and Li, Zhoujun and Wei, Furu},
5 journal = {arXiv preprint arXiv:2109.10282},
6 year = {2021}
7}