语言: 中文
数据集: CLUECorpusSmall
小部件示例:
中文GPT2模型系列
模型描述
本系列GPT2模型(除GPT2-xlarge外)均由UER-py预训练实现,相关论文见此处。GPT2-xlarge模型由TencentPretrain预训练完成,该框架继承UER-py支持十亿参数以上模型,并扩展为多模态预训练框架(详见论文)。其他模型也可通过TencentPretrain进行预训练。
这些模型用于生成中文文本。您可以通过以下方式获取:
注:6层模型参照distilgpt2配置,其预训练不依赖大模型监督,故称GPT2-distil。
使用示例
通过文本生成管道直接调用(以GPT2-distil为例):
>>> from transformers import BertTokenizer, GPT2LMHeadModel, TextGenerationPipeline
>>> tokenizer = BertTokenizer.from_pretrained("uer/gpt2-distil-chinese-cluecorpussmall")
>>> model = GPT2LMHeadModel.from_pretrained("uer/gpt2-distil-chinese-cluecorpussmall")
>>> text_generator = TextGenerationPipeline(model, tokenizer)
>>> text_generator("这是很久之前的事情了", max_length=100, do_sample=True)
[{'generated_text': '这是很久之前的事情了 。 我 现 在 想 起 来 就 让 自 己 很 伤 心 , 很 失 望 。 我 现 在 想 到 , 我 觉 得 大 多 数 人 的 生 活 比 我 的 生 命 还 要 重 要 , 对 一 些 事 情 的 看 法 , 对 一 些 人 的 看 法 , 都 是 在 发 泄 。 但 是 , 我 们 的 生 活 是 需 要 一 个 信 用 体 系 的 。 我 不 知'}]
训练数据
使用CLUECorpusSmall作为训练语料。
训练流程
GPT2-xlarge通过TencentPretrain预训练,其余模型使用UER-py在腾讯云完成。训练分为两个阶段:
- 序列长度128,训练1,000,000步
- 序列长度1024,追加训练250,000步
以GPT2-distil为例(UER-py版本):
第一阶段:
预处理与训练命令...
第二阶段:
长序列预处理与训练命令...
最终转换为Huggingface格式:
python3 scripts/convert_gpt2_from_uer_to_huggingface.py...
GPT2-xlarge使用TencentPretrain训练:
第一阶段:
DeepSpeed训练命令...
权重转换:
zero_checkpoint转换命令...
第二阶段:
长序列DeepSpeed训练命令...
最终转换:
python3 scripts/convert_gpt2_from_tencentpretrain_to_huggingface.py...
文献引用
@article{radford2019language,
title={Language Models are Unsupervised Multitask Learners},
author={Radford, Alec and Wu, Jeff and Child, Rewon and Luan, David and Amodei, Dario and Sutskever, Ilya},
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}