LiLT Model Read Here. This model being fine-tuned on English DocVQA

from transformers import AutoTokenizer, AutoModelForQuestionAnswering
from datasets import load_dataset

model_checkpoint = "TusharGoel/LiLT-Document-QA"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, add_prefix_space=True)
model_predict = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint)

model_predict.eval()
dataset = load_dataset("nielsr/funsd", split="train")
example = dataset[0]
print(example)

question = "What is the Licensee Number?"
print(question)

words = example["words"]
boxes = example["bboxes"]

encoding = tokenizer(question, words, boxes = boxes, return_token_type_ids=True, return_tensors="pt")

word_ids = encoding.word_ids(0)
outputs = model_predict(**encoding)

loss = outputs.loss
start_scores = outputs.start_logits
end_scores = outputs.end_logits

start, end = word_ids[start_scores.argmax(-1).item()], word_ids[end_scores.argmax(-1).item()]
# print(start, end)
print(" ".join(words[start : end + 1]))
Downloads last month
329
Safetensors
Model size
130M params
Tensor type
F32
ยท
Inference Providers NEW
This model is not currently available via any of the supported Inference Providers.
The model cannot be deployed to the HF Inference API: The model authors have turned it off explicitly.

Spaces using TusharGoel/LiLT-Document-QA 2