Views
No views yet
| 需求 Demand | 任务 Task | 系列 Series | 模型 Model | 参数 Parameter | 额外 Extra |
|---|---|---|---|---|---|
| 通用 General | 自然语言生成 NLG | 燃灯 Randeng | DELLA | 226M | 变分自编码器-中文 VAE-Chinese |
1# Checkout the latest Fengshenbang-LM directory and run following script under Fengshenbang-LM root directory
2
3import torch
4from torch.nn.utils.rnn import pad_sequence
5from fengshen.models.deepVAE.deep_vae import Della
6from transformers.models.bert.tokenization_bert import BertTokenizer
7
8tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-DELLA-226M-Chinese")
9vae_model = Della.from_pretrained("IDEA-CCNL/Randeng-DELLA-226M-Chinese")
10
11special_tokens_dict = {'bos_token': '<BOS>', 'eos_token': '<EOS>'}
12tokenizer.add_special_tokens(special_tokens_dict)
13sentence = "本模型是在通用数据集下预训练的VAE模型,如要获得最佳效果请在特定领域微调后使用。"
14tokenized_text = tokenizer.convert_tokens_to_ids(tokenizer.tokenize(sentence))
15decoder_target = [tokenizer.bos_token_id] + tokenized_text + [tokenizer.eos_token_id]
16inputs = []
17inputs.append(torch.tensor(decoder_target, dtype=torch.long))
18inputs = pad_sequence(inputs, batch_first=True, padding_value=0)
19
20max_length = 256
21top_p = 0.5
22top_k = 0
23temperature = .7
24repetition_penalty = 1.0
25sample = False
26device = 0
27model = vae_model.eval()
28model = model.to(device)
29
30outputs = model.model.inference(inputs.to(device), top_p=top_p, top_k=top_k, max_length=max_length, sample=sample,
31 temperature=temperature, repetition_penalty=repetition_penalty)
32
33for gen_sent, orig_sent in zip(outputs, inputs):
34 print('orig_sent:', tokenizer.decode(orig_sent).replace(' ', ''))
35 print('gen_sent:', tokenizer.decode(gen_sent).replace(' ', ''))
36 print("-"*20)
37
381@article{fengshenbang,
2 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},
3 title = {Fengshenbang 1.0: Being the Foundation of Chinese Cognitive Intelligence},
4 journal = {CoRR},
5 volume = {abs/2209.02970},
6 year = {2022}
7}1@misc{Fengshenbang-LM,
2 title={Fengshenbang-LM},
3 author={IDEA-CCNL},
4 year={2021},
5 howpublished={\url{https://github.com/IDEA-CCNL/Fengshenbang-LM}},
6}