Update README.md
Browse files
README.md
CHANGED
|
@@ -3,62 +3,112 @@ library_name: transformers
|
|
| 3 |
license: cc-by-nc-sa-4.0
|
| 4 |
base_model: microsoft/layoutlmv3-base
|
| 5 |
tags:
|
| 6 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
metrics:
|
| 8 |
- accuracy
|
| 9 |
- precision
|
| 10 |
- recall
|
| 11 |
- f1
|
| 12 |
model-index:
|
| 13 |
-
- name: layoutlmv3-finetuned
|
| 14 |
-
results:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
---
|
| 16 |
|
| 17 |
-
|
| 18 |
-
should probably proofread and complete it, then remove this comment. -->
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
## Model description
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
## Intended uses & limitations
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
- learning_rate: 5e-05
|
| 48 |
-
- train_batch_size: 4
|
| 49 |
-
- eval_batch_size: 8
|
| 50 |
-
- seed: 42
|
| 51 |
-
- optimizer: Use OptimizerNames.ADAMW_TORCH_FUSED with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
|
| 52 |
-
- lr_scheduler_type: linear
|
| 53 |
-
- num_epochs: 3
|
| 54 |
|
| 55 |
-
|
|
|
|
| 56 |
|
|
|
|
| 57 |
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
- Datasets 4.0.0
|
| 64 |
-
- Tokenizers 0.22.0
|
|
|
|
| 3 |
license: cc-by-nc-sa-4.0
|
| 4 |
base_model: microsoft/layoutlmv3-base
|
| 5 |
tags:
|
| 6 |
+
- layoutlmv3
|
| 7 |
+
- document-ai
|
| 8 |
+
- invoices
|
| 9 |
+
- token-classification
|
| 10 |
+
- pytorch
|
| 11 |
metrics:
|
| 12 |
- accuracy
|
| 13 |
- precision
|
| 14 |
- recall
|
| 15 |
- f1
|
| 16 |
model-index:
|
| 17 |
+
- name: layoutlmv3-finetuned-invoices
|
| 18 |
+
results:
|
| 19 |
+
- task:
|
| 20 |
+
type: token-classification
|
| 21 |
+
name: Named Entity Recognition (Invoices)
|
| 22 |
+
dataset:
|
| 23 |
+
name: Custom Invoice Dataset
|
| 24 |
+
type: invoices
|
| 25 |
+
split: test
|
| 26 |
+
metrics:
|
| 27 |
+
- name: Precision
|
| 28 |
+
type: precision
|
| 29 |
+
value: 0.9037
|
| 30 |
+
- name: Recall
|
| 31 |
+
type: recall
|
| 32 |
+
value: 0.8871
|
| 33 |
+
- name: F1
|
| 34 |
+
type: f1
|
| 35 |
+
value: 0.8954
|
| 36 |
---
|
| 37 |
|
| 38 |
+
# layoutlmv3-finetuned-invoices
|
|
|
|
| 39 |
|
| 40 |
+
This model is a fine-tuned version of [microsoft/layoutlmv3-base](https://huggingface.co/microsoft/layoutlmv3-base) on a **custom invoice dataset** for document understanding tasks.
|
| 41 |
+
It was trained using the Hugging Face `Trainer` API with early stopping and mixed precision.
|
| 42 |
|
| 43 |
+
## Results
|
| 44 |
+
|
| 45 |
+
The model achieves the following results on the held-out validation set after 10 epochs:
|
| 46 |
+
|
| 47 |
+
| Epoch | Train Loss | Val Loss | Precision | Recall | F1 |
|
| 48 |
+
|-------|------------|----------|-----------|--------|--------|
|
| 49 |
+
| 1 | 0.8329 | 0.7094 | 0.7184 | 0.6524 | 0.6838 |
|
| 50 |
+
| 5 | 0.3815 | 0.3104 | 0.8625 | 0.8559 | 0.8592 |
|
| 51 |
+
| 8 | 0.2988 | 0.2350 | 0.8999 | 0.8803 | 0.8900 |
|
| 52 |
+
| 10 | 0.2499 | 0.2254 | **0.9037**| 0.8872 | **0.8954** |
|
| 53 |
+
|
| 54 |
+
---
|
| 55 |
|
| 56 |
## Model description
|
| 57 |
|
| 58 |
+
- **Architecture**: LayoutLMv3
|
| 59 |
+
- **Base model**: microsoft/layoutlmv3-base
|
| 60 |
+
- **Task**: Token classification for invoice understanding (e.g., extracting key fields).
|
| 61 |
+
- **Input**: Scanned invoices (images + text tokens + bounding boxes).
|
| 62 |
+
- **Output**: Predicted entity labels (e.g., Invoice Number, Date, Vendor, Total).
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
|
| 66 |
## Intended uses & limitations
|
| 67 |
|
| 68 |
+
- **Use cases**:
|
| 69 |
+
- Automatic information extraction from invoices, receipts, and financial documents.
|
| 70 |
+
- Document AI pipelines for expense management and automation.
|
| 71 |
|
| 72 |
+
- **Limitations**:
|
| 73 |
+
- Fine-tuned only on a limited invoice dataset.
|
| 74 |
+
- May not generalize well to other document types (contracts, ID cards, etc.).
|
| 75 |
+
- Sensitive to OCR quality — better input text = better results.
|
| 76 |
|
| 77 |
+
---
|
| 78 |
+
|
| 79 |
+
## Training details
|
| 80 |
+
|
| 81 |
+
### Hyperparameters
|
| 82 |
+
- Learning rate: `3e-5`
|
| 83 |
+
- Train batch size: `4`
|
| 84 |
+
- Eval batch size: `4`
|
| 85 |
+
- Epochs: `10` (with early stopping)
|
| 86 |
+
- Optimizer: AdamW
|
| 87 |
+
- Weight decay: `0.01`
|
| 88 |
+
- Mixed precision (fp16): ✅
|
| 89 |
+
- Workers: `2`
|
| 90 |
|
| 91 |
+
### Framework versions
|
| 92 |
+
- Transformers 4.56.0
|
| 93 |
+
- PyTorch 2.8.0+cu126
|
| 94 |
+
- Datasets 4.0.0
|
| 95 |
+
- Tokenizers 0.22.0
|
| 96 |
|
| 97 |
+
---
|
| 98 |
|
| 99 |
+
## How to use
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
```python
|
| 102 |
+
from transformers import AutoModelForTokenClassification, AutoProcessor
|
| 103 |
|
| 104 |
+
repo_id = "your-username/layoutlmv3-finetuned-invoices"
|
| 105 |
|
| 106 |
+
model = AutoModelForTokenClassification.from_pretrained(repo_id)
|
| 107 |
+
processor = AutoProcessor.from_pretrained(repo_id)
|
| 108 |
|
| 109 |
+
# Example inference
|
| 110 |
+
from PIL import Image
|
| 111 |
+
image = Image.open("sample_invoice.png")
|
| 112 |
|
| 113 |
+
encoding = processor(image, return_tensors="pt")
|
| 114 |
+
outputs = model(**encoding)
|
|
|
|
|
|