Jerome2046 commited on
Commit
acabc67
1 Parent(s): 03baa10

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +13 -2
README.md CHANGED
@@ -8,13 +8,24 @@ pipeline_tag: text-classification
8
 
9
  加载代码:
10
  ```python
 
 
 
 
 
11
  tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True)
12
- config = AutoConfig.from_pretrained("glm-emotion", trust_remote_code=True, pre_seq_len=128)
13
- model = AutoModel.from_pretrained("glm-emotion", config=config, trust_remote_code=True)
 
14
  prefix_state_dict = torch.load(os.path.join("glm-emotion", "pytorch_model.bin"))
15
  new_prefix_state_dict = {}
16
  for k, v in prefix_state_dict.items():
17
  if k.startswith("transformer.prefix_encoder."):
18
  new_prefix_state_dict[k[len("transformer.prefix_encoder."):]] = v
19
  model.transformer.prefix_encoder.load_state_dict(new_prefix_state_dict)
 
 
 
 
 
20
  ```
 
8
 
9
  加载代码:
10
  ```python
11
+ import torch
12
+ import os
13
+ from transformers import AutoConfig, AutoModel, AutoTokenizer
14
+
15
+ # 载入Tokenizer与模型
16
  tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True)
17
+ config = AutoConfig.from_pretrained("THUDM/chatglm2-6b", trust_remote_code=True, pre_seq_len=128)
18
+ model = AutoModel.from_pretrained("THUDM/chatglm2-6b", config=config, trust_remote_code=True)
19
+ # 载入预训练参数
20
  prefix_state_dict = torch.load(os.path.join("glm-emotion", "pytorch_model.bin"))
21
  new_prefix_state_dict = {}
22
  for k, v in prefix_state_dict.items():
23
  if k.startswith("transformer.prefix_encoder."):
24
  new_prefix_state_dict[k[len("transformer.prefix_encoder."):]] = v
25
  model.transformer.prefix_encoder.load_state_dict(new_prefix_state_dict)
26
+
27
+ model.half().cuda().eval()
28
+
29
+ response, history = model.chat(tokenizer, "说出下列句子的情绪类型:到北京五环25分钟车程,938离我住处只有300米,饮食一条街更是北京饮食街的翻版", history=[])
30
+ print(response)
31
  ```