unsloth/LaTeX_OCR
Viewer β’ Updated β’ 76.3k β’ 2.11k β’ 98
How to use Mayank022/qwen2-vl-finetuned-Image-to-LaTeX with Transformers:
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("Mayank022/qwen2-vl-finetuned-Image-to-LaTeX", device_map="auto")Fine-tune Qwen2-VL, a Vision-Language model, to convert equation images into LaTeX code using the Unsloth framework and LoRA adapters.
Train an Equation-to-LaTeX transcriber using a pre-trained multimodal model. The model learns to read rendered math equations and generate corresponding LaTeX.
unsloth/LaTeX_OCR β Image-LaTeX pairs of printed mathematical expressions.| Component | Description |
|---|---|
| Qwen2-VL | Multimodal vision-language model (7B) by Alibaba |
| Unsloth | Fast & memory-efficient training |
| LoRA (via PEFT) | Parameter-efficient fine-tuning |
| 4-bit Quantization | Enabled by bitsandbytes |
| Datasets, HF Hub | For loading/saving models & datasets |
pip install unsloth unsloth_zoo peft trl datasets accelerate bitsandbytes xformers==0.0.29.post3 sentencepiece protobuf hf_transfer triton
Refer to: Qwen2__VL_image_to_latext.ipynb
Steps:
load_in_4bit=True)datasets.load_dataset("unsloth/LaTeX_OCR")SFTTrainer from Unsloth to fine-tuneLoRA rank used: r=16
LoRA alpha: 16
from PIL import Image
image = Image.open("equation.png")
prompt = "Write the LaTeX representation for this image."
inputs = tokenizer(image, tokenizer.apply_chat_template([("user", prompt)], add_generation_prompt=True), return_tensors="pt").to("cuda")
output = model.generate(**inputs, max_new_tokens=128)
print(tokenizer.decode(output[0], skip_special_tokens=True))
| Metric | Value |
|---|---|
| Exact Match | ~90β92% |
| LoRA Params | ~<1% of model |
| Training Time | ~20β40 mins on A100 |
| Model Size | 7B (4-bit) |
.
βββ Qwen2__VL_image_to_latext.ipynb # Training Notebook
βββ output/ # Saved fine-tuned model
βββ README.md