LiLT-SER (Sinhala form understanding: semantic entity recognition)

This model labels each word of a Sinhala form as a QUESTION, ANSWER or HEADER, or as outside these entities. It uses IOB tags. It was released with the SinFUND dataset (SriDoc/datasets).

Model

  • LiLT with an XLM-R base text encoder (nielsr/lilt-xlm-roberta-base), plus a token-classification head.
  • Input: the words of a form and their bounding boxes, scaled to 0-1000. The model does not look at image pixels, so the words must come from an annotation or an OCR system.

Training

Sequential cross-lingual fine-tuning in two stages:

  1. On the French part of XFUND (kavg/LiLT-SER-FR).
  2. On the SinFUND training split (80 forms) for 10,000 steps, with a batch size of 8 and a learning rate of 5e-5.

Results

Results on the SinFUND test split (20 forms, 812 entities). The input was ground-truth words and boxes, and the metric is entity-level precision, recall and F1, micro-averaged over QUESTION, ANSWER and HEADER:

Checkpoint Precision Recall F1
This model (checkpoint selected during training) 0.7618 0.7956 0.7783
Final training step (no selection) 0.7639 0.7771 0.7705
For comparison: fine-tuned on SinFUND only (final step) 0.7056 0.7438 0.7242

Important: SinFUND has no separate validation split. The "validation" scores in the training log below were measured on the SinFUND test split, and the released checkpoint was chosen by its test F1. The selected score is therefore optimistic. The final-step score involves no selection.

Limitations

  • The scores assume perfect text and boxes. With OCR output, especially from handwriting, accuracy will be lower.
  • The SinFUND test split shares templates with the training split (11 of 20 test forms). Results on completely new form layouts may be lower.

Usage

import torch
from transformers import AutoTokenizer, LiltForTokenClassification

tokenizer = AutoTokenizer.from_pretrained("SriDoc/LiLT-SER")
model = LiltForTokenClassification.from_pretrained("SriDoc/LiLT-SER")

words = [...]   # words of the form
boxes = [...]   # one [x0, y0, x1, y1] box per word, scaled to 0-1000

enc = tokenizer(words, is_split_into_words=True, truncation=True, max_length=512, return_tensors="pt")
bbox = [[0, 0, 0, 0] if i is None else boxes[i] for i in enc.word_ids()]
with torch.no_grad():
    logits = model(input_ids=enc["input_ids"], attention_mask=enc["attention_mask"], bbox=torch.tensor([bbox])).logits
pred = logits.argmax(-1)[0].tolist()
# label of each word = prediction for its first sub-token
seen, labels = set(), []
for t, w in enumerate(enc.word_ids()):
    if w is not None and w not in seen:
        seen.add(w)
        labels.append((words[w], model.config.id2label[pred[t]]))

Forms with more than about 500 sub-word tokens must be split into chunks of 512 tokens.

Citation

@article{gunathilaka2025sinfund,
  title   = {SinFUND and SinOCR: Benchmarks for Sinhala Handwritten OCR and Template-Free Form Understanding},
  author  = {Gunathilaka, Kavishka and Hewagama, Danusha and Pushpakumara, Supul and Ambegoda, Thanuja D.},
  journal = {Research Square preprint},
  year    = {2025},
  doi     = {10.21203/rs.3.rs-6976719/v1}
}

Training log

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 5e-05
  • train_batch_size: 8
  • eval_batch_size: 2
  • seed: 42
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: linear
  • training_steps: 10000

Training results

The "Validation" columns were measured on the SinFUND test split (see above).

Training Loss Epoch Step Validation Loss Precision Recall F1 Accuracy
0.0057 21.74 500 0.8019 0.6884 0.7020 0.6951 0.8582
0.008 43.48 1000 1.0139 0.6963 0.7623 0.7278 0.8648
0.0006 65.22 1500 0.9878 0.7090 0.7562 0.7318 0.8592
0.0038 86.96 2000 1.2269 0.7104 0.7401 0.7250 0.8373
0.001 108.7 2500 0.9751 0.7276 0.7697 0.7481 0.8707
0.0004 130.43 3000 1.0918 0.7479 0.7672 0.7574 0.8538
0.0003 152.17 3500 1.0782 0.7102 0.7635 0.7359 0.8604
0.0 173.91 4000 1.0515 0.7402 0.7894 0.7640 0.8704
0.0001 195.65 4500 1.2154 0.7373 0.7709 0.7538 0.8419
0.0 217.39 5000 1.1026 0.7411 0.7722 0.7563 0.8642
0.0001 239.13 5500 1.0594 0.7262 0.7512 0.7385 0.8576
0.0 260.87 6000 1.1103 0.7377 0.7759 0.7563 0.8609
0.0 282.61 6500 1.1591 0.7267 0.7599 0.7429 0.8610
0.0 304.35 7000 1.2382 0.7574 0.7537 0.7556 0.8562
0.0 326.09 7500 1.2027 0.7485 0.7882 0.7678 0.8578
0.0001 347.83 8000 1.1492 0.7433 0.7808 0.7616 0.8659
0.0002 369.57 8500 1.1924 0.7570 0.7980 0.7770 0.8655
0.0 391.3 9000 1.2426 0.7618 0.7956 0.7783 0.8648
0.0 413.04 9500 1.3078 0.7620 0.7808 0.7713 0.8597
0.0 434.78 10000 1.3219 0.7639 0.7771 0.7705 0.8579

Framework versions

  • Transformers 4.38.2
  • Pytorch 2.1.0+cu121
  • Datasets 2.18.0
  • Tokenizers 0.15.1
Downloads last month
18
Safetensors
Model size
0.3B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for SriDoc/LiLT-SER

Base model

kavg/LiLT-SER-FR
Finetuned
(1)
this model

Paper for SriDoc/LiLT-SER