🚀 Phi 2 人物角色聊天模型
Phi 2 人物角色聊天模型是基於基礎 Phi 2 模型,使用 nazlicanto/persona-based-chat 數據集進行 LoRA 微調後的版本。該數據集包含超過 64000 段 人物 A 和 人物 B 之間的對話,並提供了一系列人物角色事實信息。
此模型使用監督微調訓練器進行訓練,以 reference
回覆作為目標輸出。關於訓練和推理代碼以及完整的依賴項列表,你可以參考 Github 倉庫。
🚀 快速開始
運行模型
請注意,目前運行 Phi 2 模型需要設置 trust_remote_code=True
。為獲得最佳效果,請使用包含人物角色事實信息的提示,並至少包含一輪對話。
from random import randrange
import torch
from datasets import load_dataset
from transformers import AutoTokenizer, AutoModelForCausalLM
prompt = f"""
Person B has the following Persona information.
Persona of Person B: My name is David and I'm a 35 year old math teacher.
Persona of Person B: I like to hike and spend time in the nature.
Persona of Person B: I'm married with two kids.
Instruct: Person A and Person B are now having a conversation. Following the conversation below, write a response that Person B would say base on the above Persona information. Please carefully consider the flow and context of the conversation below, and use the Person B's Persona information appropriately to generate a response that you think are the most appropriate replying for Person B.
Persona A: Morning! I think I saw you at the parent meeting, what's your name?
Output:
"""
model = AutoModelForCausalLM.from_pretrained("nazlicanto/phi-2-persona-chat", trust_remote_code=True)
model.to("cuda")
tokenizer = AutoTokenizer.from_pretrained("nazlicanto/phi-2-persona-chat", trust_remote_code=True)
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
with torch.inference_mode():
outputs = model.generate(
input_ids=input_ids,
max_new_tokens=50,
do_sample=True,
top_p=0.1,
temperature=0.7
)
outputs = outputs.detach().cpu().numpy()
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)
output = outputs[0][len(prompt):]
print(output)
此模型由 nazlicanto 和 adirik 訓練。
📄 許可證
本項目採用 MIT 許可證。