shibing624 commited on
Commit
3f167e2
1 Parent(s): 456d588

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +109 -1
README.md CHANGED
@@ -1,3 +1,111 @@
1
  ---
2
- license: apache-2.0
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - zh
4
+ tags:
5
+ - chatglm
6
+ - pytorch
7
+ - zh
8
+ - Text2Text-Generation
9
+ license: "apache-2.0"
10
+ widget:
11
+ - text: "对下面中文拼写纠错:\n少先队员因该为老人让坐。\n答:"
12
+
13
  ---
14
+
15
+ # Chinese Spelling Correction LoRA Model
16
+ ChatGLM中文纠错LoRA模型
17
+
18
+ `chatglm-6b-csc-zh-lora` evaluate test data:
19
+
20
+ The overall performance of chatglm-6b-csc-zh-lora on CSC **test**:
21
+
22
+ |prefix|input_text|target_text|pred|
23
+ |:-- |:--- |:--- |:-- |
24
+ |对下面中文拼写纠错:|少先队员因该为老人让坐。|少先队员应该为老人让座。|少先队员应该为老人让座。\n错误字:因,坐|
25
+
26
+ 在CSC测试集上生成结果纠错准确率高,由于是基于大模型,结果常常能带给人惊喜,不仅能纠错,还带有句子润色和改写功能。
27
+
28
+
29
+ ## Usage
30
+
31
+ 本项目开源在lmft项目:[textgen](https://github.com/shibing624/lmft),可支持ChatGLM模型,通过如下命令调用:
32
+
33
+ Install package:
34
+ ```shell
35
+ pip install -U lmft
36
+ ```
37
+
38
+ ```python
39
+ from lmft import ChatGlmModel
40
+ model = ChatGlmModel("chatglm", "THUDM/chatglm-6b", lora_name="shibing624/chatglm-6b-csc-zh-lora")
41
+ r = model.predict(["对下面中文拼写纠错:\n少先队员因该为老人让坐。\n答:"])
42
+ print(r) # ['少先队员应该为老人让座。\n错误字:因,坐']
43
+ ```
44
+
45
+ ## Usage (HuggingFace Transformers)
46
+ Without [lmft](https://github.com/shibing624/lmft), you can use the model like this:
47
+
48
+ First, you pass your input through the transformer model, then you get the generated sentence.
49
+
50
+ Install package:
51
+ ```
52
+ pip install transformers
53
+ ```
54
+
55
+ ```python
56
+ import sys
57
+ from peft import PeftModel
58
+ from transformers import AutoModel, AutoTokenizer
59
+
60
+ sys.path.append('..')
61
+
62
+ model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True, device_map='auto')
63
+ model = PeftModel.from_pretrained(model, "shibing624/chatglm-6b-csc-zh-lora")
64
+ model = model.half().cuda() # fp16
65
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
66
+
67
+ sents = ['对下面中文拼写纠错:\n少先队员因该为老人让坐。\n答:',
68
+ '对下面中文拼写纠错:\n下个星期,我跟我朋唷打算去法国玩儿。\n答:']
69
+ for s in sents:
70
+ response = model.chat(tokenizer, s, max_length=128, eos_token_id=tokenizer.eos_token_id)
71
+ print(response)
72
+ ```
73
+
74
+ output:
75
+ ```shell
76
+ ('少先队员应该为老人让座。\n错误字:因,坐', [('对下面中文拼写纠错:\n少先队员因该为老人让坐。\n答:', '少先队员应该为老人让座。\n错误字:因,坐')])
77
+ ('下个星期,我跟我朋友打算去法国玩儿。\n错误字:唷', [('对下面中文拼写纠错:\n下个星期,我跟我朋唷打算去法国玩儿。\n答:', '下个星期,我跟我朋友打算去法国玩儿。\n错误字:唷')])
78
+ ```
79
+
80
+
81
+ 模型文件组成:
82
+ ```
83
+ chatglm-6b-csc-zh-lora
84
+ ├── adapter_config.json
85
+ └── adapter_model.bin
86
+ ```
87
+
88
+
89
+ ### 训练数据集
90
+ #### 中文纠错数据集
91
+
92
+ - 数据:[shibing624/CSC](https://huggingface.co/datasets/shibing624/CSC)
93
+
94
+
95
+
96
+ 如果需要训练ChatGLM模型,请参考[https://github.com/shibing624/lmft](https://github.com/shibing624/lmft)
97
+
98
+
99
+ ## Citation
100
+
101
+ ```latex
102
+ @software{lmft,
103
+ author = {Xu Ming},
104
+ title = {lmft: Implementation of language model finetune},
105
+ year = {2023},
106
+ url = {https://github.com/shibing624/lmft},
107
+ }
108
+ ```
109
+
110
+
111
+