UIE(Universal Information Extraction) is an SOTA method in PaddleNLP, you can see details
here.
We save the UIE model as a entire model(Ernie 3.0 backbone + start/end layers), so you need to load model as:
1git lfs install
2git clone https://huggingface.co/Pky/uie-base
1import os
2import torch
3from transformers import AutoTokenizer
4
5uie_model = 'uie-base-zh'
6model = torch.load(os.path.join(uie_model, 'pytorch_model.bin')) # load UIE model
7tokenizer = AutoTokenizer.from_pretrained('uie-base') # load tokenizer
8...
9
10start_prob, end_prob = model(input_ids=batch['input_ids'],
11 token_type_ids=batch['token_type_ids'],
12 attention_mask=batch['attention_mask']))
13print(f'start_prob ({type(start_prob)}): {start_prob.size()}') # start_prob
14print(f'end_prob ({type(end_prob)}): {end_prob.size()}') # end_prob
15...
1start_prob (<class 'torch.Tensor'>): torch.Size([16, 256])
2end_prob (<class 'torch.Tensor'>): torch.Size([16, 256])