zwzzz commited on
Commit
fdf4a9b
·
verified ·
1 Parent(s): 3fea98f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -0
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - zh
5
+ base_model:
6
+ - THUDM/glm-4-9b
7
+ pipeline_tag: text-generation
8
+ ---
9
+ # MentalGLM is a series of large language models designed for mental health analysis tasks in Chinese.
10
+ We have developed the MentalGLM series, the first Chinese open-source interpretable large language models for mental health analysis, based on GLM-4-9b and GLM-4-9b-chat.
11
+
12
+ ## How to use
13
+
14
+ ```bash
15
+ import torch
16
+ from transformers import AutoModelForCausalLM, AutoTokenizer
17
+
18
+ device = "cuda"
19
+
20
+ tokenizer = AutoTokenizer.from_pretrained("zwzzz/MentalGLM", trust_remote_code=True)
21
+
22
+ query = "考虑以下这个帖子,帖子体现了什么认知路径?这已经够糟糕的了。不过在那一周我将完全失去我的支持。我没有什么可期待的。"
23
+
24
+ inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
25
+ add_generation_prompt=True,
26
+ tokenize=True,
27
+ return_tensors="pt",
28
+ return_dict=True
29
+ )
30
+
31
+ inputs = inputs.to(device)
32
+ model = AutoModelForCausalLM.from_pretrained(
33
+ "zwzzz/MentalGLM",
34
+ torch_dtype=torch.bfloat16,
35
+ low_cpu_mem_usage=True,
36
+ trust_remote_code=True
37
+ ).to(device).eval()
38
+
39
+ gen_kwargs = {"max_length": 1000, "do_sample": True, "top_k": 1}
40
+ with torch.no_grad():
41
+ outputs = model.generate(**inputs, **gen_kwargs)
42
+ outputs = outputs[:, inputs['input_ids'].shape[1]:]
43
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
44
+ ```
45
+
46
+ ## Citation
47
+
48
+ If you find the technical report or resource is useful, please cite the following technical report in your paper.
49
+
50
+ Article address:[https://arxiv.org/pdf/2410.10323.pdf](https://arxiv.org/pdf/2410.10323.pdf)
51
+ ```bash
52
+ @article{zhai2024mentalglm,
53
+ title={MentalGLM Series: Explainable Large Language Models for Mental Health Analysis on Chinese Social Media},
54
+ author={Zhai, Wei and Bai, Nan and Zhao, Qing and Li, Jianqiang and Wang, Fan and Qi, Hongzhi and Jiang, Meng and Wang, Xiaoqin and Yang, Bing Xiang and Fu, Guanghui},
55
+ journal={arXiv preprint arXiv:2410.10323},
56
+ year={2024}
57
+ }
58
+ ```