hhou435 commited on
Commit
ba8e039
1 Parent(s): c771c42

First version of the chinese_roberta_L-8_H-128 model and tokenizer.

Browse files
Files changed (7) hide show
  1. README.md +176 -0
  2. config.json +23 -0
  3. pytorch_model.bin +3 -0
  4. special_tokens_map.json +1 -0
  5. tf_model.h5 +3 -0
  6. tokenizer_config.json +1 -0
  7. vocab.txt +0 -0
README.md ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: Chinese
3
+ datasets: CLUECorpusSmall
4
+ widget:
5
+ - text: "北京是[MASK]国的首都。"
6
+
7
+ ---
8
+
9
+
10
+ # Chinese RoBERTa Miniatures
11
+
12
+ ## Model description
13
+
14
+ This is the set of 24 Chinese RoBERTa models pre-trained by [UER-py](https://www.aclweb.org/anthology/D19-3041.pdf).
15
+
16
+ [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 24 Chinese RoBERTa models. In order to facilitate users to reproduce the results, we used the publicly available corpus and provided all training details.
17
+
18
+ You can download the 24 Chinese RoBERTa miniatures either from the [UER-py Github page](https://github.com/dbiir/UER-py/), or via HuggingFace from the links below:
19
+
20
+ | | H=128 | H=256 | H=512 | H=768 |
21
+ | -------- | :-----------------------: | :-----------------------: | :-------------------------: | :-------------------------: |
22
+ | **L=2** | [**2/128 (Tiny)**][2_128] | [2/256] | [2/512] | [2/768] |
23
+ | **L=4** | [4/128] | [**4/256 (Mini)**][4_256] | [**4/512 (Small)**][4_512] | [4/768] |
24
+ | **L=6** | [6/128] | [6/256] | [6/512] | [6/768] |
25
+ | **L=8** | [8/128] | [8/256] | [**8/512 (Medium)**][8_512] | [8/768] |
26
+ | **L=10** | [10/128] | [10/256] | [10/512] | [10/768] |
27
+ | **L=12** | [12/128] | [12/256] | [12/512] | [**12/768 (Base)**][12_768] |
28
+
29
+ Here are scores on the devlopment set of six Chinese tasks:
30
+
31
+ | Model | Score | douban | chnsenticorp | lcqmc | tnews(CLUE) | iflytek(CLUE) | ocnli(CLUE) |
32
+ | -------------- | :---: | :----: | :----------: | :---: | :---------: | :-----------: | :---------: |
33
+ | RoBERTa-Tiny | 72.3 | 83.0 | 91.4 | 81.8 | 62.0 | 55.0 | 60.3 |
34
+ | RoBERTa-Mini | 75.7 | 84.8 | 93.7 | 86.1 | 63.9 | 58.3 | 67.4 |
35
+ | RoBERTa-Small | 76.8 | 86.5 | 93.4 | 86.5 | 65.1 | 59.4 | 69.7 |
36
+ | RoBERTa-Medium | 77.8 | 87.6 | 94.8 | 88.1 | 65.6 | 59.5 | 71.2 |
37
+ | RoBERTa-Base | 79.5 | 89.1 | 95.2 | 89.2 | 67.0 | 60.9 | 75.5 |
38
+
39
+ For each task, we selected the best fine-tuning hyperparameters from the lists below, and trained with the sequence length of 128:
40
+
41
+ - epochs: 3, 5, 8
42
+ - batch sizes: 32, 64
43
+ - learning rates: 3e-5, 1e-4, 3e-4
44
+
45
+ ## How to use
46
+
47
+ You can use this model directly with a pipeline for masked language modeling (take the case of RoBERTa-Medium):
48
+
49
+ ```python
50
+ >>> from transformers import pipeline
51
+ >>> unmasker = pipeline('fill-mask', model='uer/chinese_roberta_L-8_H-512')
52
+ >>> unmasker("中国的首都是[MASK]京。")
53
+ [
54
+ {'sequence': '[CLS] 中 国 的 首 都 是 北 京 。 [SEP]',
55
+ 'score': 0.8701988458633423,
56
+ 'token': 1266,
57
+ 'token_str': '北'},
58
+ {'sequence': '[CLS] 中 国 的 首 都 是 南 京 。 [SEP]',
59
+ 'score': 0.1194809079170227,
60
+ 'token': 1298,
61
+ 'token_str': '南'},
62
+ {'sequence': '[CLS] 中 国 的 首 都 是 东 京 。 [SEP]',
63
+ 'score': 0.0037803512532263994,
64
+ 'token': 691,
65
+ 'token_str': '东'},
66
+ {'sequence': '[CLS] 中 国 的 首 都 是 普 京 。 [SEP]',
67
+ 'score': 0.0017127094324678183,
68
+ 'token': 3249,
69
+ 'token_str': '普'},
70
+ {'sequence': '[CLS] 中 国 的 首 都 是 望 京 。 [SEP]',
71
+ 'score': 0.001687526935711503,
72
+ 'token': 3307,
73
+ 'token_str': '望'}
74
+ ]
75
+ ```
76
+
77
+ Here is how to use this model to get the features of a given text in PyTorch:
78
+
79
+ ```python
80
+ from transformers import BertTokenizer, BertModel
81
+ tokenizer = BertTokenizer.from_pretrained('uer/chinese_roberta_L-8_H-512')
82
+ model = BertModel.from_pretrained("uer/chinese_roberta_L-8_H-512")
83
+ text = "用你喜欢的任何文本替换我。"
84
+ encoded_input = tokenizer(text, return_tensors='pt')
85
+ output = model(**encoded_input)
86
+ ```
87
+
88
+ and in TensorFlow:
89
+
90
+ ```python
91
+ from transformers import BertTokenizer, TFBertModel
92
+ tokenizer = BertTokenizer.from_pretrained('uer/chinese_roberta_L-8_H-512')
93
+ model = TFBertModel.from_pretrained("uer/chinese_roberta_L-8_H-512")
94
+ text = "用你喜欢的任何文本替换我。"
95
+ encoded_input = tokenizer(text, return_tensors='tf')
96
+ output = model(encoded_input)
97
+ ```
98
+
99
+ ## Training data
100
+
101
+ [CLUECorpusSmall](https://github.com/CLUEbenchmark/CLUECorpus2020/) is used as training data. We found that models pre-trained on CLUECorpusSmall outperform those pre-trained on CLUECorpus2020, although CLUECorpus2020 is much larger than CLUECorpusSmall.
102
+
103
+ ## Training procedure
104
+
105
+ Models are pre-trained by [UER-py](https://github.com/dbiir/UER-py/) on [Tencent Cloud TI-ONE](https://cloud.tencent.com/product/tione/). We pre-train 1,000,000 steps with a sequence length of 128 and then pre-train 250,000 additional steps with a sequence length of 512.
106
+
107
+ Taking the case of RoBERTa-Medium
108
+
109
+ Stage1:
110
+
111
+ ```
112
+ python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
113
+ --vocab_path models/google_zh_vocab.txt \
114
+ --dataset_path cluecorpussmall_seq128_dataset.pt \
115
+ --processes_num 32 --seq_length 128 \
116
+ --dynamic_masking --target mlm
117
+ ```
118
+
119
+ ```
120
+ python3 pretrain.py --dataset_path cluecorpussmall_seq128_dataset.pt \
121
+ --vocab_path models/google_zh_vocab.txt \
122
+ --config_path models/bert_medium_config.json \
123
+ --output_model_path models/cluecorpussmall_roberta_medium_seq128_model.bin \
124
+ --world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
125
+ --total_steps 1000000 --save_checkpoint_steps 100000 --report_steps 50000 \
126
+ --learning_rate 1e-4 --batch_size 64 \
127
+ --tie_weights --embedding word_pos_seg --encoder transformer --mask fully_visible --target mlm
128
+ ```
129
+
130
+ Stage2:
131
+
132
+ ```
133
+ python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
134
+ --vocab_path models/google_zh_vocab.txt \
135
+ --dataset_path cluecorpussmall_seq512_dataset.pt \
136
+ --processes_num 32 --seq_length 512 \
137
+ --dynamic_masking --target mlm
138
+ ```
139
+
140
+ ```
141
+ python3 pretrain.py --dataset_path cluecorpussmall_seq512_dataset.pt \
142
+ --pretrained_model_path models/cluecorpussmall_roberta_medium_seq128_model.bin-1000000 \
143
+ --vocab_path models/google_zh_vocab.txt \
144
+ --config_path models/bert_medium_config.json \
145
+ --output_model_path models/cluecorpussmall_roberta_medium_seq512_model.bin \
146
+ --world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
147
+ --total_steps 250000 --save_checkpoint_steps 50000 --report_steps 10000 \
148
+ --learning_rate 5e-5 --batch_size 16 \
149
+ --tie_weights --embedding word_pos_seg --encoder transformer --mask fully_visible --target mlm
150
+ ```
151
+
152
+ Finally, we convert the pre-trained model into Huggingface's format:
153
+
154
+ ```
155
+ python3 scripts/convert_bert_from_uer_to_huggingface.py --input_model_path models/cluecorpussmall_roberta_medium_seq512_model.bin-250000 \
156
+ --output_model_path pytorch_model.bin \
157
+ --layers_num 8 --target mlm
158
+ ```
159
+
160
+ ### BibTeX entry and citation info
161
+
162
+ ```
163
+ @article{zhao2019uer,
164
+ title={UER: An Open-Source Toolkit for Pre-training Models},
165
+ 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},
166
+ journal={EMNLP-IJCNLP 2019},
167
+ pages={241},
168
+ year={2019}
169
+ }
170
+ ```
171
+
172
+ [2_128]: https://huggingface.co/uer/chinese_roberta_L-2_H-128
173
+ [4_256]: https://huggingface.co/uer/chinese_roberta_L-4_H-256
174
+ [4_512]: https://huggingface.co/uer/chinese_roberta_L-4_H-512
175
+ [8_512]: https://huggingface.co/uer/chinese_roberta_L-8_H-512
176
+ [12_768]: https://huggingface.co/uer/chinese_roberta_L-12_H-768
config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForMaskedLM"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "gradient_checkpointing": false,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 128,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 512,
12
+ "layer_norm_eps": 1e-12,
13
+ "max_position_embeddings": 512,
14
+ "model_type": "bert",
15
+ "num_attention_heads": 2,
16
+ "num_hidden_layers": 8,
17
+ "pad_token_id": 0,
18
+ "position_embedding_type": "absolute",
19
+ "transformers_version": "4.2.1",
20
+ "type_vocab_size": 2,
21
+ "use_cache": true,
22
+ "vocab_size": 21128
23
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0c6f90114a5d8e0e0c2575eba56c8c954569e37a09b1aea9be5cd6c661db7842
3
+ size 17638343
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
1
+ {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
tf_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd72c66dbdcceeeb6b9d7d29ce881de71e4816969c6b7b8864c5bd8ed94250bf
3
+ size 28855368
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
1
+ {"do_lower_case": false, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512}
vocab.txt ADDED
The diff for this file is too large to render. See raw diff