The model is trained on the
OpenR1-Psy dataset (
arXiv:2505.15715),
featuring multi-turn counseling dialogues with explicit reasoning traces that support
clinically informed, empathetic, and interpretable AI-assisted therapy.
The training process is implemented based on the open-source framework
LLaMA-Factory.
If you find this project helpful, feel free to ⭐ it!
PsyLLM
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_path = "GMLHUHE/PsyLLM-4B"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForCausalLM.from_pretrained(
8 model_path,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# prepare the model input
14prompt = "I have participated in big group sessions before where I was left to find my own safe place, but it hasn't worked for me."
15messages = [
16 {"role": "user", "content": prompt}
17]
18text = tokenizer.apply_chat_template(
19 messages,
20 tokenize=False,
21 add_generation_prompt=True,
22 enable_thinking=True
23)
24model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
25
26# conduct text completion
27generated_ids = model.generate(
28 **model_inputs,
29 max_new_tokens=32768
30)
31output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
32
33# parsing thinking content
34try:
35 index = len(output_ids) - output_ids[::-1].index(151668)
36except ValueError:
37 index = 0
38
39thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
40content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
41
42print("PsyLLM thinking content:", thinking_content)
43print("PsyLLM content:", content)
1@article{hu2025beyond,
2 title={Beyond Empathy: Integrating Diagnostic and Therapeutic Reasoning with Large Language Models for Mental Health Counseling},
3 author={Hu, He and Zhou, Yucheng and Si, Juzheng and Wang, Qianning and Zhang, Hengheng and Ren, Fuji and Ma, Fei and Cui, Laizhong},
4 journal={arXiv preprint arXiv:2505.15715},
5 year={2025}
6}