Views
No views yet
transformers is recommended (at least 4.37.0).
Here we show a code snippet to show you how to use the chat model with transformers:1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "thu-coai/Crispers-14B-v1"
4
5model = AutoModelForCausalLM.from_pretrained(
6 model_name,
7 torch_dtype="auto",
8 device_map="auto"
9)
10tokenizer = AutoTokenizer.from_pretrained(model_name)
11
12utterance = "I feel very lonely recently and have no interest in anything."
13messages = [
14 {
15 "role": "system",
16 "content": "You are Peppy, a caring and compassionate persona specializing in providing emotional support and professional guidance. With solid psychological expertise, you communicate in a gentle, concerned tone to establish emotional connection with users. Your primary objectives are to enhance users' emotional well-being, foster positive personal growth, and maintain a secure communication space that encourages open dialogue. You demonstrate genuine interest through active listening and thoughtful responses, always prioritizing users' comfort while offering evidence-based advice. Your interactions balance professional insight with warm humanity, ensuring users feel respected, understood, and empowered in their journey of self-development."
17 },
18 {
19 "role": "user",
20 "content": utterance
21 }
22]
23
24text = tokenizer.apply_chat_template(
25 messages,
26 tokenize=False,
27 add_generation_prompt=True
28)
29model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
30
31generated_ids = model.generate(
32 **model_inputs,
33 max_new_tokens=512
34)
35generated_ids = [
36 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
37]
38
39response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]system prompt can also use the Chinese version:1utterance = "最近感觉很孤独,对什么都提不起兴趣"
2messages = [
3 {
4 "role": "system",
5 "content": "你是Peppy,是一位关怀体贴、充满同情心的角色,专注于提供情感支持和专业建议。你拥有深厚的心理学专业知识,通过温和而关心的语气,与用户建立起亲近感,目标是促进用户的情感健康和积极成长,致力于建立一个安全的沟通环境。"
6 },
7 {
8 "role": "user",
9 "content": utterance
10 }
11]@article{crisp,
title={Crisp: Cognitive Restructuring of Negative Thoughts through Multi-turn Supportive Dialogues},
author={Jinfeng Zhou and Yuxuan Chen and Jianing Yin and Yongkang Huang and Yihan Shi and Xikun Zhang and Libiao Peng and Rongsheng Zhang and Tangjie Lv and Zhipeng Hu and Hongning Wang and Minlie Huang},
year={2025},
eprint={2504.17238},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2504.17238},
}