update README
Browse files
README.md
CHANGED
|
@@ -15,4 +15,154 @@ language:
|
|
| 15 |
|
| 16 |
# 灵心健康大模型SoulChat:通过长文本咨询指令与多轮共情对话数据集的混合微调,提升大模型的“共情”能力
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
## 简介
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# 灵心健康大模型SoulChat:通过长文本咨询指令与多轮共情对话数据集的混合微调,提升大模型的“共情”能力
|
| 17 |
|
| 18 |
+
<p align="center">
|
| 19 |
+
<img src="https://github.com/scutcyr/SoulChat/ProactiveHealthGPT.png" width=900px/>
|
| 20 |
+
</p>
|
| 21 |
+
<p align="center">
|
| 22 |
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202-red.svg"></a>
|
| 23 |
+
<a href="support os"><img src="https://img.shields.io/badge/os-linux%2C%20win%2C%20mac-pink.svg"></a>
|
| 24 |
+
<a href=""><img src="https://img.shields.io/badge/python-3.8+-aff.svg"></a>
|
| 25 |
+
<a href="https://github.com/scutcyr/SoulChat/graphs/contributors"><img src="https://img.shields.io/github/contributors/scutcyr/SoulChat?color=9ea"></a>
|
| 26 |
+
<a href="https://github.com/scutcyr/SoulChat/commits"><img src="https://img.shields.io/github/commit-activity/m/scutcyr/SoulChat?color=3af"></a>
|
| 27 |
+
<a href="https://github.com/scutcyr/SoulChat/issues"><img src="https://img.shields.io/github/issues/scutcyr/SoulChat?color=9cc"></a>
|
| 28 |
+
<a href="https://github.com/scutcyr/SoulChat/stargazers"><img src="https://img.shields.io/github/stars/scutcyr/SoulChat?color=ccf"></a>
|
| 29 |
+
</p>
|
| 30 |
+
|
| 31 |
+
基于主动健康的主动性、预防性、精确性、个性化、共建共享、自律性六大特征,华工未来技术学院-广东省数字孪生人重点实验室开源了中文领域生活空间主动健康大模型基座ProactiveHealthGPT,包括:
|
| 32 |
+
* 经过千万规模中文健康对话数据指令微调的[生活空间健康大模型扁鹊(BianQue)](https://github.com/scutcyr/BianQue)
|
| 33 |
+
* 经过百万规模心理咨询领域中文长文本指令与多轮共情对话数据联合指令微调的[心理健康大模型灵心(SoulChat)](https://github.com/scutcyr/SoulChat)
|
| 34 |
+
|
| 35 |
+
我们期望,**生活空间主动健康大模型基座ProactiveHealthGPT** 可以帮助学术界加速大模型在慢性病、心理咨询等主动健康领域的研究与应用。本项目为 **生活空间健康大模型扁鹊(BianQue)** 。
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
## 最近更新
|
| 39 |
+
- 👏🏻 2023.06.06: 【预告】扁鹊-2.0模型即将开源。
|
| 40 |
+
- 👏🏻 2023.06.06: 灵心SoulChat模型即将开源,详情见:[灵心健康大模型SoulChat:通过长文本咨询指令与多轮共情对话数据集的混合微调,提升大模型的“共情”能力 ](https://huggingface.co/scutcyr/SoulChat)。
|
| 41 |
+
- 👏🏻 2023.04.22: 基于扁鹊-1.0模型的医疗问答系统Demo,详情访问:[https://huggingface.co/spaces/scutcyr/BianQue](https://huggingface.co/spaces/scutcyr/BianQue)
|
| 42 |
+
- 👏🏻 2023.04.22: 扁鹊-1.0版本模型发布,详情见:[扁鹊-1.0:通过混合指令和多轮医生问询数据集的微调,提高医疗聊天模型的“问”能力(BianQue-1.0: Improving the "Question" Ability of Medical Chat Model through finetuning with Hybrid Instructions and Multi-turn Doctor QA Datasets)](https://huggingface.co/scutcyr/BianQue-1.0)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
## 简介
|
| 46 |
+
我们调研了当前常见的心理咨询平台,发现,用户寻求在线心理帮助时,通常需要进行较长篇幅地进行自我描述,然后提供帮助的心理咨询师同样地提供长篇幅的回复(见[https://github.com/scutcyr/SoulChat/figure/single_turn.png](https://github.com/scutcyr/SoulChat/figure/single_turn.png)),缺失了一个渐进式的倾诉过程。但是,在实际的心理咨询过程当中,用户和心理咨询师之间会存在多轮次的沟通过程,在该过程当中,心理咨询师会引导用户进行倾诉,并且提供共情,例如:“非常棒”、“我理解你的感受”、“当然可以”等等(见下图)。
|
| 47 |
+
<p align="center">
|
| 48 |
+
<img src="https://github.com/scutcyr/SoulChat/figure/multi_turn.png" width=900px/>
|
| 49 |
+
</p>
|
| 50 |
+
|
| 51 |
+
考虑到当前十分欠缺多轮共情对话数据集,我们一方面,构建了超过15万规模的 **单轮长文本心理咨询指令与答案(SoulChatCorpus-single_turn)** ,回答数量超过50万(指令数是当前的常见的心理咨询数据集 [PsyQA](https://github.com/thu-coai/PsyQA) 的6.7倍),并利用ChatGPT与GPT4,生成总共约100万轮次的 **多轮回答数据(SoulChatCorpus-multi_turn)** 。特别地,我们在预实验中发现,纯单轮长本文驱动的心理咨询模型会产生让用户感到厌烦的文本长度,而且不具备引导用户倾诉的能力,纯多轮心理咨询对话数据驱动的心理咨询模型则弱化了模型的建议能力,因此,我们混合SoulChatCorpus-single_turn和SoulChatCorpus-multi_turn构造成超过120万个样本的 **单轮与多轮混合的共情对话数据集SoulChatCorpus** 。所有数据采用“用户:xxx\n心理咨询师:xxx\n用户:xxx\n心理咨询师:”的形式统一为一种指令格式。
|
| 52 |
+
|
| 53 |
+
我们选择了 [ChatGLM-6B](https://huggingface.co/THUDM/chatglm-6b) 作为初始化模型,进行了**全量参数的指令微调**,旨在提升模型的共情能力、引导用户倾诉能力以及提供合理建议的能力。更多训练细节请留意我们后续发布的论文。
|
| 54 |
+
|
| 55 |
+
## 使用方法
|
| 56 |
+
* 克隆本项目
|
| 57 |
+
```bash
|
| 58 |
+
cd ~
|
| 59 |
+
git clone https://github.com/scutcyr/SoulChat.git
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
* 安装依赖
|
| 63 |
+
需要注意的是torch的版本需要根据你的服务器实际的cuda版本选择,详情参考[pytorch安装指南](https://pytorch.org/get-started/previous-versions/)
|
| 64 |
+
```bash
|
| 65 |
+
cd SoulChat
|
| 66 |
+
conda env create -n proactivehealthgpt_py38 --file proactivehealthgpt_py38.yml
|
| 67 |
+
conda activate proactivehealthgpt_py38
|
| 68 |
+
|
| 69 |
+
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
* 在Python当中调用SoulChat模型:
|
| 73 |
+
```python
|
| 74 |
+
import torch
|
| 75 |
+
from transformers import AutoModel, AutoTokenizer
|
| 76 |
+
# GPU设置
|
| 77 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 78 |
+
# 加载模型与tokenizer
|
| 79 |
+
model_name_or_path = 'scutcyr/SoulChat'
|
| 80 |
+
model = AutoModel.from_pretrained(model_name_or_path, trust_remote_code=True).half()
|
| 81 |
+
model.to(device)
|
| 82 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True)
|
| 83 |
+
|
| 84 |
+
# 单轮对话调用模型的chat函数
|
| 85 |
+
user_input = "我失恋了,好难受!"
|
| 86 |
+
input_text = "用户:" + user_input + "\n心理咨询师:"
|
| 87 |
+
response, 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)
|
| 88 |
+
|
| 89 |
+
# 多轮对话调用模型的chat函数
|
| 90 |
+
# 注意:本项目使用"\n用户:"和"\n心理咨询师:"划分不同轮次的对话历史
|
| 91 |
+
# 注意:user_history比bot_history的长度多1
|
| 92 |
+
user_history = ['你好,老师', '我女朋友跟我分手了,感觉好难受']
|
| 93 |
+
bot_history = ['你好!我是你的个人专属数字辅导员甜心老师,欢迎找我倾诉、谈心,期待帮助到你!']
|
| 94 |
+
# 拼接对话历史
|
| 95 |
+
context = "\n".join([f"用户:{user_history[i]}\n心理咨询师:{bot_history[i]}" for i in range(len(bot_history))])
|
| 96 |
+
input_text = context + "\n用户:" + user_history[-1] + "\n心理咨询师:"
|
| 97 |
+
|
| 98 |
+
response, 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)
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
* 启动服务
|
| 106 |
+
本项目提供了[soulchat_app.py](./soulchat_app.py)作为SoulChat模型的使用示例,通过以下命令即可开启服务,然后,通过http://<your_ip>:9026访问。
|
| 107 |
+
```bash
|
| 108 |
+
streamlit run soulchat_app.py --server.port 9026
|
| 109 |
+
```
|
| 110 |
+
特别地,在[soulchat_app.py](./soulchat_app.py)当中,
|
| 111 |
+
可以修改以下代码更换指定的显卡:
|
| 112 |
+
```python
|
| 113 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '2'
|
| 114 |
+
```
|
| 115 |
+
可以通过更改以下代码指定模型路径为本地路径:
|
| 116 |
+
```python
|
| 117 |
+
model_name_or_path = 'scutcyr/SoulChat'
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
## 示例
|
| 122 |
+
* 样例1:失恋
|
| 123 |
+
*
|
| 124 |
+
<p align="center">
|
| 125 |
+
<img src="https://github.com/scutcyr/SoulChat/figure/example_shilian.png" width=600px/>
|
| 126 |
+
</p>
|
| 127 |
+
|
| 128 |
+
* 样例2:宿舍关系
|
| 129 |
+
|
| 130 |
+
<p align="center">
|
| 131 |
+
<img src="https://github.com/scutcyr/SoulChat/figure/example_sushe.png" width=600px/>
|
| 132 |
+
</p>
|
| 133 |
+
|
| 134 |
+
* 样例3:期末考试
|
| 135 |
+
|
| 136 |
+
<p align="center">
|
| 137 |
+
<img src="https://github.com/scutcyr/SoulChat/figure/example_kaoshi.png" width=600px/>
|
| 138 |
+
</p>
|
| 139 |
+
|
| 140 |
+
* 样例4:科研压力
|
| 141 |
+
|
| 142 |
+
<p align="center">
|
| 143 |
+
<img src="https://github.com/scutcyr/SoulChat/figure/example_keyan.png" width=600px/>
|
| 144 |
+
</p>
|
| 145 |
+
|
| 146 |
+
## 声明
|
| 147 |
+
* 本项目使用了ChatGLM-6B 模型的权重,需要遵循其[MODEL_LICENSE](https://github.com/THUDM/ChatGLM-6B/blob/main/MODEL_LICENSE),因此,**本项目仅可用于您的非商业研究目的**。
|
| 148 |
+
* 本项目提供的SoulChat模型致力于提升大模型的共情对话与倾听能力,然而,模型的输出文本具有一定的随机性,当其作为一个倾听者的时候,是合适的,但是不建议将SoulChat模型的输出文本替代心理医生等的诊断、建议。本项目不保证模型输出的文本完全适合于用户,用户在使用本模型时需要承担其带来的所有风险!
|
| 149 |
+
* 您不得出于任何商业、军事或非法目的使用、复制、修改、合并、发布、分发、复制或创建SoulChat模型的全部或部分衍生作品。
|
| 150 |
+
* 您不得利用SoulChat模型从事任何危害国家安全和国家统一、危害社会公共利益、侵犯人身权益的行为。
|
| 151 |
+
* 您在使用SoulChat模型时应知悉,其不能替代医生、心理医生等专业人士,不应过度依赖、服从、相信模型的输出,不能长期沉迷于与SoulChat模型聊天。
|
| 152 |
+
|
| 153 |
+
## 致谢
|
| 154 |
+
本项目由[华南理工大学未来技术学院](https://www2.scut.edu.cn/ft/main.htm) 广东省数字孪生人重点实验室发起,得到了华南理工大学信息网络工程研究中心支撑,同时致谢合作单位广东省妇幼保健院、广州市妇女儿童医疗中心、中山大学附属第三医院等。
|
| 155 |
+
|
| 156 |
+
## 引用
|
| 157 |
+
```bib
|
| 158 |
+
@misc{chen2023soulchat,
|
| 159 |
+
title={灵心健康大模型SoulChat:通过长文本咨询指令与多轮共情对话数据集的混合微调,提升大模型的“共情”能力},
|
| 160 |
+
author={Yirong Chen, Xiaofen Xing, Zhenyu Wang, Xiangmin Xu},
|
| 161 |
+
year={2023},
|
| 162 |
+
month = {6},
|
| 163 |
+
version = {1.0},
|
| 164 |
+
url = {https://github.com/scutcyr/SoulChat}
|
| 165 |
+
}
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
|