Update README.md
Browse files
README.md
CHANGED
|
@@ -6,4 +6,71 @@ tags:
|
|
| 6 |
- llama-factory
|
| 7 |
- full
|
| 8 |
- generated_from_trainer
|
| 9 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
- llama-factory
|
| 7 |
- full
|
| 8 |
- generated_from_trainer
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# PsyLLM — Model Card (简版)
|
| 13 |
+
|
| 14 |
+
**模型名称**:PsyLLM
|
| 15 |
+
**基础模型**:Qwen3-8B
|
| 16 |
+
**训练数据**:[OpenR1-Psy](https://huggingface.co/datasets/GMLHUHE/OpenR1-Psy)
|
| 17 |
+
**训练框架**:LLaMA-Factory
|
| 18 |
+
**训练方式**:全量微调 (Full Fine-tuning)
|
| 19 |
+
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
PsyLLM 是一个基于 Qwen3-8B 的心理支持与共情对话模型,使用 [OpenR1-Psy](https://huggingface.co/datasets/GMLHUHE/OpenR1-Psy) 数据集全量微调,旨在提升模型的情绪识别、共情表达与安全提示能力。该模型仅供研究与教育用途,不应作为临床诊断或心理治疗工具。
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## 推理示例代码
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 30 |
+
|
| 31 |
+
model_path = "GMLHUHE/PsyLLM"
|
| 32 |
+
|
| 33 |
+
# load the tokenizer and the model
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 35 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 36 |
+
model_path,
|
| 37 |
+
torch_dtype="auto",
|
| 38 |
+
device_map="auto"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# prepare the model input
|
| 42 |
+
prompt = "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."
|
| 43 |
+
messages = [
|
| 44 |
+
{"role": "user", "content": prompt}
|
| 45 |
+
]
|
| 46 |
+
text = tokenizer.apply_chat_template(
|
| 47 |
+
messages,
|
| 48 |
+
tokenize=False,
|
| 49 |
+
add_generation_prompt=True,
|
| 50 |
+
enable_thinking=True # 启用思维模式,可选
|
| 51 |
+
)
|
| 52 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 53 |
+
|
| 54 |
+
# conduct text completion
|
| 55 |
+
generated_ids = model.generate(
|
| 56 |
+
**model_inputs,
|
| 57 |
+
max_new_tokens=32768
|
| 58 |
+
)
|
| 59 |
+
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
| 60 |
+
|
| 61 |
+
# parsing thinking content
|
| 62 |
+
try:
|
| 63 |
+
# 查找 </think> 标记 (token id: 151668)
|
| 64 |
+
index = len(output_ids) - output_ids[::-1].index(151668)
|
| 65 |
+
except ValueError:
|
| 66 |
+
index = 0
|
| 67 |
+
|
| 68 |
+
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
|
| 69 |
+
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
|
| 70 |
+
|
| 71 |
+
print("thinking content:", thinking_content)
|
| 72 |
+
print("content:", content)
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|