Views
No views yet

| Variant | Description |
|---|---|
| LightOnOCR-2-1B | Best OCR model |
| LightOnOCR-2-1B-base | Base model, ideal for fine-tuning |
| LightOnOCR-2-1B-bbox | Best model with image bounding boxes |
| LightOnOCR-2-1B-bbox-base | Base bbox model, ideal for fine-tuning |
| LightOnOCR-2-1B-ocr-soup | Merged variant for extra robustness |
| LightOnOCR-2-1B-bbox-soup | Merged variant: OCR + bbox combined |

Note: LightOnOCR-2 is avaible in latest transformers release starting from v5.
1uv pip install transformers # => 5.0.0
2uv pip install pillow pypdfium21import torch
2from transformers import LightOnOcrForConditionalGeneration, LightOnOcrProcessor
3
4device = "mps" if torch.backends.mps.is_available() else "cuda" if torch.cuda.is_available() else "cpu"
5dtype = torch.float32 if device == "mps" else torch.bfloat16
6
7model = LightOnOcrForConditionalGeneration.from_pretrained("lightonai/LightOnOCR-2-1B", torch_dtype=dtype).to(device)
8processor = LightOnOcrProcessor.from_pretrained("lightonai/LightOnOCR-2-1B")
9
10url = "https://huggingface.co/datasets/hf-internal-testing/fixtures_ocr/resolve/main/SROIE-receipt.jpeg"
11
12conversation = [{"role": "user", "content": [{"type": "image", "url": url}]}]
13
14inputs = processor.apply_chat_template(
15 conversation,
16 add_generation_prompt=True,
17 tokenize=True,
18 return_dict=True,
19 return_tensors="pt",
20)
21inputs = {k: v.to(device=device, dtype=dtype) if v.is_floating_point() else v.to(device) for k, v in inputs.items()}
22
23output_ids = model.generate(**inputs, max_new_tokens=1024)
24generated_ids = output_ids[0, inputs["input_ids"].shape[1]:]
25output_text = processor.decode(generated_ids, skip_special_tokens=True)
26print(output_text)1vllm serve lightonai/LightOnOCR-2-1B \
2 --limit-mm-per-prompt '{"image": 1}' --mm-processor-cache-gb 0 --no-enable-prefix-caching1import base64
2import requests
3import pypdfium2 as pdfium
4import io
5
6ENDPOINT = "http://localhost:8000/v1/chat/completions"
7MODEL = "lightonai/LightOnOCR-2-1B"
8
9# Download PDF from arXiv
10pdf_url = "https://arxiv.org/pdf/2412.13663"
11pdf_data = requests.get(pdf_url).content
12
13# Open PDF and convert first page to image
14pdf = pdfium.PdfDocument(pdf_data)
15page = pdf[0]
16# Render at 200 DPI (scale factor = 200/72 ≈ 2.77)
17pil_image = page.render(scale=2.77).to_pil()
18
19# Convert to base64
20buffer = io.BytesIO()
21pil_image.save(buffer, format="PNG")
22image_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
23
24# Make request
25payload = {
26 "model": MODEL,
27 "messages": [{
28 "role": "user",
29 "content": [{
30 "type": "image_url",
31 "image_url": {"url": f"data:image/png;base64,{image_base64}"}
32 }]
33 }],
34 "max_tokens": 4096,
35 "temperature": 0.2,
36 "top_p": 0.9,
37}
38
39response = requests.post(ENDPOINT, json=payload)
40text = response.json()['choices'][0]['message']['content']
41print(text)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}