TR-OCR-Markdown v0.4
LoRA for DeepSeek-OCR-2
2 min readupdated
Built on unsloth/DeepSeek-OCR-2 (3.5B parameters), this updated adapter (v0.4) turns images of Turkish documents—forms, contracts, laws, receipts, and tables—into structured Markdown while preserving headings, lists, tables, and LaTeX formulas. Trained on a mix of synthetic and real-world data, it substantially outperforms earlier versions on both real scans and digital PDFs, driving down the character error rate (CER).
Key features
- Built for Turkish: Accurately extracts text from complex documents and printed materials.
- Markdown formatting: Automatically detects and formats headings, lists, tables, and LaTeX formulas.
- Lightweight footprint: An 86M-parameter LoRA adapter (346 MB) that leaves the base vision encoders untouched.
- Lower error rates: Major CER improvements over v0.3 across real-world test sets.
What you can do
- Plug it into document-processing pipelines to convert scanned laws and reports into clean Markdown.
- Parse receipts, waybills, and invoices using a dedicated plain-text or Markdown prompt.
- Digitize old books, academic papers, and official gazettes.
- Run it in local inference scripts on GPUs with bf16 support.
Example
import torch
from transformers import AutoModel, AutoTokenizer
from peft import PeftModel
BASE, REPO = "unsloth/DeepSeek-OCR-2", "msbayindir/tr-ocr-markdown-deepseek-ocr2-lora-v0.4"
tok = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
base = AutoModel.from_pretrained(BASE, trust_remote_code=True, use_safetensors=True, _attn_implementation="eager",
torch_dtype=torch.bfloat16).eval().cuda()
model = PeftModel.from_pretrained(base, REPO).eval()
model = model.merge_and_unload()
md = model.infer(tok, prompt="\nFree. OCR. ", image_file="sayfa.png", output_path="/tmp/out",
base_size=1024, image_size=768, crop_mode=True)
print(md)Read more
Details• Base model: unsloth/DeepSeek-OCR-2 (3.5B parameters, Apache-2.0).
• Training: 1 epoch, LoRA r=16, 20.5k examples.
• Metrics (CER): Dropped to 0.4% on born-digital laws and 25.4% on scanned Resmî Gazete issues.
• Limitations: Human review is mandatory for legal and official use cases.










Comments