t5-base-chinese-cluecorpussmall:基于CLUECorpusSmall预训练的中文T5模型,支持文本到文本生成任务

由UER-py预训练的中文T5模型,采用CLUECorpusSmall数据集,适用于文本到文本生成,使用extraxxx作为标记符,可直接通过transformers库调用。【此简介由AI生成】

分支1Tags0
Hhuggingface-webUpdate README.md
206f3951创建于 2023年10月17日15次提交

language: zh datasets: CLUECorpusSmall widget:

  • text: "作为电子extra0的平台,京东绝对是领先者。如今的刘强extra1已经是身价过extra2的老板。"

中文T5模型

模型描述

本系列中文T5模型由UER-py预训练框架研发(详见论文)。此外,这些模型也可通过TencentPretrain进行预训练(参见论文),该框架继承UER-py支持十亿参数以上模型的能力,并扩展为多模态预训练框架。

文本到文本传输转换器(T5)采用统一的文本到文本格式,在众多英语自然语言处理任务中取得了最先进的成果。基于此项研究,我们发布了系列中文T5模型。

您可以通过以下两种方式下载中文T5模型集:

模型规格 下载链接
T5-Small L=6/H=512 (小型)
T5-Base L=12/H=768 (基础)

在T5模型中,输入序列的片段通过特殊标记符(sentinel token)进行掩码处理。每个标记符代表输入序列中唯一的掩码标识,应以<extra_id_0><extra_id_1>……直至<extra_id_99>的形式呈现。由于HuggingFace托管推理API会将<extra_id_xxx>分割为多个部分,我们在词汇表中将其替换为extraxxx,BertTokenizer会将extraxxx识别为完整的标记符。

使用指南

您可以直接通过文本生成管道使用本模型(以T5-Small为例):

>>> from transformers import BertTokenizer, T5ForConditionalGeneration, Text2TextGenerationPipeline
>>> tokenizer = BertTokenizer.from_pretrained("uer/t5-small-chinese-cluecorpussmall")
>>> model = T5ForConditionalGeneration.from_pretrained("uer/t5-small-chinese-cluecorpussmall")
>>> text2text_generator = Text2TextGenerationPipeline(model, tokenizer)  
>>> text2text_generator("中国的首都是extra0京", max_length=50, do_sample=False)
    [{'generated_text': 'extra0 北 extra1 extra2 extra3 extra4 extra5'}]

训练数据

采用CLUECorpusSmall作为训练语料。

训练流程

该模型通过UER-py框架在腾讯云上进行预训练。首先以128的序列长度预训练100万步,随后以512的序列长度追加训练25万步。不同规模的模型均采用相同的超参数配置。

以T5-Small为例:

第一阶段:

python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
                      --vocab_path models/google_zh_with_sentinel_vocab.txt \
                      --dataset_path cluecorpussmall_t5_seq128_dataset.pt \
                      --processes_num 32 --seq_length 128 \
                      --dynamic_masking --data_processor t5 
python3 pretrain.py --dataset_path cluecorpussmall_t5_seq128_dataset.pt \
                    --vocab_path models/google_zh_with_sentinel_vocab.txt \
                    --config_path models/t5/small_config.json \
                    --output_model_path models/cluecorpussmall_t5_small_seq128_model.bin \
                    --world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
                    --total_steps 1000000 --save_checkpoint_steps 100000 --report_steps 50000 \
                    --learning_rate 1e-3 --batch_size 64 \
                    --span_masking --span_geo_prob 0.3 --span_max_length 5

第二阶段:

python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
                      --vocab_path models/google_zh_with_sentinel_vocab.txt \
                      --dataset_path cluecorpussmall_t5_small_seq512_dataset.pt \
                      --processes_num 32 --seq_length 512 \
                      --dynamic_masking --data_processor t5
python3 pretrain.py --dataset_path cluecorpussmall_t5_seq512_dataset.pt \
                    --vocab_path models/google_zh_with_sentinel_vocab.txt \
                    --pretrained_model_path models/cluecorpussmall_t5_small_seq128_model.bin-1000000 \
                    --config_path models/t5/small_config.json \
                    --output_model_path models/cluecorpussmall_t5_small_seq512_model.bin \
                    --world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
                    --total_steps 250000 --save_checkpoint_steps 50000 --report_steps 10000 \
                    --learning_rate 5e-4 --batch_size 16 \
                    --span_masking --span_geo_prob 0.3 --span_max_length 5

最后,我们将预训练模型转换为Huggingface的格式:

python3 scripts/convert_t5_from_uer_to_huggingface.py --input_model_path models/cluecorpussmall_t5_small_seq512_model.bin-250000 \
                                                      --output_model_path pytorch_model.bin \
                                                      --layers_num 6 \
                                                      --type t5

BibTeX 条目与引用信息

@article{2020t5,
  title   = {Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer},
  author  = {Colin Raffel and Noam Shazeer and Adam Roberts and Katherine Lee and Sharan Narang and Michael Matena and Yanqi Zhou and Wei Li and Peter J. Liu},
  journal = {Journal of Machine Learning Research},
  pages   = {1-67},
  year    = {2020}
}

@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}

项目介绍

由UER-py预训练的中文T5模型,采用CLUECorpusSmall数据集,适用于文本到文本生成,使用extraxxx作为标记符,可直接通过transformers库调用。【此简介由AI生成】

定制我的领域

下载使用量

0

项目总下载次数(含Clone、Pull、 zip 包及 release 下载),每日凌晨更新