MentalGLM is a series of large language models designed for mental health analysis tasks in Chinese.
We have developed the MentalGLM series, the first open-source LLMs designed for explainable mental health analysis targeting Chinese social media, based on GLM-4-9b and GLM-4-9b-chat.
How to use
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained("zwzzz/MentalGLM-chat", 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(
"zwzzz/MentalGLM-chat",
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True
).to(device).eval()
gen_kwargs = {"max_length": 1000, "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))
Citation
Article address:https://arxiv.org/pdf/2410.10323.pdf
@article{zhai2024mentalglm,
title={MentalGLM Series: Explainable Large Language Models for Mental Health Analysis on Chinese Social Media},
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},
journal={arXiv preprint arXiv:2410.10323},
year={2024}
}
- Downloads last month
- 14