hhou435 commited on
Commit
638960a
1 Parent(s): 062046d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +86 -0
README.md CHANGED
@@ -5,3 +5,89 @@ widget:
5
  - text: "[CLS] 青 山 削 芙 蓉 ,"
6
 
7
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  - text: "[CLS] 青 山 削 芙 蓉 ,"
6
 
7
  ---
8
+
9
+ # Chinese GPT2 Language Models
10
+
11
+ ## Model description
12
+
13
+ This is the set of two Chinese GPT2 language models pre-trained by [UER-py](https://www.aclweb.org/anthology/D19-3041.pdf).
14
+
15
+ You can download the two Chinese GPT2 language models via HuggingFace from the links below:
16
+
17
+ | Model | [gpt2-chinese-poem][poem] | [gpt2-chinese-couplet][couplet] |
18
+ | :-----------: | :------------------------------------------: | :-------------------------------------: |
19
+ | Training data | Contains about 800,000 chinese ancient poems | contains about 700,000 chinese couplets |
20
+
21
+
22
+
23
+ ## How to use
24
+
25
+ Because the parameter ***skip_special_tokens*** is used in the ***pipelines.py*** , special tokens such as [SEP], [UNK] will be deleted, and the output results may not be neat.
26
+
27
+ You can use this model directly with a pipeline for text generation:
28
+
29
+ When the parameter ***skip_special_tokens*** is True:
30
+
31
+ ```python
32
+ >>> from transformers import BertTokenizer, GPT2LMHeadModel, TextGenerationPipeline
33
+ >>> from transformers import TextGenerationPipeline,
34
+ >>> tokenizer = BertTokenizer.from_pretrained("uer/gpt2-chinese-poem")
35
+ >>> model = GPT2LMHeadModel.from_pretrained("uer/gpt2-chinese-poem")
36
+ >>> text_generator = TextGenerationPipeline(model, tokenizer)
37
+ >>> text_generator("[CLS]梅 山 如 积 翠 ,", max_length=50, do_sample=True)
38
+ [{'generated_text': '[CLS]梅 山 如 积 翠 , 的 手 堪 捧 。 遥 遥 仙 人 尉 , 盘 盘 故 时 陇 。 丹 泉 清 可 鉴 , 石 乳 甘 于 。 行 将 解 尘 缨 , 于 焉 蹈 高 踵 。 我'}]
39
+ ```
40
+
41
+ When the parameter ***skip_special_tokens*** is Flase:
42
+
43
+ ```python
44
+ >>> from transformers import BertTokenizer, GPT2LMHeadModel, TextGenerationPipeline
45
+ >>> from transformers import TextGenerationPipeline,
46
+ >>> tokenizer = BertTokenizer.from_pretrained("uer/gpt2-chinese-poem")
47
+ >>> model = GPT2LMHeadModel.from_pretrained("uer/gpt2-chinese-poem")
48
+ >>> text_generator = TextGenerationPipeline(model, tokenizer)
49
+ >>> text_generator("[CLS]梅 山 如 积 翠 ,", max_length=50, do_sample=True)
50
+ [{'generated_text': '[CLS]梅 山 如 积 翠 , 的 [UNK] 手 堪 捧 。 遥 遥 仙 人 尉 , 盘 盘 故 时 陇 。 丹 泉 清 可 鉴 , 石 乳 甘 可 捧 。 银 汉 迟 不 来 , 槎 头 欲 谁 揽 。 何'}]
51
+ ```
52
+
53
+ ## Training data
54
+
55
+ Contains about 800,000 chinese ancient poems.
56
+
57
+ ## Training procedure
58
+
59
+ 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 200,000 steps with a sequence length of 128.
60
+
61
+ ```
62
+ python3 preprocess.py --corpus_path corpora/poem.txt \
63
+ --vocab_path models/google_zh_vocab.txt \
64
+ --dataset_path poem.pt --processes_num 16 \
65
+ --seq_length 128 --target lm
66
+ ```
67
+
68
+ ```
69
+ python3 pretrain.py --dataset_path poem.pt \
70
+ --vocab_path models/google_zh_vocab.txt \
71
+ --output_model_path models/poem_gpt_base_model.bin \
72
+ --config_path models/bert_base_config.json --learning_rate 5e-4 \
73
+ --tie_weight --world_size 8 --gpu_ranks 0 1 2 3 4 5 6 7 \
74
+ --batch_size 64 --report_steps 1000 \
75
+ --save_checkpoint_steps 50000 --total_steps 200000 \
76
+ --embedding gpt --encoder gpt2 --target lm
77
+
78
+ ```
79
+
80
+ ### BibTeX entry and citation info
81
+
82
+ ```
83
+ @article{zhao2019uer,
84
+ title={UER: An Open-Source Toolkit for Pre-training Models},
85
+ 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},
86
+ journal={EMNLP-IJCNLP 2019},
87
+ pages={241},
88
+ year={2019}
89
+ }
90
+ ```
91
+
92
+ [poem]: https://huggingface.co/uer/gpt2-chinese-poem
93
+ [couplet]: https://huggingface.co/uer/gpt2-chinese-couplet