Upload 3 files
Browse files- README.md +101 -3
- config.json +166 -0
- pytorch_model.bin +3 -0
README.md
CHANGED
|
@@ -1,3 +1,101 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: KDDA Global Model - Invoices
|
| 3 |
+
emoji: 🐨
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# Configuration
|
| 7 |
+
|
| 8 |
+
`title`: _string_
|
| 9 |
+
Display title for the Space
|
| 10 |
+
|
| 11 |
+
`emoji`: _string_
|
| 12 |
+
Space emoji (emoji-only character allowed)
|
| 13 |
+
|
| 14 |
+
`colorFrom`: _string_
|
| 15 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 16 |
+
|
| 17 |
+
`colorTo`: _string_
|
| 18 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 19 |
+
|
| 20 |
+
`sdk`: _string_
|
| 21 |
+
Can be either `gradio` or `streamlit`
|
| 22 |
+
|
| 23 |
+
`app_file`: _string_
|
| 24 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
| 25 |
+
Path is relative to the root of the repository.
|
| 26 |
+
|
| 27 |
+
`pinned`: _boolean_
|
| 28 |
+
Whether the Space stays on top of your list.
|
| 29 |
+
|
| 30 |
+
# Custom LayoutLM Model for Invoice Processing
|
| 31 |
+
|
| 32 |
+
This repository hosts a custom implementation of the [LayoutLM](https://huggingface.co/microsoft/layoutlm-base-uncased) model, specifically fine-tuned for extracting key information from invoices. The model is designed to identify and extract various fields such as amounts, dates, and names from invoice documents.
|
| 33 |
+
|
| 34 |
+
## Model Overview
|
| 35 |
+
|
| 36 |
+
This model is based on the LayoutLMv2 architecture and has been fine-tuned on a custom dataset of invoices. It is capable of performing token classification to extract the following entities:
|
| 37 |
+
|
| 38 |
+
- **Amount Including Tax**
|
| 39 |
+
- **Due Date**
|
| 40 |
+
- **Reference Number**
|
| 41 |
+
- **Customer Name**
|
| 42 |
+
- **Vendor Name**
|
| 43 |
+
- **Issue Date**
|
| 44 |
+
- **Amount**
|
| 45 |
+
|
| 46 |
+
The model uses a custom set of labels to identify and classify these entities within the invoice documents.
|
| 47 |
+
|
| 48 |
+
## Label Mapping
|
| 49 |
+
|
| 50 |
+
The model has been trained with the following `label2id` and `id2label` mappings:
|
| 51 |
+
|
| 52 |
+
### `label2id` Mapping
|
| 53 |
+
|
| 54 |
+
```json
|
| 55 |
+
{
|
| 56 |
+
"I-Amount Including tax": 0,
|
| 57 |
+
"I-Due Date": 1,
|
| 58 |
+
"I-Reference Number": 2,
|
| 59 |
+
"B-Amount Including tax": 3,
|
| 60 |
+
"I-Customer Name": 4,
|
| 61 |
+
"O": 5,
|
| 62 |
+
"I-Issue Date": 6,
|
| 63 |
+
"B-Amount": 7,
|
| 64 |
+
"B-Vendor Name": 8,
|
| 65 |
+
"I-Vendor Name": 9,
|
| 66 |
+
"B-Customer Name": 10,
|
| 67 |
+
"B-Due Date": 11,
|
| 68 |
+
"I-Amount": 12,
|
| 69 |
+
"B-Reference Number": 13,
|
| 70 |
+
"B-Issue Date": 14
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
### `label2id` Mapping
|
| 74 |
+
|
| 75 |
+
{
|
| 76 |
+
0: "I-Amount Including tax",
|
| 77 |
+
1: "I-Due Date",
|
| 78 |
+
2: "I-Reference Number",
|
| 79 |
+
3: "B-Amount Including tax",
|
| 80 |
+
4: "I-Customer Name",
|
| 81 |
+
5: "O",
|
| 82 |
+
6: "I-Issue Date",
|
| 83 |
+
7: "B-Amount",
|
| 84 |
+
8: "B-Vendor Name",
|
| 85 |
+
9: "I-Vendor Name",
|
| 86 |
+
10: "B-Customer Name",
|
| 87 |
+
11: "B-Due Date",
|
| 88 |
+
12: "I-Amount",
|
| 89 |
+
13: "B-Reference Number",
|
| 90 |
+
14: "B-Issue Date"
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
## Citation
|
| 95 |
+
@article{Xu2020LayoutLMv2MP,
|
| 96 |
+
title={LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding},
|
| 97 |
+
author={Yiheng Xu and Minghao Li and Lei Cui and Shaohan Huang and Furu Wei and Ming Zhou},
|
| 98 |
+
journal={ArXiv},
|
| 99 |
+
year={2020},
|
| 100 |
+
volume={abs/2012.14740}
|
| 101 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "/content/drive/MyDrive/ner/Train_10/Checkpoints",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"LayoutLMv2ForTokenClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"convert_sync_batchnorm": true,
|
| 8 |
+
"coordinate_size": 128,
|
| 9 |
+
"detectron2_config_args": {
|
| 10 |
+
"MODEL.ANCHOR_GENERATOR.SIZES": [
|
| 11 |
+
[
|
| 12 |
+
32
|
| 13 |
+
],
|
| 14 |
+
[
|
| 15 |
+
64
|
| 16 |
+
],
|
| 17 |
+
[
|
| 18 |
+
128
|
| 19 |
+
],
|
| 20 |
+
[
|
| 21 |
+
256
|
| 22 |
+
],
|
| 23 |
+
[
|
| 24 |
+
512
|
| 25 |
+
]
|
| 26 |
+
],
|
| 27 |
+
"MODEL.BACKBONE.NAME": "build_resnet_fpn_backbone",
|
| 28 |
+
"MODEL.FPN.IN_FEATURES": [
|
| 29 |
+
"res2",
|
| 30 |
+
"res3",
|
| 31 |
+
"res4",
|
| 32 |
+
"res5"
|
| 33 |
+
],
|
| 34 |
+
"MODEL.MASK_ON": true,
|
| 35 |
+
"MODEL.PIXEL_STD": [
|
| 36 |
+
57.375,
|
| 37 |
+
57.12,
|
| 38 |
+
58.395
|
| 39 |
+
],
|
| 40 |
+
"MODEL.POST_NMS_TOPK_TEST": 1000,
|
| 41 |
+
"MODEL.RESNETS.ASPECT_RATIOS": [
|
| 42 |
+
[
|
| 43 |
+
0.5,
|
| 44 |
+
1.0,
|
| 45 |
+
2.0
|
| 46 |
+
]
|
| 47 |
+
],
|
| 48 |
+
"MODEL.RESNETS.DEPTH": 101,
|
| 49 |
+
"MODEL.RESNETS.NUM_GROUPS": 32,
|
| 50 |
+
"MODEL.RESNETS.OUT_FEATURES": [
|
| 51 |
+
"res2",
|
| 52 |
+
"res3",
|
| 53 |
+
"res4",
|
| 54 |
+
"res5"
|
| 55 |
+
],
|
| 56 |
+
"MODEL.RESNETS.SIZES": [
|
| 57 |
+
[
|
| 58 |
+
32
|
| 59 |
+
],
|
| 60 |
+
[
|
| 61 |
+
64
|
| 62 |
+
],
|
| 63 |
+
[
|
| 64 |
+
128
|
| 65 |
+
],
|
| 66 |
+
[
|
| 67 |
+
256
|
| 68 |
+
],
|
| 69 |
+
[
|
| 70 |
+
512
|
| 71 |
+
]
|
| 72 |
+
],
|
| 73 |
+
"MODEL.RESNETS.STRIDE_IN_1X1": false,
|
| 74 |
+
"MODEL.RESNETS.WIDTH_PER_GROUP": 8,
|
| 75 |
+
"MODEL.ROI_BOX_HEAD.NAME": "FastRCNNConvFCHead",
|
| 76 |
+
"MODEL.ROI_BOX_HEAD.NUM_FC": 2,
|
| 77 |
+
"MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION": 14,
|
| 78 |
+
"MODEL.ROI_HEADS.IN_FEATURES": [
|
| 79 |
+
"p2",
|
| 80 |
+
"p3",
|
| 81 |
+
"p4",
|
| 82 |
+
"p5"
|
| 83 |
+
],
|
| 84 |
+
"MODEL.ROI_HEADS.NAME": "StandardROIHeads",
|
| 85 |
+
"MODEL.ROI_HEADS.NUM_CLASSES": 5,
|
| 86 |
+
"MODEL.ROI_MASK_HEAD.NAME": "MaskRCNNConvUpsampleHead",
|
| 87 |
+
"MODEL.ROI_MASK_HEAD.NUM_CONV": 4,
|
| 88 |
+
"MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION": 7,
|
| 89 |
+
"MODEL.RPN.IN_FEATURES": [
|
| 90 |
+
"p2",
|
| 91 |
+
"p3",
|
| 92 |
+
"p4",
|
| 93 |
+
"p5",
|
| 94 |
+
"p6"
|
| 95 |
+
],
|
| 96 |
+
"MODEL.RPN.POST_NMS_TOPK_TRAIN": 1000,
|
| 97 |
+
"MODEL.RPN.PRE_NMS_TOPK_TEST": 1000,
|
| 98 |
+
"MODEL.RPN.PRE_NMS_TOPK_TRAIN": 2000
|
| 99 |
+
},
|
| 100 |
+
"fast_qkv": true,
|
| 101 |
+
"gradient_checkpointing": false,
|
| 102 |
+
"has_relative_attention_bias": true,
|
| 103 |
+
"has_spatial_attention_bias": true,
|
| 104 |
+
"has_visual_segment_embedding": false,
|
| 105 |
+
"hidden_act": "gelu",
|
| 106 |
+
"hidden_dropout_prob": 0.1,
|
| 107 |
+
"hidden_size": 768,
|
| 108 |
+
"id2label": {
|
| 109 |
+
"0": "LABEL_0",
|
| 110 |
+
"1": "LABEL_1",
|
| 111 |
+
"2": "LABEL_2",
|
| 112 |
+
"3": "LABEL_3",
|
| 113 |
+
"4": "LABEL_4",
|
| 114 |
+
"5": "LABEL_5",
|
| 115 |
+
"6": "LABEL_6",
|
| 116 |
+
"7": "LABEL_7",
|
| 117 |
+
"8": "LABEL_8",
|
| 118 |
+
"9": "LABEL_9",
|
| 119 |
+
"10": "LABEL_10",
|
| 120 |
+
"11": "LABEL_11",
|
| 121 |
+
"12": "LABEL_12",
|
| 122 |
+
"13": "LABEL_13",
|
| 123 |
+
"14": "LABEL_14"
|
| 124 |
+
},
|
| 125 |
+
"image_feature_pool_shape": [
|
| 126 |
+
7,
|
| 127 |
+
7,
|
| 128 |
+
256
|
| 129 |
+
],
|
| 130 |
+
"initializer_range": 0.02,
|
| 131 |
+
"intermediate_size": 3072,
|
| 132 |
+
"label2id": {
|
| 133 |
+
"LABEL_0": 0,
|
| 134 |
+
"LABEL_1": 1,
|
| 135 |
+
"LABEL_10": 10,
|
| 136 |
+
"LABEL_11": 11,
|
| 137 |
+
"LABEL_12": 12,
|
| 138 |
+
"LABEL_13": 13,
|
| 139 |
+
"LABEL_14": 14,
|
| 140 |
+
"LABEL_2": 2,
|
| 141 |
+
"LABEL_3": 3,
|
| 142 |
+
"LABEL_4": 4,
|
| 143 |
+
"LABEL_5": 5,
|
| 144 |
+
"LABEL_6": 6,
|
| 145 |
+
"LABEL_7": 7,
|
| 146 |
+
"LABEL_8": 8,
|
| 147 |
+
"LABEL_9": 9
|
| 148 |
+
},
|
| 149 |
+
"layer_norm_eps": 1e-12,
|
| 150 |
+
"max_2d_position_embeddings": 1024,
|
| 151 |
+
"max_position_embeddings": 512,
|
| 152 |
+
"max_rel_2d_pos": 256,
|
| 153 |
+
"max_rel_pos": 128,
|
| 154 |
+
"model_type": "layoutlmv2",
|
| 155 |
+
"num_attention_heads": 12,
|
| 156 |
+
"num_hidden_layers": 12,
|
| 157 |
+
"output_past": true,
|
| 158 |
+
"pad_token_id": 0,
|
| 159 |
+
"rel_2d_pos_bins": 64,
|
| 160 |
+
"rel_pos_bins": 32,
|
| 161 |
+
"shape_size": 128,
|
| 162 |
+
"torch_dtype": "float32",
|
| 163 |
+
"transformers_version": "4.10.0.dev0",
|
| 164 |
+
"type_vocab_size": 2,
|
| 165 |
+
"vocab_size": 30522
|
| 166 |
+
}
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5cfefbe82fb24c5651c60693b88177701fce1d50de5df5644c1f32194e8f3990
|
| 3 |
+
size 802294051
|