Norm's picture
Update README.md
50fd90a
|
raw
history blame
1.27 kB
metadata
license: afl-3.0

ERNIE-Layout_Pytorch

This repo is an unofficial Pytorch implementation of ERNIE-Layout which is originally released through PaddleNLP.

A Quick Example

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,
)