Update README.md
Browse files
README.md
CHANGED
|
@@ -1,210 +1,137 @@
|
|
| 1 |
-
|
| 2 |
-
library_name: transformers
|
| 3 |
-
tags: []
|
| 4 |
-
---
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
## Model
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 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
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
## Bias, Risks, and Limitations
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
## Training Details
|
| 77 |
|
| 78 |
### Training Data
|
| 79 |
|
| 80 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 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 |
-
precision recall f1-score support
|
| 126 |
-
|
| 127 |
-
ANSWER 0.90 0.93 0.92 817
|
| 128 |
-
HEADER 0.67 0.64 0.66 119
|
| 129 |
-
QUESTION 0.91 0.94 0.93 1077
|
| 130 |
-
|
| 131 |
-
micro avg 0.90 0.92 0.91 2013
|
| 132 |
-
macro avg 0.83 0.84 0.83 2013
|
| 133 |
-
weighted avg 0.89 0.92 0.91 2013
|
| 134 |
-
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
### Results
|
| 139 |
-
|
| 140 |
-
[More Information Needed]
|
| 141 |
-
|
| 142 |
-
#### Summary
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
## Model Examination [optional]
|
| 147 |
-
|
| 148 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 149 |
-
|
| 150 |
-
[More Information Needed]
|
| 151 |
|
| 152 |
## Environmental Impact
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
- **Cloud Provider:** [More Information Needed]
|
| 161 |
-
- **Compute Region:** [More Information Needed]
|
| 162 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 163 |
-
|
| 164 |
-
## Technical Specifications [optional]
|
| 165 |
-
|
| 166 |
-
### Model Architecture and Objective
|
| 167 |
-
|
| 168 |
-
[More Information Needed]
|
| 169 |
-
|
| 170 |
-
### Compute Infrastructure
|
| 171 |
-
|
| 172 |
-
[More Information Needed]
|
| 173 |
-
|
| 174 |
-
#### Hardware
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
#### Software
|
| 179 |
-
|
| 180 |
-
[More Information Needed]
|
| 181 |
-
|
| 182 |
-
## Citation [optional]
|
| 183 |
-
|
| 184 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 185 |
-
|
| 186 |
-
**BibTeX:**
|
| 187 |
-
|
| 188 |
-
[More Information Needed]
|
| 189 |
-
|
| 190 |
-
**APA:**
|
| 191 |
-
|
| 192 |
-
[More Information Needed]
|
| 193 |
-
|
| 194 |
-
## Glossary [optional]
|
| 195 |
-
|
| 196 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 197 |
-
|
| 198 |
-
[More Information Needed]
|
| 199 |
-
|
| 200 |
-
## More Information [optional]
|
| 201 |
-
|
| 202 |
-
[More Information Needed]
|
| 203 |
-
|
| 204 |
-
## Model Card Authors [optional]
|
| 205 |
-
|
| 206 |
-
[More Information Needed]
|
| 207 |
-
|
| 208 |
-
## Model Card Contact
|
| 209 |
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 📄 LayoutLMv3 Fine-Tuned on FUNSD for Key-Value Pair Extraction
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
## Model Details
|
| 4 |
|
| 5 |
+
**Developed by:** nnul
|
| 6 |
+
**Model type:** LayoutLMv3 (`microsoft/layoutlmv3-base`)
|
| 7 |
+
**Language(s):** English
|
| 8 |
+
**License:** Apache 2.0
|
| 9 |
+
**Fine-tuned from:** [microsoft/layoutlmv3-base](https://huggingface.co/microsoft/layoutlmv3-base)
|
| 10 |
|
| 11 |
+
This model is a fine-tuned version of LayoutLMv3 on the [FUNSD](https://huggingface.co/datasets/nielsr/funsd-layoutlmv3) dataset. It has been trained for the task of **form understanding**, specifically **token classification** for extracting structured information from scanned forms (e.g., questions and answers in a key-value format).
|
| 12 |
|
| 13 |
+
---
|
| 14 |
|
| 15 |
+
## Model Description
|
| 16 |
|
| 17 |
+
The model performs token-level classification, labeling each token as one of:
|
| 18 |
|
| 19 |
+
* `QUESTION`
|
| 20 |
+
* `ANSWER`
|
| 21 |
+
* `HEADER`
|
| 22 |
+
* `O` (other)
|
| 23 |
|
| 24 |
+
It takes as input a scanned form image and its OCR-extracted tokens and bounding boxes.
|
| 25 |
|
| 26 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
## Model Sources
|
| 29 |
|
| 30 |
+
* **Dataset:** [nielsr/funsd-layoutlmv3](https://huggingface.co/datasets/nielsr/funsd-layoutlmv3)
|
| 31 |
+
* **Base model:** [microsoft/layoutlmv3-base](https://huggingface.co/microsoft/layoutlmv3-base)
|
| 32 |
|
| 33 |
+
---
|
|
|
|
|
|
|
| 34 |
|
| 35 |
## Uses
|
| 36 |
|
|
|
|
|
|
|
| 37 |
### Direct Use
|
| 38 |
|
| 39 |
+
* Key-value pair extraction from scanned documents
|
| 40 |
+
* Form understanding
|
| 41 |
+
* Preprocessing step for document-based QA, autofill, or RPA systems
|
| 42 |
|
| 43 |
+
### Downstream Use
|
| 44 |
|
| 45 |
+
* Automating information extraction from forms
|
| 46 |
+
* Fine-tuning on custom form datasets (insurance, tax, invoices, etc.)
|
|
|
|
| 47 |
|
| 48 |
### Out-of-Scope Use
|
| 49 |
|
| 50 |
+
* Documents not structured like forms
|
| 51 |
+
* Non-English documents (was not trained on multilingual data)
|
| 52 |
+
* Highly noisy OCR (e.g., handwriting)
|
| 53 |
|
| 54 |
+
---
|
| 55 |
|
| 56 |
## Bias, Risks, and Limitations
|
| 57 |
|
| 58 |
+
* Biased toward the structure and layout of FUNSD forms (U.S.-centric, clean typewritten documents).
|
| 59 |
+
* May perform poorly on handwritten or low-quality scans.
|
| 60 |
+
* Assumes accurate OCR input.
|
| 61 |
|
| 62 |
+
---
|
| 63 |
|
| 64 |
+
## How to Get Started
|
| 65 |
|
| 66 |
+
```python
|
| 67 |
+
from transformers import LayoutLMv3Processor, LayoutLMv3ForTokenClassification
|
| 68 |
+
from PIL import Image
|
| 69 |
|
| 70 |
+
# Load model and processor
|
| 71 |
+
model = LayoutLMv3ForTokenClassification.from_pretrained("nnul/layoutlmv3-finetuned-funsd")
|
| 72 |
+
processor = LayoutLMv3Processor.from_pretrained("nnul/layoutlmv3-finetuned-funsd")
|
| 73 |
|
| 74 |
+
# Load and prepare image + OCR tokens and boxes
|
| 75 |
+
image = Image.open("your_form.jpg").convert("RGB")
|
| 76 |
+
words = ["Name", ":", "John", "Doe"]
|
| 77 |
+
boxes = [[100,100,150,120], [155,100,160,120], [165,100,220,120], [225,100,270,120]]
|
| 78 |
|
| 79 |
+
encoding = processor(image, words, boxes=boxes, return_tensors="pt")
|
| 80 |
+
outputs = model(**encoding)
|
| 81 |
+
predictions = outputs.logits.argmax(-1)
|
| 82 |
+
```
|
| 83 |
|
| 84 |
+
---
|
| 85 |
|
| 86 |
## Training Details
|
| 87 |
|
| 88 |
### Training Data
|
| 89 |
|
| 90 |
+
* [FUNSD Dataset](https://huggingface.co/datasets/nielsr/funsd-layoutlmv3)
|
| 91 |
+
* \~199 forms, annotated with token-level BIO labels
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
### Training Hyperparameters
|
| 94 |
|
| 95 |
+
* Epochs: 7
|
| 96 |
+
* Learning rate: default
|
| 97 |
+
* Batch size: 2
|
| 98 |
+
* Optimizer: AdamW
|
| 99 |
+
* Training time: \~5 minutes on A100 (Colab)
|
| 100 |
|
| 101 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
## Evaluation
|
| 104 |
|
| 105 |
+
| Label | Precision | Recall | F1-Score | Support |
|
| 106 |
+
| ---------------- | --------- | -------- | -------- | ------- |
|
| 107 |
+
| ANSWER | 0.90 | 0.93 | 0.92 | 817 |
|
| 108 |
+
| HEADER | 0.67 | 0.64 | 0.66 | 119 |
|
| 109 |
+
| QUESTION | 0.91 | 0.94 | 0.93 | 1077 |
|
| 110 |
+
| **Micro Avg** | **0.90** | **0.92** | **0.91** | 2013 |
|
| 111 |
+
| **Macro Avg** | 0.83 | 0.84 | 0.83 | 2013 |
|
| 112 |
+
| **Weighted Avg** | 0.89 | 0.92 | 0.91 | 2013 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
## Environmental Impact
|
| 117 |
|
| 118 |
+
| Parameter | Value |
|
| 119 |
+
| -------------- | ----------------------- |
|
| 120 |
+
| Hardware Used | NVIDIA A100 GPU (Colab) |
|
| 121 |
+
| Training Time | \~5 minutes |
|
| 122 |
+
| Cloud Provider | Google Colab |
|
| 123 |
+
| Carbon Emitted | Negligible |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
## Citation
|
| 128 |
+
|
| 129 |
+
```
|
| 130 |
+
@misc{layoutlmv3-funsd,
|
| 131 |
+
title={LayoutLMv3 Fine-tuned on FUNSD},
|
| 132 |
+
author={nnul},
|
| 133 |
+
year={2025},
|
| 134 |
+
howpublished={\url{https://huggingface.co/your-username/layoutlmv3-finetuned-funsd}},
|
| 135 |
+
note={Fine-tuned LayoutLMv3 for key-value extraction from forms}
|
| 136 |
+
}
|
| 137 |
+
```
|