Views
No views yet
1cd ~
2git clone https://github.com/scutcyr/SoulChat.git1cd SoulChat
2conda env create -n proactivehealthgpt_py38 --file proactivehealthgpt_py38.yml
3conda activate proactivehealthgpt_py38
4pip install cpm_kernels
5pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu1161import torch
2from transformers import AutoModel, AutoTokenizer
3# GPU设置
4device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5# 加载模型与tokenizer
6model_name_or_path = 'scutcyr/SoulChat'
7model = AutoModel.from_pretrained(model_name_or_path, trust_remote_code=True).half()
8model.to(device)
9tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True)
10
11# 单轮对话调用模型的chat函数
12user_input = "我失恋了,好难受!"
13input_text = "用户:" + user_input + "\n心理咨询师:"
14response, history = model.chat(tokenizer, query=input_text, history=None, max_length=2048, num_beams=1, do_sample=True, top_p=0.75, temperature=0.95, logits_processor=None)
15
16# 多轮对话调用模型的chat函数
17# 注意:本项目使用"\n用户:"和"\n心理咨询师:"划分不同轮次的对话历史
18# 注意:user_history比bot_history的长度多1
19user_history = ['你好,老师', '我女朋友跟我分手了,感觉好难受']
20bot_history = ['你好!我是你的个人专属数字辅导员甜心老师,欢迎找我倾诉、谈心,期待帮助到你!']
21# 拼接对话历史
22context = "\n".join([f"用户:{user_history[i]}\n心理咨询师:{bot_history[i]}" for i in range(len(bot_history))])
23input_text = context + "\n用户:" + user_history[-1] + "\n心理咨询师:"
24
25response, history = model.chat(tokenizer, query=input_text, history=None, max_length=2048, num_beams=1, do_sample=True, top_p=0.75, temperature=0.95, logits_processor=None)streamlit run soulchat_app.py --server.port 9026os.environ['CUDA_VISIBLE_DEVICES'] = '2'model_name_or_path = 'scutcyr/SoulChat'1@misc{chen2023soulchat,
2 title={灵心健康大模型SoulChat:通过长文本咨询指令与多轮共情对话数据集的混合微调,提升大模型的“共情”能力},
3 author={Yirong Chen, Xiaofen Xing, Zhenyu Wang, Xiangmin Xu},
4 year={2023},
5 month = {6},
6 version = {1.0},
7 url = {https://github.com/scutcyr/SoulChat}
8}