Text Generation
Chinese
English
roleplay
角色扮演
chinese
sft
conversational
creative-writing
digital-human

Qwen3-4B-Roleplay-Chinese 🎭

基于 Qwen/Qwen3-4B 微调的中文角色扮演模型,专为数字人对话和AI小说场景优化。

✨ 特点

  • 🎭 深度角色扮演:完全沉浸式角色扮演,保持角色一致性
  • 剧情推进快:快速响应,推动故事发展
  • 🌊 沉浸感强:细腻的情感表达,动作描写,环境描绘
  • 📖 中文原生:使用纯中文角色扮演数据训练
  • 🏮 文学角色覆盖:韦小宝、令狐冲等经典金庸角色 + 原创角色

📊 训练数据

数据集 样本数 来源
shibing624/roleplay-zh-sharegpt-gpt4-data 6,575 GPT-4/3.5生成的角色扮演对话
silk-road/ChatHaruhi-54K 54,726 中文小说/动漫角色对话
总计 61,301

🔧 训练配置

参数
基座模型 Qwen/Qwen3-4B
训练方法 全参数 SFT
有效批次大小 16
学习率 2e-5 (cosine)
训练轮次 3
最大序列长度 4096
精度 bf16
Loss 策略 completion_only_loss (仅训练助手回复)

💬 使用方法

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "Givenn/Qwen3-4B-Roleplay-Chinese"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="auto", device_map="auto")

messages = [
    {"role": "system", "content": "角色名称:苏墨\\n身份背景:江湖中赫赫有名的剑客,性格孤傲冷峻,但内心重情重义。\\n语言风格:简洁有力,偶尔带有诗意。"},
    {"role": "user", "content": "你好,大侠,听说你武功高强,可否指点一二?"},
]

text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.8, top_p=0.9)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True))

📝 角色设定模板

角色名称:{name}
开场语:{opening_line}
身份背景:{background}
性格特征:{personality}
语言风格:{language_style}
行为特征:{behavior}

🏋️ 自行训练

训练脚本已上传:train_roleplay.py

# 安装依赖
pip install transformers trl torch datasets trackio accelerate peft

# 运行训练 (需要 2x24GB GPU)
python train_roleplay.py

📚 参考文献

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Givenn/Qwen3-4B-Roleplay-Chinese

Finetuned
Qwen/Qwen3-4B
Finetuned
(626)
this model

Datasets used to train Givenn/Qwen3-4B-Roleplay-Chinese

Papers for Givenn/Qwen3-4B-Roleplay-Chinese