mymusise commited on
Commit
35aaa80
1 Parent(s): 9de5220

update Readme

Browse files

Signed-off-by: mymusise <mymusise1@gmail.com>

Files changed (1) hide show
  1. README.md +48 -0
README.md ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: zh
3
+ widget:
4
+ - text: "天下熙熙,"
5
+ - text: "天气不错,"
6
+ ---
7
+
8
+ <h1 align="center">
9
+ CPM-Generate-distill
10
+ </h1>
11
+
12
+ CPM(Chinese Pre-Trained Language Models), which has 2.6B parameters, made by the research team of Beijing Zhiyuan Institute of artificial intelligence and Tsinghua University @TsinghuaAI.
13
+
14
+ [repo: CPM-Generate](https://github.com/TsinghuaAI/CPM-Generate)
15
+ The One Thing You Need to Know is this model is not uploaded by official, the conver script is [here](https://github.com/mymusise/CPM-TF2Transformer/blob/main/transfor_CMP.ipynb)
16
+
17
+ And the `CPM-Generate-distill` is the distill model of `CPM`.
18
+
19
+
20
+ # How to use
21
+
22
+ How to use this model directly from the 🤗/transformers library:
23
+
24
+ ```python
25
+ from transformers import XLNetTokenizer, TFGPT2LMHeadModel
26
+ from transformers import TextGenerationPipeline
27
+ import jieba
28
+ # add spicel process
29
+ class XLNetTokenizer(XLNetTokenizer):
30
+ translator = str.maketrans(" \n", "\u2582\u2583")
31
+ def _tokenize(self, text, *args, **kwargs):
32
+ text = [x.translate(self.translator) for x in jieba.cut(text, cut_all=False)]
33
+ text = " ".join(text)
34
+ return super()._tokenize(text, *args, **kwargs)
35
+ def _decode(self, *args, **kwargs):
36
+ text = super()._decode(*args, **kwargs)
37
+ text = text.replace(' ', '').replace('\u2582', ' ').replace('\u2583', '\n')
38
+ return text
39
+
40
+ tokenizer = XLNetTokenizer.from_pretrained('mymusise/CPM-Generate-distill')
41
+ model = TFGPT2LMHeadModel.from_pretrained("mymusise/CPM-Generate-distill")
42
+
43
+ text_generater = TextGenerationPipeline(model, tokenizer)
44
+
45
+ print(text_generater("天下熙熙,", max_length=15, top_k=1, use_cache=True, prefix=''))
46
+ ```
47
+
48
+ ![avatar](https://github.com/mymusise/CPM-TF2Transformer/raw/main/example-cpm-distill.jpeg)