ubiai deep learning

How to Train the LILT Model on Invoices and Run Inference

Jan 3, 2023

LILT Model Architecture:

How to Train the LILT Model on Invoices and Run Inference
LILT Model Architecture. Source

Model Fine-tuning:

from transformers import LiltForTokenClassification
# huggingface hub model id
model_id = "SCUT-DLVCLab/lilt-roberta-en-base"

 

# load model with correct number of labels and mapping
model = LiltForTokenClassification.from_pretrained(
model_id, num_labels=len(label_list), label2id=label2id, id2label=id2label
)

NUM_TRAIN_EPOCHS = 120
PER_DEVICE_TRAIN_BATCH_SIZE = 6
PER_DEVICE_EVAL_BATCH_SIZE = 6
LEARNING_RATE = 4e-5
How to Train the LILT Model on Invoices and Run Inference
Image by Author: Model Training In Progress.
{
'eval_precision': 0.6335952848722987,
'eval_recall': 0.7413793103448276,
'eval_f1': 0.6832627118644069,
}
 torch.save(model,'/content/drive/MyDrive/LILT_Model/lilt.pth')

Model Inference:

 
How to Train the LILT Model on Invoices and Run Inference
Image by Author: LILT output on invoice 1
How to Train the LILT Model on Invoices and Run Inference

Image by Author: LILT output on invoice 2

How to Train the LILT Model on Invoices and Run Inference
Image by Author: LILT output on invoice 3

Conclusion