Image-Text-to-Text
PEFT
Safetensors
qwen2_5_vl
qwen2.5-vl
vision-language-model
invoice-extraction
document-understanding
ocr
indian-invoices
gst
lora
unsloth
fine-tuned
conversational
Instructions to use gouri100/Unsloth_Qwen-2.5_7B-Invoice-962 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use gouri100/Unsloth_Qwen-2.5_7B-Invoice-962 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use gouri100/Unsloth_Qwen-2.5_7B-Invoice-962 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for gouri100/Unsloth_Qwen-2.5_7B-Invoice-962 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for gouri100/Unsloth_Qwen-2.5_7B-Invoice-962 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for gouri100/Unsloth_Qwen-2.5_7B-Invoice-962 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="gouri100/Unsloth_Qwen-2.5_7B-Invoice-962", max_seq_length=2048, )
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,199 +1,269 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
## Model Details
|
| 13 |
-
|
| 14 |
-
### Model Description
|
| 15 |
-
|
| 16 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 17 |
-
|
| 18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
-
|
| 76 |
-
## Training Details
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
-
|
| 84 |
-
### Training Procedure
|
| 85 |
-
|
| 86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
-
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
|
| 153 |
-
##
|
| 154 |
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
| 158 |
|
| 159 |
-
##
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
-
|
| 164 |
|
| 165 |
-
|
| 166 |
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
| 180 |
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
|
| 184 |
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
-
|
| 188 |
|
| 189 |
-
##
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
[
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: Qwen/Qwen2.5-VL-7B-Instruct
|
| 3 |
+
datasets:
|
| 4 |
+
- custom-indian-invoice-dataset
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
- hi
|
| 8 |
+
- ta
|
| 9 |
+
- ml
|
| 10 |
+
- te
|
| 11 |
+
- kn
|
| 12 |
+
- bn
|
| 13 |
+
license: apache-2.0
|
| 14 |
+
pipeline_tag: image-text-to-text
|
| 15 |
+
tags:
|
| 16 |
+
- qwen2.5-vl
|
| 17 |
+
- vision-language-model
|
| 18 |
+
- invoice-extraction
|
| 19 |
+
- document-understanding
|
| 20 |
+
- ocr
|
| 21 |
+
- indian-invoices
|
| 22 |
+
- gst
|
| 23 |
+
- lora
|
| 24 |
+
- peft
|
| 25 |
+
- unsloth
|
| 26 |
+
- fine-tuned
|
| 27 |
---
|
| 28 |
|
| 29 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# Qwen2.5-VL 7B — Indian Invoice Extraction
|
| 32 |
|
| 33 |
+
Fine-tuned version of [Qwen/Qwen2.5-VL-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct) specialized for extracting structured JSON from Indian GST invoices (B2B, B2C, export, IRN/ACK, multi-layout). Trained with QLoRA + Unsloth on an NVIDIA A100 80 GB. Merged via PEFT merge_and_unload().
|
| 34 |
|
| 35 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
## Available Versions
|
| 38 |
|
| 39 |
+
| Version | Link | Use case |
|
| 40 |
+
|---|---|---|
|
| 41 |
+
| Merged bfloat16 | [gouri100/Unsloth_Qwen-2.5_7B-Invoice-962](https://huggingface.co/gouri100/Unsloth_Qwen-2.5_7B-Invoice-962) | Full precision inference |
|
| 42 |
+
| GGUF Q4_K_M | [gouri100/Unsloth_Qwen-2.5_7B-Invoice-962-GGUF](https://huggingface.co/gouri100/Unsloth_Qwen-2.5_7B-Invoice-962-GGUF) | llama.cpp / Ollama — light GPU |
|
| 43 |
+
| GGUF Q8_0 | [gouri100/Unsloth_Qwen-2.5_7B-Invoice-962-GGUF](https://huggingface.co/gouri100/Unsloth_Qwen-2.5_7B-Invoice-962-GGUF) | llama.cpp / Ollama — higher quality |
|
| 44 |
|
| 45 |
+
---
|
| 46 |
|
| 47 |
+
## Model Summary
|
| 48 |
|
| 49 |
+
| Property | Value |
|
| 50 |
+
|---|---|
|
| 51 |
+
| **Base model** | Qwen/Qwen2.5-VL-7B-Instruct |
|
| 52 |
+
| **Fine-tuning method** | QLoRA (r=64, alpha=128) |
|
| 53 |
+
| **Merge method** | PEFT merge_and_unload() — bfloat16 safetensors |
|
| 54 |
+
| **Framework** | Unsloth + TRL SFTTrainer |
|
| 55 |
+
| **Hardware** | NVIDIA A100 80 GB |
|
| 56 |
+
| **Task** | Invoice image to Structured JSON |
|
| 57 |
+
| **Input types** | JPG, PNG, PDF (page 1 at 200 DPI) |
|
| 58 |
+
| **Languages** | English, Hindi, Tamil, Malayalam, Telugu, Kannada, Bengali |
|
| 59 |
+
| **License** | Apache 2.0 |
|
| 60 |
|
| 61 |
+
---
|
| 62 |
|
| 63 |
+
## Training Dataset
|
| 64 |
|
| 65 |
+
| Property | Value |
|
| 66 |
+
|---|---|
|
| 67 |
+
| **Total samples** | 962 |
|
| 68 |
+
| **File types** | JPG, PNG, PDF |
|
| 69 |
+
| **PDF handling** | Page 1 extracted at 200 DPI, resized to max 1280px |
|
| 70 |
+
| **Invoice types** | B2B GST, B2C, Export, IRN/ACK |
|
| 71 |
+
| **Annotation** | Manually labeled JSON per invoice |
|
| 72 |
|
| 73 |
+
---
|
| 74 |
|
| 75 |
+
## Output JSON Schema
|
| 76 |
+
|
| 77 |
+
```json
|
| 78 |
+
{
|
| 79 |
+
"metadata": {
|
| 80 |
+
"invoice_no": "string",
|
| 81 |
+
"invoice_date": "YYYY-MM-DD",
|
| 82 |
+
"irn": "string | null",
|
| 83 |
+
"ack_no": "string | null",
|
| 84 |
+
"ack_date": "string | null"
|
| 85 |
+
},
|
| 86 |
+
"supplier": {
|
| 87 |
+
"name": "string",
|
| 88 |
+
"gstin": "string",
|
| 89 |
+
"address": "string",
|
| 90 |
+
"state_code": "string"
|
| 91 |
+
},
|
| 92 |
+
"buyer": {
|
| 93 |
+
"name": "string",
|
| 94 |
+
"gstin": "string",
|
| 95 |
+
"address": "string",
|
| 96 |
+
"state_code": "string"
|
| 97 |
+
},
|
| 98 |
+
"line_items": [{
|
| 99 |
+
"sl_no": "number",
|
| 100 |
+
"description": "string",
|
| 101 |
+
"hsn_sac": "string",
|
| 102 |
+
"qty": "number",
|
| 103 |
+
"unit": "string",
|
| 104 |
+
"rate": "number",
|
| 105 |
+
"amount": "number"
|
| 106 |
+
}],
|
| 107 |
+
"tax": {
|
| 108 |
+
"taxable_value": "number",
|
| 109 |
+
"cgst_rate": "number",
|
| 110 |
+
"cgst_amount": "number",
|
| 111 |
+
"sgst_rate": "number",
|
| 112 |
+
"sgst_amount": "number",
|
| 113 |
+
"igst_rate": "number",
|
| 114 |
+
"igst_amount": "number",
|
| 115 |
+
"total_tax": "number",
|
| 116 |
+
"grand_total": "number",
|
| 117 |
+
"round_off": "number"
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
```
|
| 121 |
|
| 122 |
+
---
|
| 123 |
|
| 124 |
+
## Training Configuration
|
| 125 |
+
|
| 126 |
+
| Hyperparameter | Value |
|
| 127 |
+
|---|---|
|
| 128 |
+
| **Epochs** | 3 |
|
| 129 |
+
| **Learning rate** | 0.0002 |
|
| 130 |
+
| **LR scheduler** | Cosine |
|
| 131 |
+
| **Warmup ratio** | 0.05 |
|
| 132 |
+
| **Per device batch size** | 2 |
|
| 133 |
+
| **Gradient accumulation steps** | 8 |
|
| 134 |
+
| **Effective batch size** | 16 |
|
| 135 |
+
| **Max sequence length** | 2048 |
|
| 136 |
+
| **Precision** | bfloat16 |
|
| 137 |
+
| **LoRA rank (r)** | 64 |
|
| 138 |
+
| **LoRA alpha** | 128 |
|
| 139 |
+
| **LoRA dropout** | 0.05 |
|
| 140 |
+
| **LoRA target modules** | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 141 |
+
| **Vision layers fine-tuned** | Yes |
|
| 142 |
+
| **Gradient checkpointing** | Unsloth optimized |
|
| 143 |
|
| 144 |
+
---
|
| 145 |
|
| 146 |
+
## Training Results
|
| 147 |
|
| 148 |
+
| Metric | Value |
|
| 149 |
+
|---|---|
|
| 150 |
+
| **Final training loss** | 0.2594 |
|
| 151 |
+
| **Total steps** | N/A |
|
| 152 |
+
| **Training time** | 2243.16s (37.4 min) |
|
| 153 |
+
| **Steps per second** | 0.082 |
|
| 154 |
|
| 155 |
+
---
|
| 156 |
|
| 157 |
+
## Inference
|
| 158 |
+
|
| 159 |
+
### With transformers (merged model)
|
| 160 |
+
|
| 161 |
+
```python
|
| 162 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 163 |
+
from PIL import Image
|
| 164 |
+
import torch, json
|
| 165 |
+
|
| 166 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 167 |
+
"gouri100/Unsloth_Qwen-2.5_7B-Invoice-962",
|
| 168 |
+
torch_dtype = torch.bfloat16,
|
| 169 |
+
device_map = 'auto',
|
| 170 |
+
)
|
| 171 |
+
processor = AutoProcessor.from_pretrained("gouri100/Unsloth_Qwen-2.5_7B-Invoice-962")
|
| 172 |
+
|
| 173 |
+
image = Image.open('invoice.jpg').convert('RGB')
|
| 174 |
+
|
| 175 |
+
SYSTEM_PROMPT = (
|
| 176 |
+
'You are an expert system for extracting structured data from invoices. '
|
| 177 |
+
'Return ONLY valid JSON. Do NOT include explanations or extra text.'
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
messages = [
|
| 181 |
+
{'role': 'system', 'content': [{'type': 'text', 'text': SYSTEM_PROMPT}]},
|
| 182 |
+
{'role': 'user', 'content': [
|
| 183 |
+
{'type': 'image', 'image': image},
|
| 184 |
+
{'type': 'text', 'text': 'Extract structured invoice data as JSON.'}
|
| 185 |
+
]}
|
| 186 |
+
]
|
| 187 |
+
|
| 188 |
+
inputs = processor.apply_chat_template(
|
| 189 |
+
messages,
|
| 190 |
+
add_generation_prompt = True,
|
| 191 |
+
tokenize = True,
|
| 192 |
+
return_tensors = 'pt',
|
| 193 |
+
return_dict = True,
|
| 194 |
+
).to(model.device)
|
| 195 |
+
|
| 196 |
+
with torch.no_grad():
|
| 197 |
+
output_ids = model.generate(
|
| 198 |
+
**inputs,
|
| 199 |
+
max_new_tokens = 1024,
|
| 200 |
+
temperature = 0.1,
|
| 201 |
+
do_sample = False,
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
decoded = processor.decode(
|
| 205 |
+
output_ids[0][inputs['input_ids'].shape[1]:],
|
| 206 |
+
skip_special_tokens = True,
|
| 207 |
+
)
|
| 208 |
+
result = json.loads(decoded)
|
| 209 |
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
### Load in 4-bit (lighter GPUs)
|
| 213 |
+
|
| 214 |
+
```python
|
| 215 |
+
from transformers import BitsAndBytesConfig
|
| 216 |
+
|
| 217 |
+
bnb_config = BitsAndBytesConfig(
|
| 218 |
+
load_in_4bit = True,
|
| 219 |
+
bnb_4bit_compute_dtype = torch.bfloat16,
|
| 220 |
+
bnb_4bit_quant_type = 'nf4',
|
| 221 |
+
bnb_4bit_use_double_quant = True,
|
| 222 |
+
)
|
| 223 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 224 |
+
"gouri100/Unsloth_Qwen-2.5_7B-Invoice-962",
|
| 225 |
+
quantization_config = bnb_config,
|
| 226 |
+
device_map = 'auto',
|
| 227 |
+
)
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
### From PDF
|
| 231 |
+
|
| 232 |
+
```python
|
| 233 |
+
from pdf2image import convert_from_path
|
| 234 |
+
pages = convert_from_path('invoice.pdf', dpi=200)
|
| 235 |
+
image = pages[0]
|
| 236 |
+
# then follow inference code above
|
| 237 |
+
```
|
| 238 |
+
|
| 239 |
+
### With Ollama (GGUF)
|
| 240 |
+
|
| 241 |
+
```bash
|
| 242 |
+
ollama run gouri100/Unsloth_Qwen-2.5_7B-Invoice-962-GGUF
|
| 243 |
+
```
|
| 244 |
|
| 245 |
+
---
|
| 246 |
|
| 247 |
+
## Limitations
|
| 248 |
|
| 249 |
+
- Optimized for Indian GST invoice formats — may underperform on foreign layouts
|
| 250 |
+
- Scans below 100 DPI or heavily skewed images reduce accuracy
|
| 251 |
+
- Handwritten invoices are not supported
|
| 252 |
+
- Multi-page invoices: only page 1 was used during training
|
| 253 |
+
- Always validate extracted JSON against your business logic before use
|
| 254 |
|
| 255 |
+
---
|
| 256 |
|
| 257 |
+
## Citation
|
| 258 |
|
| 259 |
+
```bibtex
|
| 260 |
+
@misc{qwen2.5-vl-7b-indian-invoice,
|
| 261 |
+
title = {Qwen2.5-VL-7B Fine-tuned for Indian Invoice Extraction},
|
| 262 |
+
author = {Your Name},
|
| 263 |
+
year = {2025},
|
| 264 |
+
publisher = {HuggingFace},
|
| 265 |
+
howpublished = {\url{https://huggingface.co/gouri100/Unsloth_Qwen-2.5_7B-Invoice-962}}
|
| 266 |
+
}
|
| 267 |
+
```
|
| 268 |
|
| 269 |
+
*Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) · Merged with [PEFT](https://github.com/huggingface/peft) · Trained on NVIDIA A100 80 GB*
|