CoolFace
Modelpublic

solvrays/mdf-form-reader-phi35-vision

sourceHugging Faceapache-2.0updated 4mo agoView on Hugging Face
0likes4downloads
Model Card

MDF Form Reader โ€” Phi-3.5-Vision Fine-tuned

Vision-native handwritten insurance form understanding, fine-tuned from [microsoft/Phi-3.5-vision-instruct](https://huggingface.co/microsoft/Phi-3.5-vision-instruct) using QLoRA.

No OCR needed. This model reads handwriting, checks checkbox states, and extracts structured data directly from scanned MDF (Monthly Disability Verification) form images.

๐Ÿ“‹ Model Summary

PropertyValue
Base Modelmicrosoft/Phi-3.5-vision-instruct (4.2B)
TaskVisual Question Answering on MDF forms
Fine-tuning MethodQLoRA (r=16, alpha=32) via Unsloth
Quantization4-bit NF4 (training) โ†’ 16-bit merged
AnnotatorVertex AI Gemini 2.5 Flash
Exact Match0%
OOD Refusal Rate0%
LicenseApache 2.0

๐Ÿš€ Quick Start

python
from transformers import AutoModelForCausalLM, AutoProcessor
from PIL import Image
import torch

model_id = "solvrays/mdf-form-reader-phi35-vision"

processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="cuda",
    trust_remote_code=True,
)

# Load your scanned MDF form image
image = Image.open("mdf_form.png").convert("RGB")

# Ask a question about the form
question = "What is the name of the physician who signed this form?"

messages = [{"role": "user", "content": f"<|image_1|>
{question}"}]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)

inputs = processor(text=[text], images=[image], return_tensors="pt").to("cuda")

with torch.no_grad():
    out = model.generate(**inputs, max_new_tokens=200, temperature=0.1)

answer = processor.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(answer)

๐Ÿฅ What is an MDF Form?

A Monthly Disability Verification Form (Form 441.O.MDF.O) is issued by TriPlus Services, acting as Third-Party Administrator of Penn Treaty Network America and American Network policies. It requires a licensed physician to certify a patient's ongoing disability status monthly.

Key Fields Extracted

  • โ€”Physician name, address, phone, fax
  • โ€”Submission date range (from / to)
  • โ€”Patient disability status (YES checked / NO checked)
  • โ€”Disability end date (if applicable)
  • โ€”Form completion date
  • โ€”Physician signature presence

๐Ÿ”ฌ Why Vision-Native vs OCR?

ChallengeOCR ApproachThis Model
Cursive physician namesFails ("Carnazzo", "Kruszka")Reads directly from image
Checkbox state (YES/NO)Misses (no text to extract)Sees the โœ“/โœ— mark in context
Date grid cells (MM/DD/YYYY)Digit confusion in small boxesLayout-aware reading
Signature fieldGarbage outputCorrectly ignored
Handwritten addressesHigh error rateContextual correction

๐Ÿ› ๏ธ Training Pipeline

Scanned MDF Form (PDF)
    โ†“ Image pre-processing (deskew 300 DPI, bilateral denoise, CLAHE)
    โ†“ Vertex AI Gemini 2.5 Flash โ†’ structured JSON annotation
    โ†“ VQA triplet dataset (field extraction + OOD refusal pairs)
    โ†“ Phi-3.5-Vision + QLoRA (Unsloth, 2-5ร— faster, 80% less VRAM)
    โ†“ Merge adapters โ†’ full 16-bit model
    โ†“ HuggingFace Hub (safetensors)

Training Configuration

yaml
base_model: microsoft/Phi-3.5-vision-instruct
fine_tuning_method: QLoRA (NF4, double quantization)
lora_rank: 16
lora_alpha: 32
lora_dropout: 0.05
use_rslora: true
vision_layers: frozen
language_layers: adapted
optimizer: AdamW 8-bit (paged)
lr_scheduler: cosine
neftune_noise_alpha: 5
annotator: Vertex AI Gemini 2.5 Flash
framework: Unsloth + HuggingFace TRL

๐Ÿ“Š Evaluation Results

MetricValue
Exact Match (field extraction)0%
OOD Refusal Rate0%
Evaluation SetHeld-out MDF form pages

OOD Refusal Rate measures how reliably the model declines to answer questions not answerable from the form (e.g. "What is the diagnosis?", "Has this claim been approved?").


โš ๏ธ Limitations

  • โ€”Domain-specific: Trained exclusively on TriPlus Services MDF forms. Performance on other form types is not guaranteed.
  • โ€”Image quality: Works best on scans โ‰ฅ 300 DPI. Very low-resolution or heavily degraded scans may reduce accuracy.
  • โ€”Language: English only.
  • โ€”Redacted fields: Returns null for blacked-out fields (insured name/policy number).
  • โ€”Not for medical diagnosis: This model extracts administrative form data only.

๐Ÿ“„ License

This model is released under the Apache 2.0 License. The base model (microsoft/Phi-3.5-vision-instruct) is also Apache 2.0.


๐Ÿ™ Acknowledgements