🚀 Phi 2 Persona-Chat
Phi 2 Persona-Chatは、Phi 2ベースモデルをnazlicanto/persona-based-chatデータセットを用いてLoRA微調整したバージョンです。このデータセットには、Persona AとPersona Bの間の64,000以上の会話が含まれており、それぞれの人物の特性情報が提供されています。
このモデルは、reference
応答をターゲット出力として、Supervised Fine-tuning Trainerを使用して学習されています。学習と推論のコード、および依存関係の完全なリストについては、Githubのリポジトリを参照してください。
🚀 クイックスタート
現時点では、Phi 2モデルを実行するにはtrust_remote_code=True
が必要です。最良の結果を得るには、人物の特性情報を含むプロンプトを使用し、少なくとも1回の会話ターンを続けてください。
💻 使用例
基本的な使用法
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ライセンスの下で提供されています。