CoolFace
Modelpublic

fanxiao/CGRE_CNDBPedia-Generative-Relation-Extraction

sourceHugging Faceupdated 3y agoView on Hugging Face
4likes34downloads
Model Card

CGRE is a generation-based relation extraction model

·a SOTA chinese end-to-end relation extraction model,using bart as backbone.

·using the Distant-supervised data from cndbpedia,pretrained from the checkpoint of fnlp/bart-base-chinese.

·can perform SOTA in many chinese relation extraction dataset,such as DuIE~1.0,DuIE~2.0,HacRED,etc.

·easy to use,just like normal generation task.

·input is sentence,and output is linearlize triples,such as input:姚明是一名NBA篮球运动员 output:[subj]姚明[obj]NBA[rel]公司[obj]篮球运动员[rel]职业

using model:

from transformers import BertTokenizer, BartForConditionalGeneration

model_name = 'fnlp/bart-base-chinese'

tokenizerkwargs = { "usefast": True, "additionalspecialtokens": ['<rel>', '<obj>', '<subj>'], } # if cannot see tokens in model card please open readme file

tokenizer = BertTokenizer.frompretrained(modelname, **tokenizer_kwargs)

model = BartForConditionalGeneration.frompretrained('./CGRECNDBPedia-Generative-Relation-Extraction')

inputs = tokenizer(sent, maxlength=maxsourcelength, padding="maxlength", truncation=True, return_tensors="pt")

params = {"decoderstarttokenid":0,"earlystopping":False,"norepeatngramsize":0,"lengthpenalty": 0,"numbeams":20,"usecache":True}

outid = model.generate(inputs["inputids"], attentionmask = inputs["attentionmask"], maxlength=maxtarget_length, **params)