语言: 中文
数据集: CLUECorpusSmall
微件示例:
中文RoBERTa微型模型集
模型描述
这是由UER-py预训练的24个中文RoBERTa模型系列,相关技术细节详见该论文。此外,这些模型也可通过TencentPretrain进行预训练,该框架在这篇论文中提出,继承了UER-py并支持十亿级参数量的模型,同时扩展为多模态预训练框架。
Turc等人的研究表明标准BERT方案在不同模型规模下均有效。基于此,我们发布了这24个中文RoBERTa模型。为便于复现结果,我们使用公开语料库并提供了完整训练细节。
您可以通过以下方式获取这些模型:
|
H=128 |
H=256 |
H=512 |
H=768 |
L=2 |
[2/128 (超小)][2_128] |
[2/256][2_256] |
[2/512][2_512] |
[2/768][2_768] |
L=4 |
[4/128][4_128] |
[4/256 (迷你)][4_256] |
[4/512 (小型)][4_512] |
[4/768][4_768] |
L=6 |
[6/128][6_128] |
[6/256][6_256] |
[6/512][6_512] |
[6/768][6_768] |
L=8 |
[8/128][8_128] |
[8/256][8_256] |
[8/512 (中型)][8_512] |
[8/768][8_768] |
L=10 |
[10/128][10_128] |
[10/256][10_256] |
[10/512][10_512] |
[10/768][10_768] |
L=12 |
[12/128][12_128] |
[12/256][12_256] |
[12/512][12_512] |
[12/768 (基础)][12_768] |
以下是六个中文任务开发集上的表现:
模型 |
综合得分 |
书评情感 |
中文情感分析 |
句子匹配 |
新闻分类(CLUE) |
应用分类(CLUE) |
自然语言推理(CLUE) |
RoBERTa-超小 |
72.3 |
83.4 |
91.4 |
81.8 |
62.0 |
55.0 |
60.3 |
RoBERTa-迷你 |
75.9 |
85.7 |
93.7 |
86.1 |
63.9 |
58.3 |
67.4 |
RoBERTa-小型 |
76.9 |
87.5 |
93.4 |
86.5 |
65.1 |
59.4 |
69.7 |
RoBERTa-中型 |
78.0 |
88.7 |
94.8 |
88.1 |
65.6 |
59.5 |
71.2 |
RoBERTa-基础 |
79.7 |
90.1 |
95.2 |
89.2 |
67.0 |
60.9 |
75.5 |
每个任务均从以下超参数组合中选择最优配置(序列长度固定为128):
- 训练轮次:3/5/8
- 批大小:32/64
- 学习率:3e-5/1e-4/3e-4
使用方式
掩码预测示例(以RoBERTa-中型为例):
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='uer/chinese_roberta_L-8_H-512')
>>> unmasker("中国的首都是[MASK]京。")
[
{'sequence': '[CLS] 中 国 的 首 都 是 北 京 。 [SEP]',
'score': 0.8702,
'token': 1266,
'token_str': '北'},
{'sequence': '[CLS] 中 国 的 首 都 是 南 京 。 [SEP]',
'score': 0.1195,
'token': 1298,
'token_str': '南'},
...(其他预测结果)
]
特征提取示例:
PyTorch版本:
from transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained('uer/chinese_roberta_L-8_H-512')
model = BertModel.from_pretrained("uer/chinese_roberta_L-8_H-512")
text = "输入任意文本内容"
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
TensorFlow版本:
from transformers import BertTokenizer, TFBertModel
tokenizer = BertTokenizer.from_pretrained('uer/chinese_roberta_L-8_H-512')
model = TFBertModel.from_pretrained("uer/chinese_roberta_L-8_H-512")
text = "输入任意文本内容"
encoded_input = tokenizer(text, return_tensors='tf')
output = model(encoded_input)
训练数据
使用CLUECorpusSmall作为训练语料。值得注意的是,虽然CLUECorpus2020规模更大,但我们发现基于CLUECorpusSmall预训练的模型表现更优。
训练流程
模型在腾讯云上通过UER-py完成预训练:
- 第一阶段:128序列长度训练1,000,000步
- 第二阶段:512序列长度追加训练250,000步
不同规模模型采用相同超参数。
以RoBERTa-中型为例:
python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
--vocab_path models/google_zh_vocab.txt \
--dataset_path cluecorpussmall_seq128_dataset.pt \
--processes_num 32 --seq_length 128 \
--dynamic_masking --data_processor mlm
python3 pretrain.py --dataset_path cluecorpussmall_seq128_dataset.pt \
--vocab_path models/google_zh_vocab.txt \
--config_path models/bert/medium_config.json \
--output_model_path models/cluecorpussmall_roberta_medium_seq128_model.bin \
--world_size 8 --gpu_ranks 0-7 \
--total_steps 1000000 --save_checkpoint_steps 100000 --report_steps 50000 \
--learning_rate 1e-4 --batch_size 64 \
--data_processor mlm --target mlm
python3 scripts/convert_bert_from_uer_to_huggingface.py \
--input_model_path models/cluecorpussmall_roberta_medium_seq512_model.bin-250000 \
--output_model_path pytorch_model.bin \
--layers_num 8 --type mlm
引用文献
@article{devlin2018bert,
title={BERT: 面向语言理解的深度双向变换器预训练},
author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
journal={arXiv预印本 arXiv:1810.04805},
year={2018}
}
...(其他文献引用保持原格式)
[模型链接矩阵保持不变]