language: zh
datasets: CLUECorpusSmall
widget:
中文GPT2模型系列
模型描述
本系列GPT2模型(除GPT2-xlarge外)均由UER-py预训练,相关论文见此处。GPT2-xlarge模型由TencentPretrain预训练,该框架继承UER-py支持十亿参数以上模型,并扩展为多模态预训练框架(论文见此处)。其他模型也可通过TencentPretrain进行预训练。
这些模型用于生成中文文本。您可以通过以下链接从HuggingFace下载,或访问UER-py模型库:
注: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步。
以UER-py预训练的GPT2-distil为例:
第一阶段:
预处理与训练命令(详见原文)...
第二阶段:
长序列预处理与训练命令(详见原文)...
最终转换为Huggingface格式:
python3 scripts/convert_gpt2_from_uer_to_huggingface.py --input_model_path models/cluecorpussmall_gpt2_distil_seq1024_model.bin-250000 \
--output_model_path pytorch_model.bin \
--layers_num 6
GPT2-xlarge使用TencentPretrain训练:
深度速度训练命令与权重转换(详见原文)...
参考文献
@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}