File size: 3,740 Bytes
b45f637
606445f
8ce7e25
1f39a15
8ce7e25
1f39a15
8ce7e25
4f9ab7b
d2f6402
 
8ce7e25
 
db7728d
8ce7e25
 
 
 
3a97366
 
0599fdf
 
 
 
c9c5e85
0599fdf
 
c9c5e85
0599fdf
 
ebe2b2a
0599fdf
 
ebe2b2a
0599fdf
 
ebe2b2a
0599fdf
c9c5e85
 
0599fdf
 
c9c5e85
0599fdf
 
c9c5e85
 
 
 
 
 
 
0599fdf
 
1e4ac02
 
 
 
64262a1
 
 
 
 
 
 
 
1e4ac02
75152a8
0599fdf
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
license: gpl-3.0
tags:
- DocVQA
- Document Question Answering
- Document Visual Question Answering
datasets:
- rubentito/mp-docvqa
language:
- en
---

# BigBird base (ITC) fine-tuned on MP-DocVQA

This is BigBird-base trained on TriviaQA from [Google hub](https://huggingface.co/google/bigbird-base-trivia-itc) and fine-tuned on Multipage DocVQA (MP-DocVQA) dataset.
* Due to Huggingface implementation, the global tokens are defined according to the Internal Transformer Construction (ITC) strategy.

This model was used as a baseline in [Hierarchical multimodal transformers for Multi-Page DocVQA](https://arxiv.org/pdf/2212.05935.pdf).
- Results on the MP-DocVQA dataset are reported in Table 2.
- Training hyperparameters can be found in Table 8 of Appendix D.

## How to use

How to use this model to perform inference on a sample question and context in PyTorch:

```python
from transformers import BigBirdForQuestionAnswering, BigBirdTokenizerFast

# by default its in `block_sparse` mode with num_random_blocks=3, block_size=64
model = BigBirdForQuestionAnswering.from_pretrained("rubentito/bigbird-base-itc-mpdocvqa")

# you can change `attention_type` to full attention like this:
model = BigBirdForQuestionAnswering.from_pretrained("rubentito/bigbird-base-itc-mpdocvqa", attention_type="original_full")

# you can change `block_size` & `num_random_blocks` like this:
model = BigBirdForQuestionAnswering.from_pretrained("rubentito/bigbird-base-itc-mpdocvqa", block_size=16, num_random_blocks=2)

tokenizer = BigBirdTokenizerFast.from_pretrained("rubentito/bigbird-base-itc-mpdocvqa")

question = "Replace me by any text you'd like."
context = "Put some context for answering"

encoded_input = tokenizer(question, context, return_tensors='pt')
output = model(**encoded_input)

start_pos = torch.argmax(output.start_logits, dim=-1).item()
end_pos = torch.argmax(output.end_logits, dim=-1).item()

context_tokens = tokenizer.convert_ids_to_tokens(encoded_input["input_ids"][0].tolist())
answer_tokens = context_tokens[start_pos: end_pos]
answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
```

## Model results

Extended experimentation can be found in Table 2 of [Hierarchical multimodal transformers for Multi-Page DocVQA](https://arxiv.org/pdf/2212.05935.pdf).
You can also check the live leaderboard at the [RRC Portal](https://rrc.cvc.uab.es/?ch=17&com=evaluation&task=4).
| Model 		 																	| HF name								| Parameters 	|	ANLS 		| APPA		|
|-----------------------------------------------------------------------------------|:--------------------------------------|:-------------:|:-------------:|:---------:|
| [Bert large](https://huggingface.co/rubentito/bert-large-mpdocvqa)	            | rubentito/bert-large-mpdocvqa			| 334M 			| 0.4183 		| 51.6177 	|
| [Longformer base](https://huggingface.co/rubentito/longformer-base-mpdocvqa)		| rubentito/longformer-base-mpdocvqa	| 148M			| 0.5287		| 71.1696 	|
| [**BigBird ITC base**](https://huggingface.co/rubentito/bigbird-base-itc-mpdocvqa)| rubentito/bigbird-base-itc-mpdocvqa	| 131M			| 0.4929		| 67.5433 	|
| [LayoutLMv3 base](https://huggingface.co/rubentito/layoutlmv3-base-mpdocvqa)		| rubentito/layoutlmv3-base-mpdocvqa	| 125M 			| 0.4538		| 51.9426 	|
| [T5 base](https://huggingface.co/rubentito/t5-base-mpdocvqa)						| rubentito/t5-base-mpdocvqa			| 223M 			| 0.5050		| 0.0000 	|
| Hi-VT5 																			| TBA 									| 316M 			| 0.6201		| 79.23		|

## Citation Information 

```tex
@article{tito2022hierarchical,
  title={Hierarchical multimodal transformers for Multi-Page DocVQA},
  author={Tito, Rub{\`e}n and Karatzas, Dimosthenis and Valveny, Ernest},
  journal={arXiv preprint arXiv:2212.05935},
  year={2022}
}
```