Update
Browse files
README.md
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: Chinese
|
3 |
+
datasets: CLUECorpusSmall
|
4 |
+
widget:
|
5 |
+
- text: "作为电子为主的电商平台,京东绝对是extra0者。如今的刘强extra1已经是身价过extra2的老板。"
|
6 |
+
|
7 |
+
|
8 |
+
---
|
9 |
+
|
10 |
+
# Chinese T5
|
11 |
+
|
12 |
+
## Model description
|
13 |
+
|
14 |
+
This is the set of Chinese T5 models pre-trained by [UER-py](https://arxiv.org/abs/1909.05658).
|
15 |
+
|
16 |
+
The Text-to-Text Transfer Transformer (T5) leverages a unified text-to-text format and attains state-of-the-art results on a wide variety of English-language NLP tasks. Following their work, we released a series of Chinese T5 models.
|
17 |
+
|
18 |
+
| | Link |
|
19 |
+
| -------- | :-----------------------: |
|
20 |
+
| **T5-Small** | [**L=6/H=512 (Small)**][small] |
|
21 |
+
| **T5-Base** | [**L=12/H=768 (Base)**][base] |
|
22 |
+
|
23 |
+
In T5, spans of the input sequence are masked by so-called sentinel token. Each sentinel token represents a unique mask token for the input sequence and should start with `<extra_id_0>`, `<extra_id_1>`, … up to `<extra_id_99>`. However, `<extra_id_xxx>` is separated into multiple parts in Huggingface's Hosted inference API. Therefore, we replace `<extra_id_xxx>` with `extraxxx` in vocabulary and BertTokenizer regards `extraxxx` as one sentinel token.
|
24 |
+
|
25 |
+
## How to use
|
26 |
+
|
27 |
+
You can use this model directly with a pipeline for text2text generation (take the case of T5-Small):
|
28 |
+
|
29 |
+
```python
|
30 |
+
>>> from transformers import BertTokenizer, T5ForConditionalGeneration, Text2TextGenerationPipeline
|
31 |
+
>>> tokenizer = BertTokenizer.from_pretrained("uer/t5-small-chinese-cluecorpussmall")
|
32 |
+
>>> model = T5ForConditionalGeneration.from_pretrained("uer/t5-small-chinese-cluecorpussmall")
|
33 |
+
>>> text2text_generator = Text2TextGenerationPipeline(model, tokenizer)
|
34 |
+
>>> text2text_generator("中国的首都是extra0京", max_length=50, do_sample=False)
|
35 |
+
[{'generated_text': 'extra0 北 extra1 extra2 extra3 extra4 extra5'}]
|
36 |
+
```
|
37 |
+
|
38 |
+
## Training data
|
39 |
+
|
40 |
+
[CLUECorpusSmall](https://github.com/CLUEbenchmark/CLUECorpus2020/) is used as training data.
|
41 |
+
|
42 |
+
## Training procedure
|
43 |
+
|
44 |
+
The model is pre-trained by [UER-py](https://github.com/dbiir/UER-py/) on [Tencent Cloud](https://cloud.tencent.com/). 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. We use the same hyper-parameters on different model sizes.
|
45 |
+
|
46 |
+
Taking the case of T5-Small
|
47 |
+
|
48 |
+
Stage1:
|
49 |
+
|
50 |
+
```
|
51 |
+
python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
|
52 |
+
--vocab_path models/google_zh_with_sentinel_vocab.txt \
|
53 |
+
--dataset_path cluecorpussmall_t5_seq128_dataset.pt \
|
54 |
+
--processes_num 32 --seq_length 128 \
|
55 |
+
--dynamic_masking --target t5
|
56 |
+
```
|
57 |
+
|
58 |
+
```
|
59 |
+
python3 pretrain.py --dataset_path cluecorpussmall_t5_seq128_dataset.pt \
|
60 |
+
--vocab_path models/google_zh_with_sentinel_vocab.txt \
|
61 |
+
--config_path models/t5/small_config.json \
|
62 |
+
--output_model_path models/cluecorpussmall_t5_seq128_model.bin \
|
63 |
+
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
|
64 |
+
--total_steps 1000000 --save_checkpoint_steps 100000 --report_steps 50000 \
|
65 |
+
--learning_rate 1e-3 --batch_size 64 \
|
66 |
+
--span_masking --span_geo_prob 0.3 --span_max_length 5 \
|
67 |
+
--embedding word --relative_position_embedding --remove_embedding_layernorm --tgt_embedding word \
|
68 |
+
--encoder transformer --mask fully_visible --layernorm_positioning pre\
|
69 |
+
--remove_transformer_bias --decoder transformer \
|
70 |
+
--target t5 --tie_weights
|
71 |
+
|
72 |
+
```
|
73 |
+
|
74 |
+
Stage2:
|
75 |
+
|
76 |
+
```
|
77 |
+
python3 preprocess.py --corpus_path corpora/cluecorpussmall.txt \
|
78 |
+
--vocab_path models/google_zh_with_sentinel_vocab.txt \
|
79 |
+
--dataset_path cluecorpussmall_t5_seq512_dataset.pt \
|
80 |
+
--seq_length 512 --processes_num 32 --target t5 \
|
81 |
+
--dynamic_masking
|
82 |
+
```
|
83 |
+
|
84 |
+
```
|
85 |
+
python3 pretrain.py --dataset_path cluecorpussmall_t5_seq128_dataset.pt \
|
86 |
+
--pretrained_model_path models/cluecorpussmall_t5_seq128_model.bin-1000000 \
|
87 |
+
--vocab_path models/google_zh_with_sentinel_vocab.txt \
|
88 |
+
--config_path models/t5/small_config.json \
|
89 |
+
--output_model_path models/cluecorpussmall_t5_seq512_model.bin \
|
90 |
+
--world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
|
91 |
+
--total_steps 250000 --save_checkpoint_steps 50000 --report_steps 10000 \
|
92 |
+
--learning_rate 1e-3 --batch_size 16 \
|
93 |
+
--span_masking --span_geo_prob 0.3 --span_max_length 5 \
|
94 |
+
--embedding word --relative_position_embedding --remove_embedding_layernorm --tgt_embedding word \
|
95 |
+
--encoder transformer --mask fully_visible --layernorm_positioning pre\
|
96 |
+
--remove_transformer_bias --decoder transformer \
|
97 |
+
--target t5 --tie_weights
|
98 |
+
```
|
99 |
+
|
100 |
+
Finally, we convert the pre-trained model into Huggingface's format:
|
101 |
+
|
102 |
+
```
|
103 |
+
python3 scripts/convert_t5_from_uer_to_huggingface.py --input_model_path cluecorpussmall_t5_seq512_model.bin-250000 \
|
104 |
+
--output_model_path pytorch_model.bin \
|
105 |
+
--layers_num 6 \
|
106 |
+
--type t5
|
107 |
+
```
|
108 |
+
|
109 |
+
|
110 |
+
### BibTeX entry and citation info
|
111 |
+
|
112 |
+
```
|
113 |
+
@article{zhao2019uer,
|
114 |
+
title={UER: An Open-Source Toolkit for Pre-training Models},
|
115 |
+
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},
|
116 |
+
journal={EMNLP-IJCNLP 2019},
|
117 |
+
pages={241},
|
118 |
+
year={2019}
|
119 |
+
}
|
120 |
+
```
|
121 |
+
|
122 |
+
[small]:https://huggingface.co/uer/t5-small-chinese-cluecorpussmall
|
123 |
+
[base]:https://huggingface.co/uer/t5-base-chinese-cluecorpussmall
|