Views
No views yet
| Metric | Target | Achieved | Status |
|---|---|---|---|
| Extraction Accuracy | ≥85% | 99.2% | ✅ |
| Cross-Document F1 | ≥75% | 100% | ✅ |
| Hallucination Rate | ≤8% | 0% | ✅ |
pip install transformers peft pillow qwen-vl-utils1from peft import PeftModel
2from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
3import torch
4
5# Load base model with 4-bit quantization
6model = Qwen2VLForConditionalGeneration.from_pretrained(
7 "Qwen/Qwen2.5-VL-3B-Instruct",
8 torch_dtype=torch.bfloat16,
9 load_in_4bit=True,
10 device_map="auto"
11)
12
13# Load fine-tuned adapter
14model = PeftModel.from_pretrained(model, "kunikhanna/dgx-sentinel-qwen-3b")
15
16# Load processor
17processor = AutoProcessor.from_pretrained("Qwen/Qwen2.5-VL-3B-Instruct")1from qwen_vl_utils import process_vision_info
2from PIL import Image
3
4# Load your document images
5paystub_1 = Image.open("paystub_1.jpg")
6paystub_2 = Image.open("paystub_2.jpg")
7utility_bill = Image.open("utility_bill.jpg")
8id_card = Image.open("id_card.jpg")
9
10# Prepare prompt
11prompt = """Extract the following fields from these 4 documents:
121. Full Name
132. Monthly Gross Income
143. Residential Address
154. Issue Date
16
17Output as JSON."""
18
19# Create messages
20messages = [
21 {
22 "role": "user",
23 "content": [
24 {"type": "image", "image": paystub_1},
25 {"type": "image", "image": paystub_2},
26 {"type": "image", "image": utility_bill},
27 {"type": "image", "image": id_card},
28 {"type": "text", "text": prompt}
29 ]
30 }
31]
32
33# Process and generate
34text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
35image_inputs, video_inputs = process_vision_info(messages)
36inputs = processor(
37 text=[text],
38 images=image_inputs,
39 videos=video_inputs,
40 padding=True,
41 return_tensors="pt"
42).to(model.device)
43
44output_ids = model.generate(**inputs, max_new_tokens=512)
45output_text = processor.batch_decode(
46 output_ids,
47 skip_special_tokens=True,
48 clean_up_tokenization_spaces=False
49)[0]
50
51print(output_text)
52# Output: {"full_name": "John Smith", "monthly_income": "5000", ...}1{
2 "r": 16,
3 "lora_alpha": 16,
4 "lora_dropout": 0.05,
5 "target_modules": [
6 "q_proj", "k_proj", "v_proj", "o_proj",
7 "gate_proj", "up_proj", "down_proj",
8 "vision_proj"
9 ],
10 "peft_type": "LORA"
11}vision_proj in target modules for better multi-document visual understanding.1learning_rate: 2e-4
2num_epochs: 2
3batch_size: 1
4gradient_accumulation_steps: 4
5warmup_steps: 10
6weight_decay: 0.01
7optimizer: adamw_torch
8lr_scheduler: cosine
9max_seq_length: 81921@software{dgx_sentinel_2026,
2 title={DGX Sentinel: Document Verification System},
3 author={Kunal Khanna},
4 year={2026},
5 publisher={Hugging Face},
6 url={https://huggingface.co/kunikhanna/dgx-sentinel-qwen-3b}
7}