Downloads · 30 days
25
45% of all-time downloads
thealper2/donut-im2latex
donut-im2latex is a image-to-text model from thealper2. Use it when you need a caption or text from an image. It is set up for transformers. The card lists the license as apache-2.0.
This model is an OCR-free image-to-LaTeX model. It takes a rendered image of a mathematical formula as input and directly produces the corresponding LaTeX markup, without a separate text-detection or OCR stage. It was…
Downloads · 30 days
25
45% of all-time downloads
All-time downloads
55
Public
Parameters
202M
809 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors809 MB · 100%
How the weights are stored.
F32202M · 100%
From the Hugging Face model README
This model is an OCR-free image-to-LaTeX model. It takes a rendered image of a mathematical formula as input and directly produces the corresponding LaTeX markup, without a separate text-detection or OCR stage. It was fine-tuned from naver-clova-ix/donut-base on the yuntian-deng/im2latex-100k dataset.
Donut is a Vision-Encoder-Decoder model: a Swin Transformer vision encoder reads the input image and a BART-style autoregressive text decoder generates the target sequence. A dedicated task-start token prompts the decoder to emit LaTeX.
yuntian-deng/im2latex-100kThe model was trained with mixed precision, gradient accumulation, gradient clipping and gradient checkpointing. The best checkpoint was selected on the validation CER with early stopping.
Linux-6.18.33.2-microsoft-standard-WSL2-x86_64-with-glibc2.39torch: 2.10.0+cu128transformers: 5.14.1datasets: 4.3.0accelerate: 1.12.0peft: 0.18.1Metrics computed on the validation split:
| Metric | Value |
|---|---|
| Exact match | 0.5050 |
| CER | 0.0558 |
| Levenshtein | 6.7850 |
| BLEU | 0.9147 |
| Avg. gen. length | 43.5100 |
| Validation loss | 0.0561 |
Converting images of typeset mathematical formulas (for example, screenshots of rendered LaTeX) into editable LaTeX source. Suitable for document digitization, accessibility tooling and dataset construction.
The dataset consists of machine-rendered formulas from scientific papers and is limited to the notation and symbol distribution of that corpus. The model may underperform on notation conventions outside this distribution. Outputs should be reviewed before use in academic or production settings.
import torch
from PIL import Image
from transformers import DonutProcessor, VisionEncoderDecoderModel
model_id = "thealper2/donut-im2latex"
processor = DonutProcessor.from_pretrained(model_id)
model = VisionEncoderDecoderModel.from_pretrained(model_id)
model.eval()
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
image = Image.open("formula.png").convert("RGB")
pixel_values = processor.image_processor(image, return_tensors="pt").pixel_values.to(device)
decoder_input_ids = torch.tensor(
[[model.config.decoder_start_token_id]], device=device
)
generated = model.generate(
pixel_values=pixel_values,
decoder_input_ids=decoder_input_ids,
max_length=model.generation_config.max_length,
num_beams=4,
)
latex = processor.tokenizer.batch_decode(generated, skip_special_tokens=True)[0]
print(latex)
@misc{donut_latex,
title = {Donut-LaTeX: OCR-free image-to-LaTeX with Donut},
author = {donut-latex authors},
year = {2024},
note = {Fine-tuned from naver-clova-ix/donut-base on yuntian-deng/im2latex-100k}
}
@inproceedings{kim2022donut,
title = {OCR-free Document Understanding Transformer},
author = {Kim, Geewook and Hong, Teakgyu and Yim, Moonbin and others},
booktitle = {European Conference on Computer Vision (ECCV)},
year = {2022}
}
Released under the Apache-2.0 license (placeholder -- confirm the license of any derived data and base model before publishing).