A production-grade financial document parser fine-tuned on Qwen2.5-7B-Instruct using QLoRA (4-bit NF4 quantization). Given raw text from any financial document, it outputs structured JSON — ready for downstream processing, ERP integration, or analytics pipelines.
Stores weights in 4-bit NormalFloat format — ~4x model size reduction
Double quantization
Quantizes the quantization constants — additional ~0.4 bits/param saving
bfloat16 compute
Full precision operations, 4-bit storage
LoRA adapters (r=8)
Only 0.5% of parameters trained — 99.5% frozen
Paged AdamW 8-bit
Optimizer state memory reduction
Gradient checkpointing
~40% activation memory reduction
📤 Output Schema
json
1{2"document_type":"invoice|balance_sheet|income_stmt|sap_report|sql_result|bank_statement|purchase_order",3"vendor":"string or null",4"client":"string or null",5"date":"YYYY-MM-DD or null",6"due_date":"YYYY-MM-DD or null",7"document_id":"string or null",8"currency":"USD|EUR|INR|GBP|...",9"subtotal":"float or null",10"tax_amount":"float or null",11"tax_rate_pct":"float or null",12"total_amount":"float or null",13"line_items":[14{15"description":"string",16"quantity":"float or null",17"unit_price":"float or null",18"amount":"float"19}20],21"payment_terms":"string or null",22"notes":"string or null",23"metadata":{}24}
💻 Usage
Via HuggingFace Inference API
python
1import requests
2import json
3import re
45API_URL ="https://api-inference.huggingface.co/models/ratulsur/multi-format-finance-parser"6HF_TOKEN ="hf_xxxxxxxxxxxx"78SYSTEM_PROMPT ="""You are a production financial document parser.
9Given raw text from any financial document, output ONLY a single valid JSON object.
10Schema: {document_type, vendor, client, date (YYYY-MM-DD), due_date, document_id,
11currency, subtotal, tax_amount, tax_rate_pct, total_amount,
12line_items:[{description,quantity,unit_price,amount}], payment_terms, notes, metadata}.
13All monetary values must be floats. Unknown fields → null. No explanation."""1415defparse_document(text:str)->dict:16 prompt =(17f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"18f"<|im_start|>user\nParse this financial document:\n\n{text}<|im_end|>\n"19f"<|im_start|>assistant\n"20)21 headers ={"Authorization":f"Bearer {HF_TOKEN}"}22 payload ={23"inputs": prompt,24"parameters":{25"max_new_tokens":512,26"temperature":0.05,27"return_full_text":False,28"do_sample":False,29}30}31 resp = requests.post(API_URL, headers=headers, json=payload, timeout=120)32 raw = resp.json()[0]["generated_text"].strip()33 raw = re.sub(r"```json\s*|```\s*","", raw).strip()34return json.loads(raw)3536# Example37invoice ="""
38INVOICE
39Vendor: Tata Consultancy Services Ltd.
40Invoice No: TCS-2024-8821
41Date: 2024-11-15
42Service: Cloud Infrastructure Management INR 42,500.00
43GST @ 18%: INR 7,650.00
44TOTAL DUE: INR 50,150.00
45Payment Terms: Net 30
46"""4748result = parse_document(invoice)49print(json.dumps(result, indent=2))