Downloads · 30 days
0
aaghaazkhan/Qwen2_5_3B_VL_HandWritten_LaTeX_OCR
Qwen2_5_3B_VL_HandWritten_LaTeX_OCR is a machine learning model from aaghaazkhan. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
https://github.com/aaghaazkhan/Qwen253BVLHandWrittenLaTeXOCR
Downloads · 30 days
0
Access
Public
Updated Nov 17, 2025
Repo size
85.8 MB
Likes
0
Public
Click a slice to open those files.
.safetensors74.4 MB · 82%
From the Hugging Face model README
https://github.com/aaghaazkhan/Qwen2_5_3B_VL_HandWritten_LaTeX_OCR
This model converts images of handwritten mathematical expressions into LaTeX code using a fine-tuned version of Qwen 2.5-VL. It was trained using LoRA on a 4-bit quantized model setup, making it GPU-friendly and accessible for low-resource environments.
Ideal for automating LaTeX conversion in:
Trained locally on NVIDIA RTX 3050 (6GB VRAM)
Total VRAM usage: 5.72 GB
from transformers import Qwen2_5_VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
model_id = "aaghaazkhan/Qwen2_5_3B_VL_HandWritten_LaTeX_OCR"
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
"aaghaazkhan/Qwen2_5_3B_VL_HandWritten_LaTeX_OCR", torch_dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_id)
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "latex_demo.png",
},
{"type": "text", "text": "Convert the mathematical content in the image into LaTeX."},
],
}
]
# Preparation for inference
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# Inference: Generation of the output
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
| Setting | Value |
|---|---|
| LoRA Rank | 16 |
| LoRA Alpha | 32 |
| Learning Rate | 2e-4 |
| Batch Size | 2 (with grad accumulation 8) |
| Precision | 4-bit NF4 |
| Epochs | 1 |
| VRAM Used | ~5.7GB |
| Training Duration | 49 mins (local) |
| Gradient Checkpointing | Enabled |
| Metric | Value |
|---|---|
| Token Accuracy | ~99.8% |
| Exact Match | ~90% |
| Val Loss | ~0.006 |
Aaghaaz Khan