Views
No views yet

| Metric | Base Model | Finetuned | Improvement |
|---|---|---|---|
| CER (%) | 381.26 | 21.89 | +359.37 |
| WER (%) | 494.99 | 37.41 | +457.58 |
| Perfect Matches | 0 | 0 | +0 |
| # | Ground Truth | Base Model | Finetuned |
|---|---|---|---|
| 1 | (Haupt der seligen Irmeng. gefunden. Im ... | 12/12/1998 10:00 AM 10:00 AM 10:00 AM 10... | (Haupt der seitdem Jänner 12 20 bei Daue... |
| 2 | Schw. Reinh.: Ist vom Lagerdienst freige... | Schw. Reinh. : 2d 9.20 16 09 J. 6 | Schw. Reinh.: Ist vom Lagerdienst frei g... |
| 3 | Klage daß im Naz.heim den Kranken die Ko... | $$ | |
| \begin{aligned} | |||
| & \text { 22 e 2 haz.... | Klage daß im Naz.heim den Kranken die Ko... | ||
| 4 | Irene: Stimmung sehr verschieden. Kommen... | Irene: Stimmung sehr verschiedenes. Münd... | |
| 5 | Zwei Schwestern Calabrien: M. Cristina u... | 226 Kolabrie: M. Cisneros, Urode | Zwei Schwestern Katalrien: M. Cristina u... |
1# Requires transformers from source
2pip install git+https://github.com/huggingface/transformers
3pip install pillow torch1import torch
2from transformers import LightOnOcrForConditionalGeneration, LightOnOcrProcessor
3from PIL import Image
4
5# Load model and processor
6model_id = "wjbmattingly/LightOnOCR-2-1B-german-shorthand-line"
7device = "cuda" if torch.cuda.is_available() else "cpu"
8dtype = torch.bfloat16 if device == "cuda" else torch.float32
9
10processor = LightOnOcrProcessor.from_pretrained(model_id)
11model = LightOnOcrForConditionalGeneration.from_pretrained(
12 model_id,
13 torch_dtype=dtype,
14).to(device)
15
16# Load your line image
17image = Image.open("your_image.jpg").convert("RGB")
18
19# Prepare input
20messages = [{"role": "user", "content": [{"type": "image"}]}]
21text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
22
23inputs = processor(
24 text=[text],
25 images=[[image]],
26 return_tensors="pt",
27 padding=True,
28 size={"longest_edge": 700},
29).to(device)
30inputs["pixel_values"] = inputs["pixel_values"].to(dtype)
31
32# Generate transcription
33with torch.no_grad():
34 outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False)
35
36# Decode output
37input_length = inputs["input_ids"].shape[1]
38generated_ids = outputs[0, input_length:]
39transcription = processor.decode(generated_ids, skip_special_tokens=True)
40
41print(transcription)1from datasets import load_dataset
2
3# Load dataset
4dataset = load_dataset("medieval-data/german-shorthand-line", split="train[:10]")
5
6# Process batch
7images = [[img.convert("RGB")] for img in dataset["image"]]
8messages = [{"role": "user", "content": [{"type": "image"}]}]
9text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
10texts = [text] * len(images)
11
12inputs = processor(
13 text=texts,
14 images=images,
15 return_tensors="pt",
16 padding=True,
17 size={"longest_edge": 700},
18).to(device)
19inputs["pixel_values"] = inputs["pixel_values"].to(dtype)
20
21outputs = model.generate(**inputs, max_new_tokens=256, do_sample=False)
22predictions = processor.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
23
24for pred, gt in zip(predictions, dataset["text"]):
25 print(f"Prediction: {pred}")
26 print(f"Ground Truth: {gt}")
27 print()1@misc{lightonocr2_finetuned_2026,
2 title = {LightOnOCR Fine-tuned for German},
3 author = {William Mattingly},
4 year = {2026},
5 howpublished = {\url{https://huggingface.co/wjbmattingly/LightOnOCR-2-1B-german-shorthand-line}}
6}1@misc{lightonocr2_2026,
2 title = {LightOnOCR: A 1B End-to-End Multilingual Vision-Language Model for State-of-the-Art OCR},
3 author = {Said Taghadouini and Adrien Cavaill\`{e}s and Baptiste Aubertin},
4 year = {2026},
5 howpublished = {\url{https://arxiv.org/pdf/2601.14251}}
6}