Downloads · 30 days
14
1% of all-time downloads
TusharGoel/LiLT-Document-QA
LiLT-Document-QA is a document question answering model from TusharGoel. Use it for the document question answering task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
LiLT Model Read Here. This model being fine-tuned on English DocVQA
Downloads · 30 days
14
1% of all-time downloads
All-time downloads
2.6K
Public
Parameters
130M
3.6 GB on disk
Likes
3
Public
Click a slice to open those files.
.bin521 MB · 50%
From the Hugging Face model README
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]))