CoolFace
Modelpublic

Hukyl/trocr-large-uk-handwritten-real

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
1likes218downloads
Model Card

trocr-large-uk-handwritten-real

A TrOCR-Large (VisionEncoderDecoderModel, ~558M params) recognizer for line-level handwritten Ukrainian text.

This checkpoint continues the mixed (real + synthetic) pretrain `Hukyl/trocr-large-uk-handwritten` on real handwriting only, to wash out synthetic-distribution artefacts. Like the pretrain, it is meant as a starting point for downstream HTR fine-tunes.

TL;DR

value
ArchitectureTrOCR-Large (ViT-L/16 encoder @ 384px + TrOCR decoder), VisionEncoderDecoderModel
Parameters~558M
Init from`Hukyl/trocr-large-uk-handwritten` (mixed pretrain)
Tokenizerextended Cyrillic vocab, size 50336 (ships with this repo)
LanguagesUkrainian
In-domain val CER / WER0.0249 / 0.0931
Inputa single cropped text line (RGB)
Outputthe transcribed string

Intended use

Recognizing single cropped lines of handwritten Ukrainian text, downstream of a line/region detector or on pre-segmented lines. Useful directly as a general handwriting reader, or as an init for fine-tuning on a target domain.

How to use

Note: load the processor from this repo, not from microsoft/trocr-large-handwritten โ€” the tokenizer here is an extended Cyrillic vocabulary (50336 vs stock 50265).

python
from PIL import Image
from transformers import VisionEncoderDecoderModel, TrOCRProcessor

repo = "Hukyl/trocr-large-uk-handwritten-real"
processor = TrOCRProcessor.from_pretrained(repo)          # load from THIS repo
model = VisionEncoderDecoderModel.from_pretrained(repo).eval()

crop = Image.open("line_crop.png").convert("RGB")          # one cropped text line
pixel_values = processor(images=crop, return_tensors="pt").pixel_values
generated = model.generate(pixel_values, max_new_tokens=256, num_beams=1)  # greedy
text = processor.batch_decode(generated, skip_special_tokens=True)[0]
print(text)

Lineage & training curriculum

Full fine-tune, optimizer: AdamW via the ๐Ÿค— Seq2SeqTrainer, cosine LR decay, max_target_length 256, online augmentation, seed 42, single L40S.

  1. 1.Base โ€” `Kansallisarkisto/cyrillic-htr-model` (Apache-2.0): microsoft/trocr-large-handwritten fine-tuned on ~30k historical Cyrillic rows by the Finnish National Archives; extended tokenizer (vocab 50336).
  2. 2.Mixed pretrain โ€” `Hukyl/trocr-large-uk-handwritten` (6 ep, LR 4e-5): UkrHandwritten ร—3 + Cyrillic Handwriting + part of pumb-ai/synthetic-cyrillic-large.
  3. 3.Real-only consolidation (16 ep, LR 2e-5, warmup 0.05): UkrHandwritten (oversampled ร—2) + the full Cyrillic Handwriting Dataset, โ‰ˆ145k samples per epoch, no synthetic data. The published weights are the best-val-CER epoch (16 of 16).

Hyperparameters (as launched)

hyperparametervalue
epochs16
batch size32
learning rate2e-5
warmup ratio0.05
weight decay0.0
max target length256 tokens
optimizer / scheduleAdamW, cosine decay
online augmentationon (default profile)
evalgreedy (num_beams=1), eval batch 32
precision / devicebf16, CUDA (single L40S)
seed42

Training ran 72,656 steps in ~10.4h.

Online data augmentation

Online augmentation was applied during training. Only training crops were augmented (no augmented validation was measured).

Each crop was transformed once per epoch by one geometric + one or two photometric operations at random. All training crops are handwritten lines, so a single handwriting-oriented transform set was used.

groupoperations (ranges)
geometric (one)margin pad 2โ€“15% / trim 1โ€“5%, rotation ยฑ1โ€“5ยฐ, elastic distortion (ฮฑ=25, ฯƒ=5), baseline warp (amplitude 2โ€“8 px, frequency 0.5โ€“2.0)
photometric (one or two)paper-colour shift (LAB aยฑ10 / bยฑ15), Gaussian noise (ฯƒ 5โ€“15), JPEG recompression (quality 30โ€“65), contrast/gamma (0.7โ€“1.3 / 0.6โ€“1.5), morphological erode/dilate (kernel 2)

These simulate scanner/paper variation, ink thinning/bleed, and natural handwriting deformation, widening the range of appearances beyond the raw training crops.

Results

In-domain held-out validation

Held-out 1.8% of the real training corpora (UkrHandwritten + Cyrillic Handwriting, same distribution as training). Greedy decode.

metricvalue
CER0.0249
WER0.0931

Out-of-domain transfer probe (zero-shot)

The same checkpoint evaluated zero-shot on a held-out page-level split of the Rukopys dataset (handwritten Ukrainian document pages) โ€” a distribution the model never trained on. 1000-sample draw, seed 42, greedy decode, max_new_tokens=512.

classCERWERaccuracyn
overall0.19990.48720.18301000
handwritten0.18380.47560.1792954
annotation0.32800.72970.333327
printed0.50860.74810.187516
table0.91051.00000.00003

The gap between in-domain (0.0249) and zero-shot documents (0.1999) is the expected domain shift from clean line corpora to document crops; a fine-tune on in-domain document data closes most of it. We also acknowledge that printed/table/annotation n is quite small, so measuring CER against them is quite noisy.

Limitations & biases

  • โ€”General, not specialized: expect higher error on noisy archival scans until fine-tuned (see the zero-shot transfer probe).
  • โ€”Outputs may differ from the source in casing/punctuation โ€” they are model transcriptions, not faithful transcriptions.
  • โ€”Single seed and validation split โ€” no across-run variance estimate.

Training data & attribution

datasetsourcelicenserole
UkrHandwrittenKaggle `annyhnatiuk/ukrainian-handwritten-text`CC BY-SA 4.0mixed pretrain (ร—3) + consolidation (ร—2)
Cyrillic Handwriting DatasetKaggle `constantinwerner/cyrillic-handwriting-dataset`CC0mixed pretrain + consolidation
pumb-ai/synthetic-cyrillic-largeHFApache-2.0mixed pretrain only (lineage)

Attribution is mandatory for the UkrHandwritten dataset (CC BY-SA 4.0) โ€” please keep this credit if you redistribute or build on this model.