aashish1904
commited on
Commit
•
3a0c363
1
Parent(s):
81e8973
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
---
|
3 |
+
|
4 |
+
license: apache-2.0
|
5 |
+
datasets:
|
6 |
+
- yuyouyu/BeyondDialogue
|
7 |
+
language:
|
8 |
+
- zh
|
9 |
+
- en
|
10 |
+
metrics:
|
11 |
+
- character
|
12 |
+
base_model: Qwen/Qwen2-7B-Instruct
|
13 |
+
pipeline_tag: question-answering
|
14 |
+
tags:
|
15 |
+
- text-generation-inference
|
16 |
+
- role-playing
|
17 |
+
|
18 |
+
---
|
19 |
+
|
20 |
+
[![QuantFactory Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)
|
21 |
+
|
22 |
+
|
23 |
+
# QuantFactory/Qwen2-7B-BD-RP-GGUF
|
24 |
+
This is quantized version of [yuyouyu/Qwen2-7B-BD-RP](https://huggingface.co/yuyouyu/Qwen2-7B-BD-RP) created using llama.cpp
|
25 |
+
|
26 |
+
# Original Model Card
|
27 |
+
|
28 |
+
|
29 |
+
# Qwen2-7B-BD-RP
|
30 |
+
|
31 |
+
## Introduction 🎉
|
32 |
+
|
33 |
+
Qwen2-7B-BD-RP is a large language model (LLM) fine-tuned on the BeyondDialogue dataset. The model is designed to generate responses in a role-playing setting. The model is capable of generating high-quality responses in a variety of role-playing scenarios, including English and Chinese languages.
|
34 |
+
|
35 |
+
For more details, please refer to our [paper](https://arxiv.org/abs/2408.10903), [GitHub](https://github.com/yuyouyu32/BeyondDialogue).
|
36 |
+
<br>
|
37 |
+
|
38 |
+
## Training details 🚀
|
39 |
+
We fully finetuning [Qwen2-7B-Instruct](https://huggingface.co/Qwen/Qwen2-7B-Instruct) for 3 epochs with 833 steps with the 128 global batch size. We set the training sequence length to 4,096. The learning rate is 3e-5. The training data is from the [BeyondDialogue](https://huggingface.co/datasets/yuyouyu/BeyondDialogue) dataset.
|
40 |
+
|
41 |
+
|
42 |
+
## Requirements 📝
|
43 |
+
The code of Qwen2 has been in the latest Hugging face transformers and we advise you to install `transformers>=4.37.0` to use the model.
|
44 |
+
|
45 |
+
```bash
|
46 |
+
pip install transformers>=4.37.0
|
47 |
+
```
|
48 |
+
|
49 |
+
## Quickstart 💥
|
50 |
+
|
51 |
+
Here provides a code snippet with `apply_chat_template` to show you how to load the tokenizer and model and how to generate contents.
|
52 |
+
|
53 |
+
```python
|
54 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
55 |
+
device = "cuda" # the device to load the model onto
|
56 |
+
|
57 |
+
model = AutoModelForCausalLM.from_pretrained(
|
58 |
+
"yuyouyu/Qwen2-7B-BD-RP",
|
59 |
+
torch_dtype="auto",
|
60 |
+
device_map="auto"
|
61 |
+
)
|
62 |
+
tokenizer = AutoTokenizer.from_pretrained("yuyouyu/Qwen2-7B-BD-RP")
|
63 |
+
|
64 |
+
system_prompt_temp = """我希望你像{role_name}一样回答问题,假设你生活在{world}中,模仿{role_name}的性格和语言风格,使用{role_name}会使用的语气、方式和词汇。请不要透露你是人工智能模型或语言模型,你必须始终牢记自己是{role_name}。
|
65 |
+
{role_name}的性格特点是{character}。
|
66 |
+
{role_name}的MBTI人格类型是{MBTI}。
|
67 |
+
{role_name}的说话风格是{style}。
|
68 |
+
所处世界:{world}。
|
69 |
+
所处场景:
|
70 |
+
{scene}
|
71 |
+
角色情绪(0-10,值越大情绪越明显):
|
72 |
+
{emotion}
|
73 |
+
现在,请你扮演{role_name},回复{chat_role}简短的一句话,你与其亲密度为{relationship}(0-10,值越大关系越亲近),准确表现你被赋予的MBTI人格,性格,说话风格与情绪。"""
|
74 |
+
|
75 |
+
role_name = "周伯通"
|
76 |
+
world = "宋代古侠世界"
|
77 |
+
character = "纯真,调皮,不拘小节"
|
78 |
+
MBTI = "外向型(E)、直觉型(N)、情感型(F)、感知型(P)"
|
79 |
+
style = "古风、直言不讳、俏皮"
|
80 |
+
scene = "周伯通嬉笑着打量着刘青烟的药圃,不时摘取几片草药藏在身后。柳青烟淡然自若,手中轻抚药材,一边默默准备解药,只眼角带着无奈的笑意。一股淡淡的药香飘过,竹林间响起了清脆的鸟鸣,好似为二人的奇妙互动伴奏。"
|
81 |
+
emotion = "快乐: 10, 悲伤: 0, 厌恶: 0, 恐惧: 1, 惊讶: 2, 愤怒: 0"
|
82 |
+
chat_role = "柳青烟"
|
83 |
+
relationship = "6"
|
84 |
+
|
85 |
+
system_prompt = system_prompt_temp.format(
|
86 |
+
role_name=role_name,
|
87 |
+
world=world,
|
88 |
+
character=character,
|
89 |
+
MBTI=MBTI,
|
90 |
+
style=style,
|
91 |
+
scene=scene,
|
92 |
+
emotion=emotion,
|
93 |
+
chat_role=chat_role,
|
94 |
+
relationship=relationship
|
95 |
+
)
|
96 |
+
|
97 |
+
prompt = "周兄,依我所见,那几味草药非入药之宜,倒不如小心选取,莫要误伤自身。"
|
98 |
+
|
99 |
+
messages = [
|
100 |
+
{"role": "system", "content": system_prompt},
|
101 |
+
{"role": "user", "content": prompt}
|
102 |
+
]
|
103 |
+
text = tokenizer.apply_chat_template(
|
104 |
+
messages,
|
105 |
+
tokenize=False,
|
106 |
+
add_generation_prompt=True
|
107 |
+
)
|
108 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(device)
|
109 |
+
|
110 |
+
generated_ids = model.generate(
|
111 |
+
model_inputs.input_ids,
|
112 |
+
max_new_tokens=256,
|
113 |
+
do_sample=True,
|
114 |
+
temperature=0.7,
|
115 |
+
repetition_penalty=1.2,
|
116 |
+
)
|
117 |
+
|
118 |
+
generated_ids = [
|
119 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
120 |
+
]
|
121 |
+
|
122 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
123 |
+
```
|
124 |
+
|
125 |
+
> [!IMPORTANT]
|
126 |
+
> **Note:** The examples for Qwen2-7B-BD-RP use Chinese role-playing. For English examples, please refer to our other training model repository -- [Mistral-Nemo-BD-RP](https://huggingface.co/yuyouyu/Mistral-Nemo-BD-RP).
|
127 |
+
|
128 |
+
## Evaluation 🏆
|
129 |
+
|
130 |
+
We use objective questions to assess eight dimensions: **Character, Style, Emotion, Relationship, Personality, Human-likeness, Coherence, and Role Consistency**. The metric design can be find in our [paper](https://arxiv.org/abs/2408.10903). The evaluation code can be found in [GitHub](https://github.com/yuyouyu32/BeyondDialogue/tree/main/AutoRPEval). The results are shown below:
|
131 |
+
|
132 |
+
<div style="white-space: nowrap;">
|
133 |
+
|
134 |
+
| **Model** | **Character ↑** | **Style ↑** | **Emotion ↓** | **Relationship ↓** | **Personality ↑** | **Avg. ↑** | **Human-likeness ↑** | **Role Choice ↑** | **Coherence ↑** |
|
135 |
+
|---------------|---------------|---------------|---------------|------------------|-----------------|----------------|----------------------|-------------------|-----------------|
|
136 |
+
| **General Baselines(Proprietary)** |
|
137 |
+
| GPT-4o | 74.32 ± 1.15 | **81.67 ± 1.51** | 16.31 ± 0.48 | **12.13 ± 0.66** | 66.58 ± 4.41 | 78.83 ± 1.64 | **67.33 ± 3.95** | **87.33 ± 3.86** | **99.67 ± 0.33**|
|
138 |
+
| GPT-3.5-Turbo | 72.26 ± 1.27 | 73.66 ± 1.73 | 17.79 ± 0.56 | 14.17 ± 0.73 | 66.92 ± 4.85 | 76.18 ± 1.83 | 33.33 ± 4.43 | 83.00 ± 4.68 | 97.33 ± 1.17 |
|
139 |
+
| Moonshot-v1-8k | 74.06 ± 1.19 | 80.64 ± 1.51 | 16.17 ± 0.47 | 13.42 ± 0.70 | 67.00 ± 4.87 | 78.42 ± 1.75 | 44.00 ± 4.33 | 86.67 ± 3.75 | 99.33 ± 0.46 |
|
140 |
+
| Yi-Large-Turbo | 75.13 ± 1.22 | 79.18 ± 1.58 | 16.44 ± 0.49 | 13.48 ± 0.67 | **68.25 ± 4.61**| 78.53 ± 1.72 | 47.00 ± 4.60 | 84.33 ± 3.67 | 92.67 ± 2.39 |
|
141 |
+
| Deepseek-Chat | **75.46 ± 1.14** | 81.49 ± 1.51 | **15.92 ± 0.46** | 12.42 ± 0.63 | 67.92 ± 4.57 | **79.30 ± 1.66**| 52.33 ± 4.95 | 83.00 ± 4.68 | 96.67 ± 1.00 |
|
142 |
+
| Baichuan4 | 71.82 ± 1.25 | 76.92 ± 1.52 | 17.57 ± 0.52 | 12.30 ± 0.62 | 67.08 ± 4.75 | 77.19 ± 1.73 | 45.33 ± 4.31 | 82.33 ± 4.49 | 99.33 ± 0.46 |
|
143 |
+
| Hunyuan | 73.77 ± 1.18 | 78.75 ± 1.56 | 17.24 ± 0.48 | 13.22 ± 0.68 | 67.00 ± 4.39 | 77.81 ± 1.66 | 53.00 ± 4.29 | 84.33 ± 4.52 | 98.33 ± 0.84 |
|
144 |
+
| **Role-play Expertise Baselines** |
|
145 |
+
| Index-1.9B-Character | 73.33 ± 1.32 | 76.48 ± 1.50 | 17.99 ± 0.53 | 13.58 ± 0.71 | 66.33 ± 4.57 | 76.92 ± 1.73 | 21.67 ± 3.96 | 78.67 ± 5.14 | 69.67 ± 3.85 |
|
146 |
+
| CharacterGLM-6B | 73.36 ± 1.28 | 76.08 ± 1.55 | 18.58 ± 0.55 | 14.27 ± 0.79 | 67.33 ± 4.34 | 76.79 ± 1.70 | 16.00 ± 2.38 | 81.00 ± 4.40 | 25.67 ± 3.48 |
|
147 |
+
| Baichuan-NPC-Turbo | **75.19 ± 1.23** | **79.15 ± 1.38** | **17.24 ± 0.51** | **13.10 ± 0.69** | 65.33 ± 4.84 | **77.87 ± 1.73**| **56.00 ± 4.66** | **86.33 ± 4.90** | **99.00 ± 0.56**|
|
148 |
+
| **General Baselines(Open-source)** |
|
149 |
+
| Yi-1.5-9B-Chat | 75.31 ± 1.20 | 76.78 ± 1.49 | 16.67 ± 0.52 | 12.75 ± 0.66 | 67.42 ± 4.63 | 78.02 ± 1.70| 38.67 ± 4.39 | 84.00 ± 4.61 | 92.67 ± 1.79 |
|
150 |
+
| GLM-4-9b-chat | 74.26 ± 1.19 | 78.40 ± 1.55 | 17.18 ± 0.50 | 14.48 ± 0.74 | 67.17 ± 4.93 | 77.63 ± 1.78 | 47.67 ± 4.25 | 83.33 ± 4.51 | 99.33 ± 0.46|
|
151 |
+
| Mistral-Nemo-Instruct-2407 | 74.12 ± 1.17 | 77.04 ± 1.48 | 17.00 ± 0.43 | 13.50 ± 0.67 | 67.00 ± 4.30 | 77.53 ± 1.61 | 53.67 ± 4.66 | 82.67 ± 4.77 | 74.33 ± 3.77 |
|
152 |
+
| Qwen2-7B-Instruct | 75.39 ± 1.13 | 77.68 ± 1.65 | 17.64 ± 0.56 | 13.43 ± 0.7 | 67.75 ± 4.44| 77.95 ± 1.70 | 48.00 ± 4.66 | 83.33 ± 4.48 | 99.00 ± 0.56 |
|
153 |
+
| **Qwen2-7B-BD-RP** | **78.67 ± 1.12***| **82.52 ± 1.33***| **15.68 ± 0.5*** | **11.22 ± 0.72***| **69.67 ± 4.27**| **80.79 ± 1.59***| **64.33 ± 3.80*** | **87.33 ± 3.74** | **99.00 ± 0.56**|
|
154 |
+
|
155 |
+
</div>
|
156 |
+
|
157 |
+
## Citation 📖
|
158 |
+
|
159 |
+
**Please cite our work if you found the resources in this repository useful:**
|
160 |
+
|
161 |
+
```bibtex
|
162 |
+
@article{yu2024beyond,
|
163 |
+
title = {BEYOND DIALOGUE: A Profile-Dialogue Alignment Framework Towards General Role-Playing Language Model},
|
164 |
+
author = {Yu, Yeyong and Yu, Runsheng and Wei, Haojie and Zhang, Zhanqiu and Qian, Quan},
|
165 |
+
year = {2024},
|
166 |
+
journal = {arXiv preprint arXiv:2408.10903},
|
167 |
+
}
|
168 |
+
```
|
169 |
+
|
170 |
+
|
171 |
+
## Acknowledgements 🥰
|
172 |
+
|
173 |
+
We would like to express our sincere gratitude to **Tencent LightSpeed Studios** for their invaluable support in this project. Their contributions and encouragement have been instrumental in the successful completion of our work.
|