File size: 2,265 Bytes
8a73df9
cc63537
 
 
8a73df9
 
 
 
 
ec8e97e
 
 
 
 
8a73df9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec8e97e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
license: other
license_name: glm-4
license_link: https://huggingface.co/THUDM/glm-4-9b-chat/blob/main/LICENSE
language:
- en
- zh
library_name: transformers
pipeline_tag: text-generation
base_model: THUDM/glm-4-9b-chat
tags:
- Mental Health
- Chatbot
- LLM
---
# Update
**The model is now following the update from GLM-4-9B-Chat and now requires `transformers>=4.44.0`. Please update your dependencies accordingly.**
**Also follow the [dependencies](https://github.com/THUDM/GLM-4/blob/main/basic_demo/requirements.txt) it before using**

# Introduction
This model is [GLM-4-9B-Chat](https://huggingface.co/THUDM/glm-4-9b-chat/tree/main), fine-tuned with the [Smile dataset](https://github.com/qiuhuachuan/smile) to focus on mental health care.

Since it is fine-tuned with a Chinese dataset, please use it in Chinese, even though the base model supports English text.

# Use the following method to quickly call the GLM-4-9B-Chat language model
Use the transformers backend for inference:
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained("derek33125/project-angel-chatglm4", trust_remote_code=True)
query = "我感到很悲伤"
inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
                                       add_generation_prompt=True,
                                       tokenize=True,
                                       return_tensors="pt",
                                       return_dict=True
                                       )
inputs = inputs.to(device)
model = AutoModelForCausalLM.from_pretrained(
    "derek33125/project-angel-chatglm4",
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    trust_remote_code=True
).to(device).eval()
gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
with torch.no_grad():
    outputs = model.generate(**inputs, **gen_kwargs)
    outputs = outputs[:, inputs['input_ids'].shape[1]:]
    print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```

It also supports [VLLM](https://github.com/THUDM/GLM-4/blob/main/basic_demo/openai_api_server.py) and [LangChain](https://python.langchain.com/v0.2/docs/integrations/llms/huggingface_pipelines/) .