A LoRA adapter for Qwen/Qwen2.5-VL-7B-Instruct that makes the model emit schema-conformant JSON directly from a receipt image.
Most of what this adapter adds is reliability. The base model almost always wraps its answer in a ```json fence (96 of 100 receipts), so plain json.loads works only 3% of the time. With the adapter it works 100% of the time. Precision roughly triples because the model stops padding its answers with commentary and made-up fields. Recall goes up too, from 0.65 to 0.84, though some of that is probably the model learning the schema rather than reading better. A field only counts if both its key path and value match, so the current numbers can't separate the two.
Trained with TRL SFTTrainer in the prompt-completion format (completion_only_loss=True, so the loss covers only the JSON answer) under PyTorch FSDP FULL_SHARD via Hugging Face Accelerate on a SLURM cluster. The released adapter comes from a 1 node x 8 A100 (40 GB) run, 14.4 minutes of training.
import torch
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
from peft import PeftModel
base = "Qwen/Qwen2.5-VL-7B-Instruct"
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(base, dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, "dmnsjk/qwen2.5-vl-7b-cord-json-lora")
processor = AutoProcessor.from_pretrained("dmnsjk/qwen2.5-vl-7b-cord-json-lora")
| code | Training pipeline and FSDP configs: https://github.com/dmn-sjk/vlm_doc_parsing. See src/vlm_doc_parsing/infer/predict.py there for a complete inference example. |
| base model | Qwen/Qwen2.5-VL-7B-Instruct |
| LoRA rank / alpha / dropout | 32 / 64 / 0.05 |
| target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| vision tower | frozen, not adapted |
| dataset | naver-clova-ix/cord-v2 |
| resolution cap | min_pixels=200704, max_pixels=1003520 |
| epochs / lr / scheduler | 3.0 / 0.0001 / cosine |
| precision | bf16, gradient checkpointing, loss_type="chunked_nll" |
run_config.yaml in this repository is the exact resolved configuration of the run.
Held-out CORD-v2 test split, 100 receipts, greedy decoding. Scored against the base checkpoint under an identical prompt, so the delta is attributable to the adapter.
| Metric | Base (no adapter) | This adapter |
|---|---|---|
| JSON parse rate (strict) | 0.030 | 1.000 |
| JSON parse rate (lenient) | 0.990 | 1.000 |
| Field precision | 0.288 | 0.860 |
| Field recall | 0.651 | 0.839 |
| Field F1 | 0.400 | 0.849 |
| Exact match | 0.000 | 0.420 |
| Normalised edit similarity | 0.496 | 0.946 |
JSON parse rate is reported separately from field accuracy because a model that extracts every field but emits a trailing comma scores zero downstream. "Strict" is json.loads on the raw generation; "lenient" first strips a markdown code fence.
run_config.yaml). Prompting it for a different key set will degrade it. The adapter has been specialised toward one output shape.max_pixels (see the table above). Documents far denser than a receipt may lose legibility at that cap.Trained and evaluated on CORD-v2 by NAVER Clova, licensed under CC BY 4.0. If you use this adapter, please cite the dataset:
@inproceedings{park2019cord,
title = {CORD: A Consolidated Receipt Dataset for Post-OCR Parsing},
author = {Park, Seunghyun and Shin, Seung and Lee, Bado and Lee, Junyeop and Surh, Jaeheung and Seo, Minjoon and Lee, Hwalsuk},
booktitle = {Document Intelligence Workshop at Neural Information Processing Systems},
year = {2019}
}
Qwen/Qwen2.5-VL-7B-Instruct