Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
| 1 |
---
|
| 2 |
license: gpl-3.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: gpl-3.0
|
| 3 |
+
tags:
|
| 4 |
+
- DocVQA
|
| 5 |
+
- Document Question Answering
|
| 6 |
+
- Document Visual Question Answering
|
| 7 |
+
datasets:
|
| 8 |
+
- MP-DocVQA
|
| 9 |
+
language:
|
| 10 |
+
- en
|
| 11 |
---
|
| 12 |
+
|
| 13 |
+
# LayoutLMv3 base fine-tuned on MP-DocVQA
|
| 14 |
+
|
| 15 |
+
This is pretrained LayoutLMv3 from [Microsoft hub](https://huggingface.co/microsoft/layoutlmv3-base) and fine-tuned on Multipage DocVQA (MP-DocVQA) dataset.
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
This model was used as a baseline in [Hierarchical multimodal transformers for Multi-Page DocVQA](https://arxiv.org/pdf/2212.05935.pdf).
|
| 19 |
+
- Results on the MP-DocVQA dataset are reported in Table 2.
|
| 20 |
+
- Training hyperparameters can be found in Table 8 of Appendix D.
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
## How to use
|
| 24 |
+
|
| 25 |
+
Here is how to use this model to get the features of a given text in PyTorch:
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
import torch
|
| 29 |
+
from transformers import LayoutLMv3Processor, LayoutLMv3ForQuestionAnswering
|
| 30 |
+
|
| 31 |
+
processor = LayoutLMv3Processor.from_pretrained("rubentito/layoutlmv3-base-mpdocvqa", apply_ocr=False)
|
| 32 |
+
model = LayoutLMv3ForQuestionAnswering.from_pretrained("rubentito/layoutlmv3-base-mpdocvqa")
|
| 33 |
+
|
| 34 |
+
image = Image.open("example.jpg").convert("RGB")
|
| 35 |
+
question = "Is this a question?"
|
| 36 |
+
context = ["Example"]
|
| 37 |
+
boxes = [0, 0, 1000, 1000] # This is an example bounding box covering the whole image.
|
| 38 |
+
document_encoding = processor(image, question, context, boxes=boxes, return_tensors="pt")
|
| 39 |
+
outputs = model(**document_encoding)
|
| 40 |
+
|
| 41 |
+
# Get the answer
|
| 42 |
+
start_idx = torch.argmax(outputs.start_logits, axis=1)
|
| 43 |
+
end_idx = torch.argmax(outputs.end_logits, axis=1)
|
| 44 |
+
answers = self.processor.tokenizer.decode(input_tokens[start_idx: end_idx+1]).strip()
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## BibTeX entry
|
| 48 |
+
|
| 49 |
+
```tex
|
| 50 |
+
@article{tito2022hierarchical,
|
| 51 |
+
title={Hierarchical multimodal transformers for Multi-Page DocVQA},
|
| 52 |
+
author={Tito, Rub{\`e}n and Karatzas, Dimosthenis and Valveny, Ernest},
|
| 53 |
+
journal={arXiv preprint arXiv:2212.05935},
|
| 54 |
+
year={2022}
|
| 55 |
+
}
|
| 56 |
+
```
|