File size: 1,215 Bytes
ff22ecd
 
 
4880398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: afl-3.0
---

# ERNIE-Layout_Pytorch

This is an unofficial Pytorch implementation of [ERNIE-Layout](http://arxiv.org/abs/2210.06155) which is originally released through PaddleNLP.


**A Quick Example**
```python
from networks.modeling_erine_layout import ErnieLayoutConfig, ErnieLayoutForQuestionAnswering
from networks.tokenizer import ErnieLayoutTokenizer


pretrain_torch_model_or_path = "path/to/pretrained-model"

# initialize tokenizer
tokenizer = ErnieLayoutTokenizer.from_pretrained(pretrained_model_name_or_path=pretrain_torch_model_or_path)
encodings = tokenizer.encode_plus(text="Question", text_pair="Answer", add_special_tokens=True,
                                  max_length=512, truncation="only_second",
                                  return_offsets_mapping=True, return_attention_mask=True,
                                  return_overflowing_tokens=True)

# initialize config
config = ErnieLayoutConfig.from_pretrained(pretrained_model_name_or_path=pretrain_torch_model_or_path)
config.num_classes = 2

# initialize ERNIE for VQA
model = ErnieLayoutForQuestionAnswering.from_pretrained(
    pretrained_model_name_or_path=pretrain_torch_model_or_path,
    config=config,
)

```