🚀 中文RoBERTa基础问答模型
本模型用于抽取式问答任务。它能有效从给定文本中提取与问题相关的答案,为问答系统提供了强大的支持。
🚀 快速开始
本模型可直接用于抽取式问答任务。它经过了精心的微调,能高效准确地从文本中提取答案。
✨ 主要特性
💻 使用示例
基础用法
你可以使用以下代码直接调用该模型进行抽取式问答:
>>> from transformers import AutoModelForQuestionAnswering,AutoTokenizer,pipeline
>>> model = AutoModelForQuestionAnswering.from_pretrained('uer/roberta-base-chinese-extractive-qa')
>>> tokenizer = AutoTokenizer.from_pretrained('uer/roberta-base-chinese-extractive-qa')
>>> QA = pipeline('question-answering', model=model, tokenizer=tokenizer)
>>> QA_input = {'question': "著名诗歌《假如生活欺骗了你》的作者是",'context': "普希金从那里学习人民的语言,吸取了许多有益的养料,这一切对普希金后来的创作产生了很大的影响。这两年里,普希金创作了不少优秀的作品,如《囚徒》、《致大海》、《致凯恩》和《假如生活欺骗了你》等几十首抒情诗,叙事诗《努林伯爵》,历史剧《鲍里斯·戈都诺夫》,以及《叶甫盖尼·奥涅金》前六章。"}
>>> QA(QA_input)
{'score': 0.9766426682472229, 'start': 0, 'end': 3, 'answer': '普希金'}
📦 安装指南
本部分文档未提供具体安装命令,故跳过。
📚 详细文档
训练数据
训练数据来自三个来源:cmrc2018、webqa 和 laisi。我们仅使用了这三个数据集的训练集。
训练过程
该模型在 腾讯云 上通过 UER-py 进行微调。我们在预训练模型 chinese_roberta_L-12_H-768 的基础上,以 512 的序列长度进行了三个轮次的微调。在每个轮次结束时,当模型在开发集上取得最佳性能时,会对模型进行保存。
python3 finetune/run_cmrc.py --pretrained_model_path models/cluecorpussmall_roberta_base_seq512_model.bin-250000 \
--vocab_path models/google_zh_vocab.txt \
--train_path datasets/extractive_qa.json \
--dev_path datasets/cmrc2018/dev.json \
--output_model_path models/extractive_qa_model.bin \
--learning_rate 3e-5 --epochs_num 3 --batch_size 32 --seq_length 512
最后,我们将微调后的模型转换为 Huggingface 格式:
python3 scripts/convert_bert_extractive_qa_from_uer_to_huggingface.py --input_model_path models/extractive_qa_model.bin \
--output_model_path pytorch_model.bin \
--layers_num 12
BibTeX 引用和引用信息
@article{liu2019roberta,
title={Roberta: A robustly optimized bert pretraining approach},
author={Liu, Yinhan and Ott, Myle and Goyal, Naman and Du, Jingfei and Joshi, Mandar and Chen, Danqi and Levy, Omer and Lewis, Mike and Zettlemoyer, Luke and Stoyanov, Veselin},
journal={arXiv preprint arXiv:1907.11692},
year={2019}
}
@article{zhao2019uer,
title={UER: An Open-Source Toolkit for Pre-training Models},
author={Zhao, Zhe and Chen, Hui and Zhang, Jinbin and Zhao, Xin and Liu, Tao and Lu, Wei and Chen, Xi and Deng, Haotang and Ju, Qi and Du, Xiaoyong},
journal={EMNLP-IJCNLP 2019},
pages={241},
year={2019}
}
@article{zhao2023tencentpretrain,
title={TencentPretrain: A Scalable and Flexible Toolkit for Pre-training Models of Different Modalities},
author={Zhao, Zhe and Li, Yudong and Hou, Cheng and Zhao, Jing and others},
journal={ACL 2023},
pages={217},
year={2023}
🔧 技术细节
本部分文档未提供具体技术说明,故跳过。
📄 许可证
本部分文档未提供许可证信息,故跳过。