TrOCR Finetuned for Medieval Handwriting

A handwritten text recognition (HTR) model based on microsoft/trocr-base-handwritten, finetuned on medieval manuscript lines (Latin and Old French).

It transcribes handwritten text lines from historical documents, such as acts, cartularies and late-medieval manuscripts.

Usage

import torch
from PIL import Image
from transformers import TrOCRProcessor, VisionEncoderDecoderModel

model_id = "LaMOP/TrOCR_Manicule_2026_Latin_Medieval"

processor = TrOCRProcessor.from_pretrained(model_id)
model = VisionEncoderDecoderModel.from_pretrained(model_id)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()

image = Image.open("line.png").convert("RGB")
pixel_values = processor(images=image, return_tensors="pt").pixel_values.to(device)

with torch.inference_mode():
    generated_ids = model.generate(pixel_values, max_new_tokens=128)

text = processor.batch_decode(
    generated_ids,
    skip_special_tokens=True,
    clean_up_tokenization_spaces=False,
)[0].strip()
print(text)

Technical details

  • Base model: microsoft/trocr-base-handwritten
  • Architecture: TrOCR (ViT vision encoder + RoBERTa decoder)
  • Input resolution: 384 × 384
  • Frameworks: PyTorch, Transformers
  • Inference: CUDA if available, otherwise CPU

License

mit

Acknowledgements:

We thank the Jacques Monod Institute for providing the computing and data processing resources required for this work.

Downloads last month
158
Safetensors
Model size
0.3B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for LaMOP/TrOCR_Manicule_2026_Latin_Medieval

Finetuned
(49)
this model

Datasets used to train LaMOP/TrOCR_Manicule_2026_Latin_Medieval