|
|
--- |
|
|
language: |
|
|
- en |
|
|
base_model: |
|
|
- meta-llama/Llama-3.1-8B-Instruct |
|
|
pipeline_tag: text-generation |
|
|
library_name: peft |
|
|
tags: |
|
|
- india |
|
|
- receipt-parsing |
|
|
- llama |
|
|
- lora |
|
|
- peft |
|
|
- fintech |
|
|
- expense-tracking |
|
|
- indian-vendors |
|
|
--- |
|
|
# Indian Receipt Parser v1.0 |
|
|
|
|
|
## Model Description |
|
|
|
|
|
**Indian Receipt Parser** is a fine-tuned Llama 3.1 8B model specialized in parsing receipts from 50+ popular Indian vendors. It extracts vendor name, amount, date, and category from receipt text and returns structured JSON output. |
|
|
|
|
|
### Model Details |
|
|
|
|
|
- **Base Model:** meta-llama/Meta-Llama-3.1-8B-Instruct |
|
|
- **Fine-tuning Method:** LoRA (Low-Rank Adaptation) |
|
|
- **Training Data:** 2000+ synthetic receipt examples |
|
|
- **Vendors Covered:** 50+ popular Indian brands |
|
|
- **Categories:** 8 (dining, groceries, shopping, transportation, healthcare, entertainment, utilities, travel) |
|
|
- **Output Format:** Structured JSON |
|
|
|
|
|
### Covered Vendors |
|
|
|
|
|
**Food Delivery & Dining (9):** |
|
|
Zomato, Swiggy, EatSure, Dominos, McDonald's, KFC, Burger King, Pizza Hut, Foodpanda |
|
|
|
|
|
**Quick Commerce & Groceries (7):** |
|
|
BigBasket, Blinkit, Zepto, Swiggy Instamart, Dunzo, JioMart, DMart Ready |
|
|
|
|
|
**E-commerce & Shopping (8):** |
|
|
Amazon India, Flipkart, Myntra, Meesho, Ajio, Nykaa, Snapdeal, Tata CLiQ |
|
|
|
|
|
**Transportation (6):** |
|
|
Ola, Uber, Rapido, Namma Yatri, BluSmart, InDrive |
|
|
|
|
|
**FinTech & Payments (7):** |
|
|
Paytm, PhonePe, GooglePay, MobiKwik, Freecharge, Amazon Pay, CRED |
|
|
|
|
|
**Healthcare (5):** |
|
|
Apollo Pharmacy, 1mg, PharmEasy, Netmeds, MedLife |
|
|
|
|
|
**Entertainment (8):** |
|
|
BookMyShow, PVR INOX, Netflix, Amazon Prime, Disney+ Hotstar, Jio Cinema, ZEE5, Sony LIV |
|
|
|
|
|
**Travel (5):** |
|
|
MakeMyTrip, Goibibo, IRCTC, OYO, EaseMyTrip |
|
|
|
|
|
**Telecom (3):** |
|
|
Jio, Airtel, Vi (Vodafone Idea) |
|
|
|
|
|
## Intended Use |
|
|
|
|
|
### Primary Use Cases |
|
|
|
|
|
- **Expense Tracking Apps:** Automatically categorize and extract receipt information |
|
|
- **Financial Management:** Parse receipts for budgeting and analysis |
|
|
- **Receipt Digitization:** Convert physical/digital receipts to structured data |
|
|
- **Business Expense Reports:** Automate expense report generation |
|
|
|
|
|
### Out-of-Scope Use Cases |
|
|
|
|
|
- Non-Indian vendors (model is optimized for Indian brands) |
|
|
- Complex multi-item receipts requiring line-item extraction |
|
|
- Handwritten receipts (OCR required first) |
|
|
- Non-receipt financial documents |
|
|
|
|
|
## How to Use |
|
|
|
|
|
### Installation |
|
|
|
|
|
```bash |
|
|
pip install transformers torch peft |
|
|
``` |
|
|
|
|
|
### Basic Usage |
|
|
|
|
|
```python |
|
|
import torch |
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
|
from peft import PeftModel |
|
|
|
|
|
# Load model |
|
|
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct") |
|
|
base_model = AutoModelForCausalLM.from_pretrained( |
|
|
"meta-llama/Meta-Llama-3.1-8B-Instruct", |
|
|
device_map="auto", |
|
|
torch_dtype=torch.bfloat16 |
|
|
) |
|
|
model = PeftModel.from_pretrained(base_model, "path/to/indian-receipt-parser-v1/final") |
|
|
|
|
|
# Parse receipt |
|
|
receipt_text = """ |
|
|
Thank you for ordering from Zomato |
|
|
|
|
|
Order Date: 15/11/2024 |
|
|
|
|
|
Subtotal: ₹450 |
|
|
Tax: ₹81 |
|
|
Total: ₹531 |
|
|
""" |
|
|
|
|
|
messages = [ |
|
|
{ |
|
|
"role": "system", |
|
|
"content": "You are a financial receipt parser specialized in Indian vendors. Extract vendor name, amount, date, and category from receipts. Return ONLY valid JSON in this exact format: {\"vendor\": \"VendorName\", \"amount\": 0.0, \"date\": \"YYYY-MM-DD\", \"category\": \"category\", \"tax\": 0.0, \"currency\": \"INR\", \"confidence\": 0.0}" |
|
|
}, |
|
|
{ |
|
|
"role": "user", |
|
|
"content": receipt_text |
|
|
} |
|
|
] |
|
|
|
|
|
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) |
|
|
inputs = tokenizer(input_text, return_tensors="pt").to("cuda") |
|
|
|
|
|
with torch.no_grad(): |
|
|
outputs = model.generate(**inputs, max_new_tokens=200, temperature=0.1) |
|
|
|
|
|
response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True) |
|
|
print(response) |
|
|
``` |
|
|
|
|
|
### Expected Output |
|
|
|
|
|
```json |
|
|
{ |
|
|
"vendor": "Zomato", |
|
|
"amount": 531.0, |
|
|
"date": "2024-11-15", |
|
|
"category": "dining", |
|
|
"tax": 81.0, |
|
|
"currency": "INR", |
|
|
"confidence": 0.95 |
|
|
} |
|
|
``` |
|
|
|
|
|
## Training Details |
|
|
|
|
|
### Training Data |
|
|
|
|
|
- **Total Examples:** 2000+ synthetic receipt examples |
|
|
- **Vendors:** 50+ popular Indian brands |
|
|
- **Data Distribution:** |
|
|
- Dining: 360 examples |
|
|
- Groceries: 280 examples |
|
|
- Shopping: 320 examples |
|
|
- Transportation: 240 examples |
|
|
- Healthcare: 200 examples |
|
|
- Entertainment: 320 examples |
|
|
- Utilities: 200 examples |
|
|
- Travel: 200 examples |
|
|
|
|
|
### Training Procedure |
|
|
|
|
|
- **Fine-tuning Method:** LoRA (r=16, alpha=32) |
|
|
- **Trainable Parameters:** 0.52% of total parameters |
|
|
- **Precision:** BF16 (bfloat16) - no quantization |
|
|
- **Epochs:** 5 |
|
|
- **Batch Size:** 16 (effective, with gradient accumulation) |
|
|
- **Learning Rate:** 2e-4 with cosine schedule |
|
|
- **Optimizer:** AdamW |
|
|
- **Hardware:** NVIDIA RTX 5090 (32GB VRAM) |
|
|
- **Training Time:** ~60-90 minutes |
|
|
|
|
|
### Training Loss |
|
|
|
|
|
``` |
|
|
Initial loss: 2.64 |
|
|
Final loss: 0.13 |
|
|
Improvement: 95% |
|
|
``` |
|
|
|
|
|
## Evaluation |
|
|
|
|
|
### Performance Metrics |
|
|
|
|
|
- **Vendor Recognition Accuracy:** ~95% |
|
|
- **Amount Extraction Accuracy:** ~98% |
|
|
- **Category Classification:** ~92% |
|
|
- **Date Parsing Accuracy:** ~90% |
|
|
- **Valid JSON Output:** ~85% |
|
|
|
|
|
### Limitations |
|
|
|
|
|
- **Indian Vendors Only:** Optimized for brands listed above, may not recognize international brands |
|
|
- **Date Format Variations:** Performs best with common Indian date formats (DD/MM/YYYY, DD-MM-YYYY) |
|
|
- **Currency:** Optimized for INR (₹), may struggle with other currencies |
|
|
- **Receipt Complexity:** Works best with simple receipt formats, complex multi-page receipts may need preprocessing |
|
|
- **Hallucination:** May occasionally generate plausible but incorrect values for missing fields |
|
|
|
|
|
## Ethical Considerations |
|
|
|
|
|
### Privacy |
|
|
|
|
|
- Model does not store or transmit any receipt data |
|
|
- All processing happens locally |
|
|
- Users should be aware of sensitive financial information in receipts |
|
|
|
|
|
### Bias |
|
|
|
|
|
- Model is trained primarily on synthetic data |
|
|
- May perform differently on real-world receipts |
|
|
- Vendor coverage is limited to 50+ popular brands |
|
|
- Performance may vary for regional/local vendors not in training data |
|
|
|
|
|
### Responsible Use |
|
|
|
|
|
- Intended for personal finance management and expense tracking |
|
|
- Should not be used as sole source of truth for financial/tax reporting |
|
|
- Users should verify extracted information for critical applications |
|
|
- Not recommended for legal/compliance purposes without human verification |
|
|
|
|
|
## Citation |
|
|
|
|
|
If you use this model, please cite: |
|
|
|
|
|
```bibtex |
|
|
@misc{indian-receipt-parser-v1, |
|
|
title={Indian Receipt Parser v1.0}, |
|
|
author={Your Name}, |
|
|
year={2024}, |
|
|
publisher={Hugging Face}, |
|
|
howpublished={\url{https://huggingface.co/your-username/indian-receipt-parser-v1}} |
|
|
} |
|
|
``` |
|
|
|
|
|
## License |
|
|
|
|
|
This model is released under the [Llama 3.1 Community License](https://ai.meta.com/llama/license/). |
|
|
|
|
|
## Contact |
|
|
|
|
|
For issues, questions, or suggestions: |
|
|
- GitHub Issues: [[url](https://huggingface.co/manaspros/indian-receipt-parser-v1)] |
|
|
- Email: [manas24102@iiitnr.edu.in] |
|
|
|
|
|
--- |
|
|
|
|
|
## Acknowledgments |
|
|
|
|
|
Built with: |
|
|
- 🦙 Meta's Llama 3.1 8B |
|
|
- 🔧 Hugging Face Transformers & PEFT |
|
|
- ⚡ NVIDIA RTX 5090 |
|
|
- 🇮🇳 Inspired by India's digital payment ecosystem |
|
|
|
|
|
**Made with ❤️ for India's fintech community!** |