Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: zh
|
3 |
+
datasets: CLUECorpusSmall
|
4 |
+
widget:
|
5 |
+
- text: "北京是[MASK]国的首都。"
|
6 |
+
|
7 |
+
---
|
8 |
+
|
9 |
+
# Chinese Xlarge Whole Word Masking RoBERTa Model
|
10 |
+
|
11 |
+
## Model description
|
12 |
+
|
13 |
+
This is an xlarge Chinese Whole Word Masking RoBERTa model pre-trained by [TencentPretrain](https://github.com/Tencent/TencentPretrain) introduced in [this paper](https://arxiv.org/abs/2212.06385), which inherits [UER-py](https://github.com/dbiir/UER-py/) to support models with parameters above one billion, and extends it to a multimodal pre-training framework.
|
14 |
+
|
15 |
+
[Turc et al.](https://arxiv.org/abs/1908.08962) have shown that the standard BERT recipe is effective on a wide range of model sizes. Following their paper, we released the xlarge Chinese Whole Word Masking RoBERTa model. In order to facilitate users in reproducing the results, we used a publicly available corpus and word segmentation tool, and provided all training details.
|
16 |
+
|
17 |
+
You can download the model either from the [UER-py Modelzoo page](https://github.com/dbiir/UER-py/wiki/Modelzoo), or via HuggingFace from the link [roberta-xlarge-wwm-chinese-cluecorpussmall](https://huggingface.co/uer/roberta-xlarge-wwm-chinese-cluecorpussmall):
|
18 |
+
|
19 |
+
## How to use
|
20 |
+
|
21 |
+
You can use this model directly with a pipeline for masked language modeling:
|
22 |
+
|
23 |
+
```python
|
24 |
+
>>> from transformers import pipeline
|
25 |
+
>>> unmasker = pipeline('fill-mask', model='uer/roberta-xlarge-wwm-chinese-cluecorpussmall')
|
26 |
+
>>> unmasker("北京是[MASK]国的首都。")
|
27 |
+
|
28 |
+
```
|
29 |
+
|
30 |
+
Here is how to use this model to get the features of a given text in PyTorch:
|
31 |
+
|
32 |
+
```python
|
33 |
+
from transformers import BertTokenizer, BertModel
|
34 |
+
tokenizer = BertTokenizer.from_pretrained('uer/roberta-xlarge-wwm-chinese-cluecorpussmall')
|
35 |
+
model = BertModel.from_pretrained("uer/roberta-xlarge-wwm-chinese-cluecorpussmall")
|
36 |
+
text = "用你喜欢的任何文本替换我。"
|
37 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
38 |
+
output = model(**encoded_input)
|
39 |
+
```
|
40 |
+
|
41 |
+
and in TensorFlow:
|
42 |
+
|
43 |
+
```python
|
44 |
+
from transformers import BertTokenizer, TFBertModel
|
45 |
+
tokenizer = BertTokenizer.from_pretrained('uer/roberta-xlarge-wwm-chinese-cluecorpussmall')
|
46 |
+
model = TFBertModel.from_pretrained("uer/roberta-xlarge-wwm-chinese-cluecorpussmall")
|
47 |
+
text = "用你喜欢的任何文本替换我。"
|
48 |
+
encoded_input = tokenizer(text, return_tensors='tf')
|
49 |
+
output = model(encoded_input)
|
50 |
+
```
|
51 |
+
|
52 |
+
## Training data
|
53 |
+
|
54 |
+
[CLUECorpusSmall](https://github.com/CLUEbenchmark/CLUECorpus2020/) is used as training data.
|
55 |
+
|
56 |
+
## Training procedure
|
57 |
+
|
58 |
+
Models are pre-trained by [TencentPretrain](https://github.com/Tencent/TencentPretrain) on [Tencent Cloud](https://cloud.tencent.com/). We pre-train 500,000 steps with a sequence length of 128 and then pre-train 250,000 additional steps with a sequence length of 512.
|
59 |
+
|
60 |
+
[jieba](https://github.com/fxsjy/jieba) is used as word segmentation tool.
|
61 |
+
|
62 |
+
Stage1:
|
63 |
+
|
64 |
+
```
|
65 |
+
python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
|
66 |
+
--vocab_path models/google_zh_vocab.txt \
|
67 |
+
--dataset_path cluecorpussmall_seq128_dataset.pt \
|
68 |
+
--processes_num 32 --seq_length 128 \
|
69 |
+
--dynamic_masking --data_processor mlm
|
70 |
+
```
|
71 |
+
|
72 |
+
```
|
73 |
+
deepspeed pretrain.py --deepspeed --deepspeed_config models/deepspeed_config.json --dataset_path cluecorpussmall_seq128_dataset.pt \
|
74 |
+
--vocab_path models/google_zh_vocab.txt \
|
75 |
+
--config_path models/bert/xlarge_config.json \
|
76 |
+
--output_model_path models/cluecorpussmall_wwm_roberta_xlarge_seq128_model \
|
77 |
+
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
|
78 |
+
--total_steps 500000 --save_checkpoint_steps 50000 --report_steps 500 \
|
79 |
+
--learning_rate 2e-5 --batch_size 128 --deep_init \
|
80 |
+
--whole_word_masking --deepspeed_checkpoint_activations \
|
81 |
+
--data_processor mlm --target mlm
|
82 |
+
```
|
83 |
+
|
84 |
+
Before stage2, we extract fp32 consolidated weights from a zero 2 and 3 DeepSpeed checkpoints:
|
85 |
+
|
86 |
+
```
|
87 |
+
python3 models/cluecorpussmall_wwm_roberta_xlarge_seq128_model/zero_to_fp32.py models/cluecorpussmall_wwm_roberta_xlarge_seq128_model/ \
|
88 |
+
models/cluecorpussmall_wwm_roberta_xlarge_seq128_model.bin
|
89 |
+
```
|
90 |
+
|
91 |
+
Stage2:
|
92 |
+
|
93 |
+
```
|
94 |
+
python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
|
95 |
+
--vocab_path models/google_zh_vocab.txt \
|
96 |
+
--dataset_path cluecorpussmall_seq512_dataset.pt \
|
97 |
+
--processes_num 32 --seq_length 512 \
|
98 |
+
--dynamic_masking --data_processor mlm
|
99 |
+
```
|
100 |
+
|
101 |
+
```
|
102 |
+
deepspeed pretrain.py --deepspeed --deepspeed_config models/deepspeed_config.json --dataset_path cluecorpussmall_seq512_dataset.pt \
|
103 |
+
--vocab_path models/google_zh_vocab.txt \
|
104 |
+
--config_path models/bert/xlarge_config.json \
|
105 |
+
--pretrained_model_path models/cluecorpussmall_wwm_roberta_xlarge_seq128_model.bin \
|
106 |
+
--output_model_path models/cluecorpussmall_wwm_roberta_xlarge_seq512_model \
|
107 |
+
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
|
108 |
+
--total_steps 250000 --save_checkpoint_steps 50000 --report_steps 500 \
|
109 |
+
--learning_rate 5e-5 --batch_size 32 \
|
110 |
+
--whole_word_masking --deepspeed_checkpoint_activations \
|
111 |
+
--data_processor mlm --target mlm
|
112 |
+
```
|
113 |
+
|
114 |
+
Then, we extract fp32 consolidated weights from a zero 2 and 3 DeepSpeed checkpoints:
|
115 |
+
|
116 |
+
```
|
117 |
+
python3 models/cluecorpussmall_wwm_roberta_xlarge_seq512_model/zero_to_fp32.py models/cluecorpussmall_wwm_roberta_xlarge_seq512_model/ \
|
118 |
+
models/cluecorpussmall_wwm_roberta_xlarge_seq512_model.bin
|
119 |
+
```
|
120 |
+
|
121 |
+
Finally, we convert the pre-trained model into Huggingface's format:
|
122 |
+
|
123 |
+
```
|
124 |
+
python3 scripts/convert_bert_from_tencentpretrain_to_huggingface.py --input_model_path models/cluecorpussmall_wwm_roberta_xlarge_seq512_model.bin \
|
125 |
+
--output_model_path pytorch_model.bin \
|
126 |
+
--layers_num 36 --type mlm
|
127 |
+
```
|
128 |
+
|
129 |
+
### BibTeX entry and citation info
|
130 |
+
|
131 |
+
```
|
132 |
+
@article{zhao2019uer,
|
133 |
+
title={UER: An Open-Source Toolkit for Pre-training Models},
|
134 |
+
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},
|
135 |
+
journal={EMNLP-IJCNLP 2019},
|
136 |
+
pages={241},
|
137 |
+
year={2019}
|
138 |
+
}
|
139 |
+
|
140 |
+
@article{zhao2023tencentpretrain,
|
141 |
+
title={TencentPretrain: A Scalable and Flexible Toolkit for Pre-training Models of Different Modalities},
|
142 |
+
author={Zhao, Zhe and Li, Yudong and Hou, Cheng and Zhao, Jing and others},
|
143 |
+
journal={ACL 2023},
|
144 |
+
pages={217},
|
145 |
+
year={2023}
|
146 |
+
```
|