Upload 3 files
Browse filesFiles changed (3)
- README.mdAdded+110
- config.jsonAdded+44
- pytorch_model.binAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110# LayoutLMv1 Quantized Model for Form Understanding (FUNSD)
This repository hosts a quantized version of the LayoutLMv1 model, fine-tuned for document information extraction on the FUNSD dataset. The model is optimized for extracting entities such as questions, answers, and headers from scanned forms while maintaining efficient performance for deployment in production environments.
## Model Details
- **Model Architecture:** LayoutLMv1 (Hugging Face Transformers) - **Task:** Token Classification (Form Understanding / Information Extraction) - **Dataset:** [nielsr/funsd](https://huggingface.co/datasets/nielsr/funsd) - **Quantization:** Dynamic Quantization (INT8 for Linear layers) - **Fine-tuning Framework:** PyTorch & Hugging Face Transformers
---
## Usage
### Installation
```shpip install transformers datasets torch torchvision```
### Loading the Quantized Model
```pythonfrom transformers import LayoutLMForTokenClassification, LayoutLMTokenizerimport torch
# Load quantized modelmodel = LayoutLMForTokenClassification.from_pretrained("saved_model_quantized/")model.load_state_dict(torch.load("saved_model_quantized/pytorch_model.bin"))model.eval()
# Load tokenizertokenizer = LayoutLMTokenizer.from_pretrained("microsoft/layoutlm-base-uncased")```
---
## Performance Metrics
| Epoch | Training Loss | Validation Loss ||-------|----------------|------------------|| 0 | 73.67 | 22.15 || 1 | 37.13 | 15.65 || 2 | 26.30 | 16.39 || 3 | 17.68 | 14.45 || 4 | 11.12 | 17.16 |
> π The model steadily improves until Epoch 3, indicating that the best checkpoint may be around this point.
---
## Fine-Tuning Details
### Dataset
- **Name:** `nielsr/funsd` - **Description:** A benchmark dataset for form understanding tasks with manually labeled fields like questions, answers, headers, etc.
### Training Configuration
- **Epochs:** 5 - **Batch Size:** As per available memory - **Learning Rate:** 4e-5 - **Optimizer:** AdamW - **Loss Function:** CrossEntropyLoss (token classification)
---
## Quantization
Dynamic post-training quantization was applied using PyTorch:
```pythonimport torchquantized_model = torch.quantization.quantize_dynamic( model_fp32, {torch.nn.Linear}, dtype=torch.qint8)torch.save(quantized_model.state_dict(), "saved_model_quantized/pytorch_model.bin")```
---
## Repository Structure
```.βββ saved_model/ # Original fine-tuned LayoutLMv1βββ saved_model_quantized/ # INT8 quantized model filesβ βββ config.jsonβ βββ pytorch_model.binβββ README.md # Project documentation```
---
## Limitations
- Trained only on the FUNSD dataset; may not generalize to other document formats.- Quantized version may have slight degradation in performance compared to the full-precision model.- Requires OCR and bounding boxes as input for proper operation.
---
## Contributing
Contributions are welcome! If you have suggestions, improvements, or find bugs, feel free to open an issue or submit a pull request.1234567891011121314151617181920212223242526272829303132333435363738394041424344{ "_attn_implementation_autoset": true, "architectures": [ "LayoutLMForTokenClassification" ], "attention_probs_dropout_prob": 0.1, "hidden_act": "gelu", "hidden_dropout_prob": 0.1, "hidden_size": 768, "id2label": { "0": "LABEL_0", "1": "LABEL_1", "2": "LABEL_2", "3": "LABEL_3", "4": "LABEL_4", "5": "LABEL_5", "6": "LABEL_6" }, "initializer_range": 0.02, "intermediate_size": 3072, "label2id": { "LABEL_0": 0, "LABEL_1": 1, "LABEL_2": 2, "LABEL_3": 3, "LABEL_4": 4, "LABEL_5": 5, "LABEL_6": 6 }, "layer_norm_eps": 1e-12, "max_2d_position_embeddings": 1024, "max_position_embeddings": 512, "model_type": "layoutlm", "num_attention_heads": 12, "num_hidden_layers": 12, "output_past": true, "pad_token_id": 0, "position_embedding_type": "absolute", "torch_dtype": "float32", "transformers_version": "4.51.3", "type_vocab_size": 2, "use_cache": true, "vocab_size": 30522}123version https://git-lfs.github.com/spec/v1oid sha256:a0f4b6415488ff5eb308d2f6eda1ac1c2cef440ff7a1788265931911edcb71e9size 194086670README.mdAdded+110
config.jsonAdded+44
pytorch_model.binAdded+3