🚀 燃灯-T5-784M-中文问答模型
这是一款基于T5架构的中文问答模型,可根据给定段落和问题生成流畅准确的答案,在多个问答指标上表现出色。
🚀 快速开始
本模型是huggingface上首个中文的生成式问答模型。它基于T5-Large结构,使用悟道180G语料在封神框架进行预训练,在翻译的中文SQuAD和CMRC2018两个阅读理解数据集上进行微调。输入一篇文章和一个问题,它可以生成准确流畅的回答。
安装
pip install transformers==4.21.1
使用示例
import numpy as np
from transformers import T5Tokenizer,MT5ForConditionalGeneration
pretrain_path = 'IDEA-CCNL/Randeng-T5-784M-QA-Chinese'
tokenizer=T5Tokenizer.from_pretrained(pretrain_path)
model=MT5ForConditionalGeneration.from_pretrained(pretrain_path)
sample={"context":"在柏林,胡格诺派教徒创建了两个新的社区:多罗西恩斯塔特和弗里德里希斯塔特。到1700年,这个城市五分之一的人口讲法语。柏林胡格诺派在他们的教堂服务中保留了将近一个世纪的法语。他们最终决定改用德语,以抗议1806-1807年拿破仑占领普鲁士。他们的许多后代都有显赫的地位。成立了几个教会,如弗雷德里夏(丹麦)、柏林、斯德哥尔摩、汉堡、法兰克福、赫尔辛基和埃姆登的教会。","question":"除了多罗西恩斯塔特,柏林还有哪个新的社区?","idx":1}
plain_text='question:'+sample['question']+'knowledge:'+sample['context'][:self.max_knowledge_length]
res_prefix=tokenizer.encode('answer',add_special_tokens=False)
res_prefix.append(tokenizer.convert_tokens_to_ids('<extra_id_0>'))
res_prefix.append(tokenizer.eos_token_id)
l_rp=len(res_prefix)
tokenized=tokenizer.encode(plain_text,add_special_tokens=False,truncation=True,max_length=1024-2-l_rp)
tokenized+=res_prefix
batch=[tokenized]*2
input_ids=torch.tensor(np.array(batch),dtype=torch.long)
max_target_length=128
pred_ids = model.generate(input_ids=input_ids,max_new_tokens=max_target_length,do_sample=True,top_p=0.9)
pred_tokens=tokenizer.batch_decode(pred_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
res=pred_tokens.replace('<extra_id_0>','').replace('有答案:','')
✨ 主要特性
- 首个中文生成式问答模型:在huggingface上率先推出针对中文的生成式问答模型。
- 高质量训练:基于悟道180G语料预训练,并在中文SQuAD和CMRC2018数据集上微调。
- 高生成质量和准确率:76%的回答包含了正确答案,RougeL和BLEU - 4反映出预测结果和标准答案有较高的重合度。
📦 安装指南
pip install transformers==4.21.1
📚 详细文档
模型类别
属性 |
详情 |
需求 |
通用 |
任务 |
自然语言转换 |
系列 |
燃灯 |
模型 |
T5 |
参数 |
784M |
额外 |
中文生成式问答 |
模型表现
在CMRC 2018的测试集上进行评估(原始任务是起始和结束预测问题,这里作为生成回答的问题):
模型 |
包含答案率 |
RougeL |
BLEU - 4 |
F1 |
EM |
本模型 |
76.0 |
82.7 |
61.1 |
77.9 |
57.1 |
MacBERT - Large(SOTA) |
- |
- |
- |
88.9 |
70.0 |
我们的模型有着极高的生成质量和准确率,76%的回答包含了正确答案(包含答案率)。RougeL和BLEU - 4反映了模型预测结果和标准答案重合的程度。我们的模型EM值较低,因为生成的大部分为完整的句子,而标准答案通常是句子片段。需要注意的是,SOTA模型只需预测起始和结束位置,这种抽取式阅读理解任务比生成式的简单很多。
样例
以下是随机抽取的样本:

pred 为生成结果,target 为标准答案。
如果图片无法显示,您可以在文件和版本中找到该图片。
📄 许可证
本模型使用的许可证为Apache - 2.0。
📖 引用
如果您在您的工作中使用了我们的模型,可以引用我们的论文:
@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}
}
也欢迎引用我们的网站:
@misc{Fengshenbang-LM,
title={Fengshenbang-LM},
author={IDEA-CCNL},
year={2021},
howpublished={\url{https://github.com/IDEA-CCNL/Fengshenbang-LM}},
}