Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,123 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 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 |
-
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 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 |
-
|
| 43 |
-
|
| 44 |
-
|
| 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 |
-
|
| 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 |
-
|
| 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 |
-
###
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
### Training Procedure
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
|
| 93 |
-
|
| 94 |
|
| 95 |
-
- **
|
|
|
|
| 96 |
|
| 97 |
-
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
|
| 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 |
-
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 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 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 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 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
|
| 187 |
-
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
|
|
|
|
| 192 |
|
| 193 |
-
|
|
|
|
| 194 |
|
| 195 |
-
|
|
|
|
| 196 |
|
| 197 |
-
|
|
|
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- document-question-answering
|
| 5 |
+
- layoutlmv3
|
| 6 |
+
- ocr
|
| 7 |
+
- document-understanding
|
| 8 |
+
- paddleocr
|
| 9 |
+
- multilingual
|
| 10 |
+
- layout-aware
|
| 11 |
+
- lakshya-singh
|
| 12 |
+
license: apache-2.0
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
base_model:
|
| 16 |
+
- microsoft/layoutlmv3-base
|
| 17 |
+
datasets:
|
| 18 |
+
- nielsr/docvqa_1200_examples
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# Document QA Model
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
This is a fine-tuned **document question-answering model** based on `layoutlmv3-base`. It is trained to understand documents using OCR data (via PaddleOCR) and accurately answer questions related to structured information in the document layout.
|
| 24 |
|
| 25 |
+
---
|
| 26 |
|
| 27 |
## Model Details
|
| 28 |
|
| 29 |
### Model Description
|
| 30 |
|
| 31 |
+
- **Model Name:** `document-qa-model`
|
| 32 |
+
- **Base Model:** [`microsoft/layoutlmv3-base`](https://huggingface.co/microsoft/layoutlmv3-base)
|
| 33 |
+
- **Fine-tuned by:** Lakshya Singh (solo contributor)
|
| 34 |
+
- **Languages:** English, Spanish, Chinese
|
| 35 |
+
- **License:** Apache-2.0 (inherited from base model)
|
| 36 |
+
- **Intended Use:** Extract answers to structured queries from scanned documents
|
| 37 |
+
- **Not funded** — this project was completed independently.
|
| 38 |
|
| 39 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
## Model Sources
|
| 42 |
|
| 43 |
+
- **Repository:** [https://github.com/Lakshyasinghrawat12]
|
| 44 |
+
- **Trained on:** Adapted version of [`nielsr/docvqa_1200_examples`](https://huggingface.co/datasets/nielsr/docvqa_1200_examples)
|
| 45 |
+
- **Model metrics:** See 
|
| 46 |
|
| 47 |
+
---
|
|
|
|
|
|
|
| 48 |
|
| 49 |
## Uses
|
| 50 |
|
|
|
|
|
|
|
| 51 |
### Direct Use
|
| 52 |
|
| 53 |
+
This model can be used for:
|
| 54 |
+
- Question Answering on document images (PDFs, invoices, utility bills)
|
| 55 |
+
- Information extraction tasks using OCR and layout-aware understanding
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
### Out-of-Scope Use
|
| 58 |
|
| 59 |
+
- Not suitable for conversational QA
|
| 60 |
+
- Not suitable for images with no OCR-processed text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
## Training Details
|
| 65 |
|
| 66 |
+
### Dataset
|
| 67 |
|
| 68 |
+
The dataset consisted of:
|
| 69 |
+
- **Images** of utility bills and documents
|
| 70 |
+
- **OCR data** with bounding boxes (from PaddleOCR)
|
| 71 |
+
- **Queries** in English, Spanish, and Chinese
|
| 72 |
+
- **Answer spans** with match scores and positions
|
| 73 |
|
| 74 |
### Training Procedure
|
| 75 |
|
| 76 |
+
- Preprocessing: PaddleOCR was used to extract tokens, positions, and structure
|
| 77 |
+
- Model: LayoutLMv3-base
|
| 78 |
+
- Epochs: 4
|
| 79 |
+
- Learning rate schedule: Shown in image below
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
### Training Metrics
|
| 82 |
|
| 83 |
+
- **F1 Score** (validation): 
|
| 84 |
+
- **Loss & Learning Rate Chart**: 
|
| 85 |
|
| 86 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
## Evaluation
|
| 89 |
|
| 90 |
+
### Metrics Used
|
| 91 |
+
- F1 score
|
| 92 |
+
- Match score of predicted spans
|
| 93 |
+
- Token overlap vs ground truth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
### Summary
|
| 96 |
|
| 97 |
+
The model performs well on document-style QA tasks, especially with:
|
| 98 |
+
- Clearly structured OCR results
|
| 99 |
+
- Document types similar to utility bills, invoices, and forms
|
| 100 |
|
| 101 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
## How to Use
|
| 104 |
|
| 105 |
+
```python
|
| 106 |
+
from transformers import LayoutLMv3Processor, LayoutLMv3ForQuestionAnswering
|
| 107 |
+
from PIL import Image
|
| 108 |
+
import torch
|
| 109 |
|
| 110 |
+
processor = LayoutLMv3Processor.from_pretrained("lakshya-singh/document-qa-model")
|
| 111 |
+
model = LayoutLMv3ForQuestionAnswering.from_pretrained("lakshya-singh/document-qa-model")
|
| 112 |
|
| 113 |
+
image = Image.open("your_document.png")
|
| 114 |
+
question = "What is the total amount due?"
|
| 115 |
|
| 116 |
+
inputs = processor(image, question, return_tensors="pt")
|
| 117 |
+
outputs = model(**inputs)
|
| 118 |
|
| 119 |
+
start_idx = torch.argmax(outputs.start_logits)
|
| 120 |
+
end_idx = torch.argmax(outputs.end_logits)
|
| 121 |
|
| 122 |
+
answer = processor.tokenizer.decode(inputs["input_ids"][0][start_idx:end_idx+1])
|
| 123 |
+
print("Answer:", answer)
|