A deep VAE model pretrained on Wudao dataset and finetinued on NER dataset. Both encoder and decoder are based on GPT-2 architecture. This model is capable of generating a sentence given the named entity and its entity type.
Note that although we adopted the layer-wise recurrent latent variables structure as the paper, we did not use the low-rank-tensor-product to fuse the latent vectors to the decoder hidden states. Instead we applied a simple linear transformation on the latent vectors and then add them to the hidden states independently.
使用 Usage
# Checkout the latest Fengshenbang-LM directory and run following script under Fengshenbang-LM root directory import torch
from torch.nn.utils.rnn import pad_sequence
from fengshen.models.deepVAE.deep_vae import Della
from transformers.models.bert.tokenization_bert import BertTokenizer
tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese")
vae_model = Della.from_pretrained("IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese")
special_tokens_dict = {'bos_token': '<BOS>', 'eos_token': '<EOS>', 'additional_special_tokens': ['<ENT>', '<ENS>']}
tokenizer.add_special_tokens(special_tokens_dict)
device = 0
model = vae_model.model.to(device)
ent_token_type_id = tokenizer.additional_special_tokens_ids[0]
ent_token_sep_id = tokenizer.additional_special_tokens_ids[1]
bos_token_id, eos_token_id = tokenizer.bos_token_id, tokenizer.eos_token_id
decoder_target, decoder_entities = [], []
entity_list = [('深圳', '地点/地理位置'), ('昨天', '时间')]
for ent in entity_list:
entity_name = tokenizer.convert_tokens_to_ids(tokenizer.tokenize(ent[0]))
entity_type = tokenizer.convert_tokens_to_ids(tokenizer.tokenize(ent[1]))
decoder_entities.extend(entity_name + [ent_token_type_id] + entity_type + [ent_token_sep_id])
decoder_entities.extend([bos_token_id]) # for generation
decoder_target.append(torch.tensor(decoder_entities, dtype=torch.long))
inputs = pad_sequence(decoder_target, batch_first=True, padding_value=0)
encoder_outputs = model.encoder(input_ids=inputs.to(device))
prior_z_list, prior_output_list = model.get_cond_prior_vecs(encoder_outputs.hidden_states[1:],
inputs, sample=True, beta_logvar=0.)
outputs = model.decoder.generate(input_ids=inputs.to(device), layer_latent_vecs=prior_z_list, labels=None,
label_ignore=model.pad_token_id, num_return_sequences=32, max_new_tokens=256,
eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id,
no_repeat_ngram_size=-1, do_sample=True, top_p=0.8)
print(tokenizer.decode(inputs[0]))
gen_sents = []
for idx inrange(len(outputs)):
sent_len= 512if eos_token_id notin outputs[idx].tolist() else outputs[idx].tolist().index(eos_token_id) + 1
start_loc = outputs[idx].tolist().index(bos_token_id)
gen_sent = tokenizer.decode(outputs[idx][start_loc:sent_len]).replace(' ', '')
ifall([ent[0] in gen_sent for ent in entity_list]):
gen_sents.append(gen_sent)
for s in gen_sents:
print(s)
If you are using the resource for your work, please cite the our
paper
:
@article{fengshenbang,
author = {Jiaxing Zhang and Ruyi Gan and Junjie Wang and Yuxiang Zhang and Lin Zhang and Ping Yang and Xinyu Gao and Ziwei Wu and Xiaoqun Dong and Junqing He and Jianheng Zhuo and Qi Yang and Yongfeng Huang and Xiayu Li and Yanghan Wu and Junyu Lu and Xinyu Zhu and Weifeng Chen and Ting Han and Kunhao Pan and Rui Wang and Hao Wang and Xiaojun Wu and Zhongshen Zeng and Chongpei Chen},
title = {Fengshenbang 1.0: Being the Foundation of Chinese Cognitive Intelligence},
journal = {CoRR},
volume = {abs/2209.02970},
year = {2022}
}
Randeng-DELLA-CVAE-226M-NER-Chinese huggingface.co is an AI model on huggingface.co that provides Randeng-DELLA-CVAE-226M-NER-Chinese's model effect (), which can be used instantly with this IDEA-CCNL Randeng-DELLA-CVAE-226M-NER-Chinese model. huggingface.co supports a free trial of the Randeng-DELLA-CVAE-226M-NER-Chinese model, and also provides paid use of the Randeng-DELLA-CVAE-226M-NER-Chinese. Support call Randeng-DELLA-CVAE-226M-NER-Chinese model through api, including Node.js, Python, http.
Randeng-DELLA-CVAE-226M-NER-Chinese huggingface.co is an online trial and call api platform, which integrates Randeng-DELLA-CVAE-226M-NER-Chinese's modeling effects, including api services, and provides a free online trial of Randeng-DELLA-CVAE-226M-NER-Chinese, you can try Randeng-DELLA-CVAE-226M-NER-Chinese online for free by clicking the link below.
IDEA-CCNL Randeng-DELLA-CVAE-226M-NER-Chinese online free url in huggingface.co:
Randeng-DELLA-CVAE-226M-NER-Chinese is an open source model from GitHub that offers a free installation service, and any user can find Randeng-DELLA-CVAE-226M-NER-Chinese on GitHub to install. At the same time, huggingface.co provides the effect of Randeng-DELLA-CVAE-226M-NER-Chinese install, users can directly use Randeng-DELLA-CVAE-226M-NER-Chinese installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
Randeng-DELLA-CVAE-226M-NER-Chinese install url in huggingface.co: